Class: Kward::PluginArguments Private
- Inherits:
-
Object
- Object
- Kward::PluginArguments
- Defined in:
- lib/kward/plugins/actions.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Parses and validates arguments for typed plugin commands and actions.
Constant Summary collapse
- PROPERTY_NAME_PATTERN =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
/\A[A-Za-z0-9][A-Za-z0-9_-]*\z/.freeze
- SUPPORTED_TYPES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
%w[string integer number boolean array object].freeze
- BOOLEAN_VALUES =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
{ "true" => true, "yes" => true, "1" => true, "false" => false, "no" => false, "0" => false }.freeze
Instance Attribute Summary collapse
- #positionals ⇒ Object readonly private
- #schema ⇒ Object readonly private
Instance Method Summary collapse
-
#initialize(label:, schema:, positionals: []) ⇒ PluginArguments
constructor
private
A new instance of PluginArguments.
- #parse(arguments) ⇒ Object private
Constructor Details
#initialize(label:, schema:, positionals: []) ⇒ PluginArguments
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of PluginArguments.
23 24 25 26 27 28 29 |
# File 'lib/kward/plugins/actions.rb', line 23 def initialize(label:, schema:, positionals: []) @label = label @schema = normalize_schema(schema) @properties = @schema.fetch(:properties).to_h { |name, property| [name.to_s, property] } @positionals = normalize_positionals(positionals) validate_defaults end |
Instance Attribute Details
#positionals ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
21 22 23 |
# File 'lib/kward/plugins/actions.rb', line 21 def positionals @positionals end |
#schema ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
21 22 23 |
# File 'lib/kward/plugins/actions.rb', line 21 def schema @schema end |
Instance Method Details
#parse(arguments) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/kward/plugins/actions.rb', line 31 def parse(arguments) values = case arguments when String parse_text(arguments) when Hash normalize_object(arguments) when nil {} else raise ArgumentError, "#{@label} arguments must be shell-style text or an object" end apply_defaults(values) validate_required(values) validate_object(values) end |