Class: Innate::Action
- Inherits:
-
Struct
- Object
- Struct
- Innate::Action
- Defined in:
- /home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/action.rb
Class Method Summary (collapse)
-
+ (Action) create(hash = {})
Create a new Action instance.
Instance Method Summary (collapse)
-
- (Binding) binding
Binding of the instance for this Action.
-
- (String) call
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.
-
- (NilClass) copy_variables(object = instance)
Copy Action#variables as instance variables into the given object.
-
- (Object) full_path
Path to this action, including params, with the mapping of the current controller prepended.
-
- (Object) layout_view_or_method(name, arg)
-
- (Object) merge!(hash)
-
- (Object) name
Try to figure out a sane name for current action.
-
- (Object) render
-
- (Object) render_in_layout
-
- (Action) sync_variables(from_action)
Copy the instance variable names and values from given from_action#instance into the Action#variables of the action this method is called on.
-
- (Boolean) valid?
-
- (Object) wrap_in_current
-
- (Object) wrap_in_layout
Class Method Details
+ (Action) create(hash = {})
Create a new Action instance. 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.
15 16 17 18 |
# File '/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/action.rb', line 15 def self.create(hash = {}) default = {:options => {}, :variables => {}, :params => []} new(*default.merge(hash.to_hash).values_at(*ACTION_MEMBERS)) end |
Instance Method Details
- (Binding) binding
Returns binding of the instance for this Action
42 43 44 |
# File '/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/action.rb', line 42 def binding instance.binding end |
- (String) call
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
34 35 36 |
# File '/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/action.rb', line 34 def call Current.actions ? wrap_in_current{ render } : render end |
- (NilClass) copy_variables(object = instance)
Copy Action#variables as instance variables into the given object. Defaults to copying the variables to self.
73 74 75 76 77 |
# File '/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/action.rb', line 73 def copy_variables(object = instance) self.variables.each do |iv, value| object.instance_variable_set("@#{iv}", value) end end |
- (Object) full_path
Path to this action, including params, with the mapping of the current controller prepended.
131 132 133 |
# File '/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/action.rb', line 131 def full_path File.join(node.mapping, path) end |
- (Object) layout_view_or_method(name, arg)
113 114 115 |
# File '/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/action.rb', line 113 def layout_view_or_method(name, arg) [:layout, :view].include?(name) ? [arg, nil] : [nil, arg] end |
- (Object) merge!(hash)
20 21 22 23 |
# File '/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/action.rb', line 20 def merge!(hash) hash.each_pair{|key, value| send("#{key}=", value) } self end |
- (Object) name
Try to figure out a sane name for current action.
125 126 127 |
# File '/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/action.rb', line 125 def name File.basename((method || view).to_s).split('.').first end |
- (Object) render
79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File '/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/action.rb', line 79 def render self.instance = instance = node.new self.variables[:content] ||= nil instance.wrap_action_call(self) do copy_variables self.method_value = method ? instance.__send__(method, *params) : nil self.view_value = view ? View.read(view) : nil body, content_type = wrap_in_layout{ engine.call(self, view_value || method_value || '') } [:content_type] ||= content_type body end end |
- (Object) render_in_layout
98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File '/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/action.rb', line 98 def render_in_layout self.view, self.method = layout_view_or_method(*layout) self.[:is_layout] = true self.params = [] self.layout = self.view_value = nil self.sync_variables(self) body, content_type = yield self.sync_variables(self) self.variables[:content] = body return call, content_type end |
- (Action) sync_variables(from_action)
Copy the instance variable names and values from given from_action#instance into the Action#variables of the action this method is called on.
55 56 57 58 59 60 61 62 63 64 |
# File '/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/action.rb', line 55 def sync_variables(from_action) instance = from_action.instance instance.instance_variables.each{|variable| name = variable.to_s[1..-1].to_sym self.variables[name] = instance.instance_variable_get(variable) } from_action end |
- (Boolean) valid?
135 136 137 |
# File '/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/action.rb', line 135 def valid? node.needs_method? ? (method && view) : (method || view) end |
- (Object) wrap_in_current
117 118 119 120 121 122 |
# File '/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/action.rb', line 117 def wrap_in_current Current.actions << self yield ensure Current.actions.delete(self) end |
- (Object) wrap_in_layout
94 95 96 |
# File '/home/manveru/github/ramaze/ramaze.net/tmp/git/innate/lib/innate/action.rb', line 94 def wrap_in_layout layout ? dup.render_in_layout(&Proc.new) : yield end |