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.



64
65
66
# File 'lib/command-set/command.rb', line 64

def advice_block
  @advice_block
end

#argument_listObject (readonly)

Returns the value of attribute argument_list.



64
65
66
# File 'lib/command-set/command.rb', line 64

def argument_list
  @argument_list
end

#contextObject (readonly)

Returns the value of attribute context.



64
65
66
# File 'lib/command-set/command.rb', line 64

def context
  @context
end

#subject_requirementsObject (readonly)

Returns the value of attribute subject_requirements.



64
65
66
# File 'lib/command-set/command.rb', line 64

def subject_requirements
  @subject_requirements
end

Instance Method Details

#consume_terms(terms, subject, arg_hash) ⇒ Object



67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/command-set/command.rb', line 67

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



87
88
89
90
91
92
93
94
95
96
# File 'lib/command-set/command.rb', line 87

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)


98
99
100
# File 'lib/command-set/command.rb', line 98

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

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



102
103
104
# File 'lib/command-set/command.rb', line 102

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