Class: Rumx::Operation

Inherits:
Object
  • Object
show all
Defined in:
lib/rumx/operation.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, type_name, description, arguments) ⇒ Operation

Returns a new instance of Operation.



5
6
7
8
9
10
# File 'lib/rumx/operation.rb', line 5

def initialize(name, type_name, description, arguments)
  @name        = name.to_sym
  @type        = Type.find(type_name)
  @description = description
  @arguments   = arguments
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments.



3
4
5
# File 'lib/rumx/operation.rb', line 3

def arguments
  @arguments
end

#descriptionObject (readonly)

Returns the value of attribute description.



3
4
5
# File 'lib/rumx/operation.rb', line 3

def description
  @description
end

#nameObject (readonly)

Returns the value of attribute name.



3
4
5
# File 'lib/rumx/operation.rb', line 3

def name
  @name
end

#typeObject (readonly)

Returns the value of attribute type.



3
4
5
# File 'lib/rumx/operation.rb', line 3

def type
  @type
end

Instance Method Details

#run(bean, argument_hash) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/rumx/operation.rb', line 12

def run(bean, argument_hash)
  args = @arguments.map do |argument|
    if argument_hash.has_key?(argument.name)
      value = argument_hash[argument.name]
    elsif argument_hash.has_key?(argument.name.to_s)
      value = argument_hash[argument.name.to_s]
    else
      raise "No value for argument #{argument.name}"
    end
    argument.type.string_to_value(value)
  end
  bean.send(self.name, *args)
end