Class: Innate::Action

### Home Classes Methods

### In Files

- lib/innate/action.rb

### Parent

Struct.new(*ACTION_MEMBERS)

### Methods

- ::create
- #binding
- #call
- #copy_variables
- #full_path
- #layout_view_or_method
- #merge!
- #name
- #render
- #render_in_layout
- #sync_variables
- #valid?
- #wrap_in_current
- #wrap_in_layout

### Class/Module Index

Quicksearch

- Innate
- Innate::Action
- Innate::Adapter
- Innate::Cache
- Innate::Cache::API
- Innate::Cache::DRb
- Innate::Cache::FileBased
- Innate::Cache::Marshal
- Innate::Cache::Memory
- Innate::Cache::YAML
- Innate::Current
- Innate::Etanni
- Innate::Helper
- Innate::Helper::Aspect
- Innate::Helper::Aspect::SingletonMethods
- Innate::Helper::CGI
- Innate::Helper::Flash
- Innate::Helper::Link
- Innate::Helper::Redirect
- Innate::Helper::Render
- Innate::HelperAccess
- Innate::HelpersHelper
- Innate::LRUHash
- Innate::LogHub
- Innate::Mock
- Innate::Mock::Session
- Innate::Node
- Innate::Optioned
- Innate::Optioned::SingletonMethods
- Innate::Options
- Innate::Request
- Innate::Response
- Innate::Rewrite
- Innate::Route
- Innate::Session
- Innate::Session::Flash
- Innate::SingletonMethods
- Innate::StateAccessor
- Innate::Traited
- Innate::Trinity
- Innate::URLMap
- Innate::View
- Innate::View::ERB
- Innate::View::Etanni
- Innate::View::None
- Logger
- Logger::ColorFormatter
- Object

No matching classes.

# 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, to_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
    def self.create(hash = {})
      default = {:options => {}, :variables => {}, :params => []}
      new(*default.merge(hash.to_hash).values_at(*ACTION_MEMBERS))
    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
    def binding
      instance.binding
    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
    def call
      Current.actions ? wrap_in_current{ render } : render
    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 instance_variable_set] object @return [NilClass] there is no indication of failure or success @see Action#render @author manveru

    # File 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

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 131
    def full_path
      File.join(node.mapping, path)
    end

layout_view_or_method(name, arg) click to toggle source

    # File lib/innate/action.rb, line 113
    def layout_view_or_method(name, arg)
      [:layout, :view].include?(name) ? [arg, nil] : [nil, arg]
    end

merge!(hash) click to toggle source

    # File lib/innate/action.rb, line 20
    def merge!(hash)
      hash.each_pair{|key, value| send("#{key}=", value) }
      self
    end

name() click to toggle source

Try to figure out a sane name for current action.

    # File lib/innate/action.rb, line 125
    def name
      File.basename((method || view).to_s).split('.').first
    end

render() click to toggle source

    # File 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 || '') }
        options[:content_type] ||= content_type
        body
      end
    end

render_in_layout() click to toggle source

    # File lib/innate/action.rb, line 98
    def render_in_layout
      self.view, self.method = layout_view_or_method(*layout)
      self.options[: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

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 instance] from_action @return [Action] from_action @see Action#wrap_in_layout @api unstable @author manveru

    # File 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

valid?() click to toggle source

    # File lib/innate/action.rb, line 135
    def valid?
      node.needs_method? ? (method && view) : (method || view)
    end

wrap_in_current() click to toggle source

    # File lib/innate/action.rb, line 117
    def wrap_in_current
      Current.actions << self
      yield
    ensure
      Current.actions.delete(self)
    end

wrap_in_layout() click to toggle source

    # File lib/innate/action.rb, line 94
    def wrap_in_layout
      layout ? dup.render_in_layout(&Proc.new) : yield
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.