Class: Rattler::Parsers::NodeCode

Inherits:
Object
  • Object
show all
Defined in:
lib/rattler/parsers/node_code.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(target_name, method_name, target_attrs = {}) ⇒ NodeCode

Returns a new instance of NodeCode.



18
19
20
21
22
# File 'lib/rattler/parsers/node_code.rb', line 18

def initialize(target_name, method_name, target_attrs = {})
  @target_name = target_name
  @method_name = method_name
  @target_attrs = target_attrs
end

Instance Attribute Details

#method_nameObject (readonly)

Returns the value of attribute method_name.



24
25
26
# File 'lib/rattler/parsers/node_code.rb', line 24

def method_name
  @method_name
end

#target_attrsObject (readonly)

Returns the value of attribute target_attrs.



24
25
26
# File 'lib/rattler/parsers/node_code.rb', line 24

def target_attrs
  @target_attrs
end

#target_nameObject (readonly)

Returns the value of attribute target_name.



24
25
26
# File 'lib/rattler/parsers/node_code.rb', line 24

def target_name
  @target_name
end

Class Method Details

.bindable_code(action) ⇒ Object

:nodoc:



14
15
16
# File 'lib/rattler/parsers/node_code.rb', line 14

def self.bindable_code(action)
  self.new(action.target, action.method_name)
end

Instance Method Details

#array_expr(bind_args) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/rattler/parsers/node_code.rb', line 37

def array_expr(bind_args)
  if bind_args.respond_to? :to_str
    bind_args
  else
    '[' + bind_args.join(', ') + ']'
  end
end

#bind(scope, bind_args) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/rattler/parsers/node_code.rb', line 26

def bind(scope, bind_args)
  args = [array_expr(bind_args)]
  if not scope.empty?
    labeled = '{' + scope.map {|k, v| ":#{k} => #{v}"}.join(', ') + '}'
    args << ":labeled => #{labeled}"
  end
  target_attrs.each {|k, v| args << ":#{k} => #{v.inspect}" }
  t = target_name == 'self' ? '' : "#{target_name}."
  "#{t}#{method_name}(#{args.join ', '})"
end