Module: Command::CommandClassMethods

Included in:
Command
Defined in:
lib/command-set/command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#advice_blockObject (readonly)

Returns the value of attribute advice_block.



85
86
87
# File 'lib/command-set/command.rb', line 85

def advice_block
  @advice_block
end

#argument_listObject (readonly)

Returns the value of attribute argument_list.



85
86
87
# File 'lib/command-set/command.rb', line 85

def argument_list
  @argument_list
end

#parent_argumentsObject (readonly)

Returns the value of attribute parent_arguments.



85
86
87
# File 'lib/command-set/command.rb', line 85

def parent_arguments
  @parent_arguments
end

#subject_requirementsObject (readonly)

Returns the value of attribute subject_requirements.



85
86
87
# File 'lib/command-set/command.rb', line 85

def subject_requirements
  @subject_requirements
end

Instance Method Details

#consume_terms(terms, subject, arg_hash) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/command-set/command.rb', line 88

def consume_terms(terms, subject, arg_hash)
  begin
    argument_list.each do |argument|
      raise TypeError, "#{terms.inspect} isn't an Array!" unless Array === terms
      begin
        if terms.empty?
          raise OutOfArgumentsException, "argument #{argument.inspect} required!"
        end
        single_consume(argument, arg_hash, subject, terms)
      rescue ArgumentInvalidException => aie
        @validation_problem = aie
        raise
      end
    end
  rescue OutOfArgumentsException
  end
  @validation_problem = nil
  return arg_hash
end

#embed_argument(arg) ⇒ Object



108
109
110
111
112
113
114
115
116
117
# File 'lib/command-set/command.rb', line 108

def embed_argument(arg)
  unless argument_list.last.nil? or argument_list.last.required?
    if arg.required?
      raise NoMethodError, "Can't define required arguments after optionals"
    end
  end
  @subject_requirements += arg.subject_requirements

  argument_list << arg
end

#executeable?Boolean

Returns:

  • (Boolean)


119
120
121
# File 'lib/command-set/command.rb', line 119

def executeable?
  instance_methods.include?("execute")
end

#factoryObject



127
128
129
# File 'lib/command-set/command.rb', line 127

def factory
  return self
end

#optional_argument(arg, values = nil, &get_values) ⇒ Object



123
124
125
# File 'lib/command-set/command.rb', line 123

def optional_argument(arg, values=nil, &get_values)
  optional.argument(arg, values, &get_values)
end