Class: Fabulator::Lib::ActionRef

Inherits:
Object
  • Object
show all
Defined in:
lib/fabulator/lib/action.rb

Instance Method Summary collapse

Constructor Details

#initialize(defining_action, context, actions = nil) ⇒ ActionRef

Returns a new instance of ActionRef.



34
35
36
37
38
39
40
41
42
# File 'lib/fabulator/lib/action.rb', line 34

def initialize(defining_action, context, actions = nil)
  @context = context
  @action = defining_action
  @actions = actions
  @static_attributes = { }
  @context.get_action(@action.first, @action.last).attributes.select{ |a| a.is_static? }.each do |a|
    @static_attributes[a.name] = a.value(@context)
  end
end

Instance Method Details

#run(context, autovivify = false) ⇒ Object



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
# File 'lib/fabulator/lib/action.rb', line 44

def run(context, autovivify = false)
  ret = [ ]
  @context.with(context) do |ctx|
    @static_attributes.each_pair do |p,v|
      ctx.set_var(p, v)
    end
# These can be passed to f:eval to get their value
    action = ctx.get_action(@action.first, @action.last)
    action.attributes.select{ |a| !a.is_static? }.each do |attr|
      ctx.set_var(attr.name, attr.value(@context))
    end
    # we can f:eval($actions) in whatever current context we have
    if action.has_actions?
      @actions.use_context(context)
      ctx.set_var('actions', ctx.root.anon_node( @actions, [ FAB_NS, 'expression' ]))
    end
    if action.has_select?
      v = @context.attribute(Fabulator::FAB_NS, 'select', { :eval => true })

      ctx.set_var('select', ctx.root.anon_node( v, [ FAB_NS, 'expression' ]))
    end
    ret = action.run(ctx)
  end
  ret
end