Module: Gat::Interpreter

Included in:
Action::Base, Action::ShellCommandChild, Condition
Defined in:
lib/gat/interpreter.rb

Instance Method Summary collapse

Instance Method Details

#interpreter_parameter(parameter_name, gatget_object) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/gat/interpreter.rb', line 37

def interpreter_parameter(parameter_name, gatget_object)
  parameter_config = gatget_object.get_element_config('parameters', parameter_name)

  if not parameter_config or parameter_config.nil?
 # FIXME This is never true as it would have raised an exception in get_element_config
    raise GatgetConfigException.new("Parameter #{ parameter_name } not found at YML", "interpreter_parameters")
  end

  if not parameter_config['value'] or parameter_config['value'].blank?
    raise GatgetConfigException.new("Parameter #{ parameter_name } has blank or missing value", "interpreter_parameter")
  end

  case parameter_config['type']
  when 'dependence'
    dependence_type, *dependence_name = parameter_config['value'].split("/")
    ret = gatget_object.get_dependence_value(dependence_type, dependence_name.join("_"))
    if parameter_config['array_method']
      ret = eval("ret.#{ parameter_config['array_method'] }")
    end

    if parameter_config['join']
      ret = [ *ret ].join(parameter_config['join'])
    end
  when 'eval'
    ret = eval(parameter_config['value'])
  else
    if parameter_config['type'].empty?
      raise GatgetConfigException.new("'#{parameter_config['type']}' type invalid for argument #{ parameter_name }. Should be 'dependence' or 'eval'", "interpreter_parameter")
    else
      raise GatgetConfigException.new("missing type por argument #{ parameter_name }", "interpreter_parameter")
    end

  end
  ret

  # What does it happens if a ret is nil or blank or false?????
  # ToDo

end

#interpreter_parameters(gatget_text, gatget_object) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/gat/interpreter.rb', line 27

def interpreter_parameters(gatget_text, gatget_object)

  interpreted_string = gatget_text.gsub(/\{\{[\w\d]+\}\}/) do |gat_parameter|
    parameter        = gat_parameter.gsub(/[{}]/,'')
    gat_parameter    = interpreter_parameter(parameter, gatget_object)
  end
end

#interpreter_shell_command(action) ⇒ Object



78
79
80
81
82
83
84
85
86
87
88
89
# File 'lib/gat/interpreter.rb', line 78

def interpreter_shell_command(action)
  syntax = self.syntax.gsub(/\{\{[\w\d]+\}\}/) do |argument|

    # replace current argument with data
    unless self.arguments.keys.include?(argument.gsub(/[{}]/,''))
      raise GatgetConfigException.new("Syntax failed for action #{ action.name }. Missing argument: #{ argument }", "interpreter_shell_command")
    end

    argument = self.arguments[argument.gsub(/[{}]/,'')]
  end
  syntax
end