Struct.new(*ACTION_MEMBERS)
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
@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 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 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
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
# 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
# File lib/innate/action.rb, line 20 20: def merge!(hash) 21: hash.each_pair{|key, value| send("#{key}=", value) } 22: self 23: end
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
# 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
# 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
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
# File lib/innate/action.rb, line 136 136: def valid? 137: node.needs_method? ? (method && view) : (method || view) 138: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.