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.



109
110
111
# File 'lib/command-set/command.rb', line 109

def advice_block
  @advice_block
end

#argument_listObject (readonly)

Returns the value of attribute argument_list.



109
110
111
# File 'lib/command-set/command.rb', line 109

def argument_list
  @argument_list
end

#contextObject (readonly)

Returns the value of attribute context.



109
110
111
# File 'lib/command-set/command.rb', line 109

def context
  @context
end

#subject_requirementsObject (readonly)

Returns the value of attribute subject_requirements.



109
110
111
# File 'lib/command-set/command.rb', line 109

def subject_requirements
  @subject_requirements
end

Instance Method Details

#consume_terms(terms, subject, arg_hash) ⇒ Object



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/command-set/command.rb', line 112

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



132
133
134
135
136
137
138
139
140
141
# File 'lib/command-set/command.rb', line 132

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)


143
144
145
# File 'lib/command-set/command.rb', line 143

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

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



147
148
149
# File 'lib/command-set/command.rb', line 147

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