Parent

Innate::Action

Public Class Methods

create(hash = {}) click to toggle source

Note that the default cannot be a constant as assigning the value objects to the struct would modify them and might lead to bugs due to persisting action contents.

@param [Hash, #] hash used to seed new Action instance @return [Action] action with the given defaults from hash @api stable @author manveru

    # File lib/innate/action.rb, line 15
15:     def self.create(hash = {})
16:       default = {:options => {}, :variables => {}, :params => []}
17:       new(*default.merge(hash.to_hash).values_at(*ACTION_MEMBERS))
18:     end

Public Instance Methods

binding() click to toggle source

@return [Binding] binding of the instance for this Action @see Node#binding @api stable @author manveru

    # File lib/innate/action.rb, line 42
42:     def binding
43:       instance.binding
44:     end
call() click to toggle source

Call the Action instance, will insert itself temporarily into Current.actions during the render operation so even in nested calls one can still access all other Action instances. Will initialize the assigned node and call Action#render

@return [String] The rendition of all nested calls @see Action#render Node#action_found @api stable @author manveru

    # File lib/innate/action.rb, line 34
34:     def call
35:       Current.actions ? wrap_in_current{ render } : render
36:     end
copy_variables(object = instance) click to toggle source

Copy Action#variables as instance variables into the given object. Defaults to copying the variables to self.

@param [Object #] object @return [NilClass] there is no indication of failure or success @see Action#render @author manveru

    # File lib/innate/action.rb, line 73
73:     def copy_variables(object = instance)
74:       self.variables.each do |iv, value|
75:         object.instance_variable_set("@#{iv}", value)
76:       end
77:     end
full_path() click to toggle source

Path to this action, including params, with the mapping of the current controller prepended.

     # File lib/innate/action.rb, line 132
132:     def full_path
133:       File.join(node.mapping, path)
134:     end
layout_view_or_method(name, arg) click to toggle source
     # File lib/innate/action.rb, line 114
114:     def layout_view_or_method(name, arg)
115:       [:layout, :view].include?(name) ? [arg, nil] : [nil, arg]
116:     end
merge!(hash) click to toggle source
    # File lib/innate/action.rb, line 20
20:     def merge!(hash)
21:       hash.each_pair{|key, value| send("#{key}=", value) }
22:       self
23:     end
name() click to toggle source

Try to figure out a sane name for current action.

     # File lib/innate/action.rb, line 126
126:     def name
127:       File.basename((method || view).to_s).split('.').first
128:     end
render() click to toggle source
    # File lib/innate/action.rb, line 79
79:     def render
80:       self.instance = instance = node.new
81:       self.variables[:content] ||= nil
82: 
83:       instance.wrap_action_call(self) do
84:         copy_variables
85:         self.method_value = instance.__send__(method, *params) if method
86:         self.view_value = View.read(view) if view
87: 
88:         body, content_type = wrap_in_layout{
89:           engine.call(self, view_value || method_value || '') }
90:         options[:content_type] ||= content_type if content_type
91:         body
92:       end
93:     end
render_in_layout() click to toggle source
     # File lib/innate/action.rb, line 99
 99:     def render_in_layout
100:       self.view, self.method = layout_view_or_method(*layout)
101:       self.options[:is_layout] = true
102:       self.params = []
103:       self.layout = self.view_value = nil
104:       self.sync_variables(self)
105: 
106:       body, content_type = yield
107: 
108:       self.sync_variables(self)
109:       self.variables[:content] = body
110: 
111:       return call, content_type
112:     end
sync_variables(from_action) click to toggle source

Copy the instance variable names and values from given from_action#instance into the Action#variables of the action this method is called on.

@param [Action #] from_action @return [Action] from_action @see Action#wrap_in_layout @api unstable @author manveru

    # File lib/innate/action.rb, line 55
55:     def sync_variables(from_action)
56:       instance = from_action.instance
57: 
58:       instance.instance_variables.each{|variable|
59:         name = variable.to_s[1..1].to_sym
60:         self.variables[name] = instance.instance_variable_get(variable)
61:       }
62: 
63:       from_action
64:     end
valid?() click to toggle source
     # File lib/innate/action.rb, line 136
136:     def valid?
137:       node.needs_method? ? (method && view) : (method || view)
138:     end
wrap_in_current() click to toggle source
     # File lib/innate/action.rb, line 118
118:     def wrap_in_current
119:       Current.actions << self
120:       yield
121:     ensure
122:       Current.actions.delete(self)
123:     end
wrap_in_layout() click to toggle source
    # File lib/innate/action.rb, line 95
95:     def wrap_in_layout
96:       layout ? dup.render_in_layout(&Proc.new) : yield
97:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.