Class: Crew::Task::Arguments
- Inherits:
-
Object
- Object
- Crew::Task::Arguments
- Defined in:
- lib/crew/task/arguments.rb,
lib/crew/task/arguments/dsl.rb
Defined Under Namespace
Modules: DSL Classes: BlockDefinition, Definition, Proxy
Instance Attribute Summary collapse
-
#definitions ⇒ Object
readonly
Returns the value of attribute definitions.
Instance Method Summary collapse
- #define(arg, type, desc, opts) ⇒ Object
- #define_block(opts, &block) ⇒ Object
-
#initialize ⇒ Arguments
constructor
A new instance of Arguments.
- #process!(args, &blk) ⇒ Object
- #proxy(task) ⇒ Object
Constructor Details
#initialize ⇒ Arguments
Returns a new instance of Arguments.
75 76 77 |
# File 'lib/crew/task/arguments.rb', line 75 def initialize @definitions = [] end |
Instance Attribute Details
#definitions ⇒ Object (readonly)
Returns the value of attribute definitions.
73 74 75 |
# File 'lib/crew/task/arguments.rb', line 73 def definitions @definitions end |
Instance Method Details
#define(arg, type, desc, opts) ⇒ Object
93 94 95 |
# File 'lib/crew/task/arguments.rb', line 93 def define(arg, type, desc, opts) @definitions << Definition.new(arg, type, desc, opts) end |
#define_block(opts, &block) ⇒ Object
97 98 99 |
# File 'lib/crew/task/arguments.rb', line 97 def define_block(opts, &block) @block_definition = BlockDefinition.new(opts, &block) end |
#process!(args, &blk) ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/crew/task/arguments.rb', line 79 def process!(args, &blk) opts = args.last.is_a?(Hash) ? args.pop : {} opts = opts.each_with_object({}){|(k,v), h| h[k.to_s] = v} if args.size < minimum_args or (maximum_args && args.size > maximum_args) = "wrong number of arguments (got #{args.size} expected at least #{minimum_args})" << " and at most #{maximum_args}" if maximum_args raise ArgumentError, end @args = args @opts = opts @block = @block_definition.process(&blk) if @block_definition raise if blk && @block_definition.nil? end |