class DecentExposure::Flow

Attributes

controller[R]
name[R]
options[R]

Public Class Methods

new(controller, options) click to toggle source

Public: Initialize a Flow. This object responds to missing methods errors and attempts to delegate them to other objects.

controller - The Controller class where the method was called. options - The options Hash of the Exposure instance being called. name - The String name of the Exposure instance.

# File lib/decent_exposure/flow.rb, line 11
def initialize(controller, options)
  @controller = controller
  @options = options
  @name = options.fetch(:name)
end

Public Instance Methods

method_missing(name, *args, &block) click to toggle source

Public: Attempts to re-delegate a method missing to the supplied block or the Behavior object.

name - The String name of the Exposure instance. *args - The arguments given for the missing method. block - The Proc invoked by the method.

Calls superclass method
# File lib/decent_exposure/flow.rb, line 23
def method_missing(name, *args, &block)
  if respond_to_missing?(name)
    handle_flow_method(name, *args, &block)
  else
    super
  end
end
respond_to_missing?(method_name, include_private = false) click to toggle source

Public: Checks if the Behavior class can handle the missing method.

method_name - The name of method that has been called. include_private - Prevents this method from catching calls to private method (default: false).

Calls superclass method
# File lib/decent_exposure/flow.rb, line 36
def respond_to_missing?(method_name, include_private = false)
  Behavior.method_defined?(method_name) || super
end

Private Instance Methods

fetch_ivar(name) { || ... } click to toggle source
# File lib/decent_exposure/flow.rb, line 78
def fetch_ivar(name)
  ivar_name = "@#{name}"

  if instance_variable_defined?(ivar_name)
    instance_variable_get(ivar_name)
  else
    instance_variable_set(ivar_name, yield)
  end
end
get_request?() click to toggle source
# File lib/decent_exposure/flow.rb, line 44
def get_request?
  controller.request.get? || controller.request.head?
end
handle_default_flow_method(name, *args, &block) click to toggle source
# File lib/decent_exposure/flow.rb, line 73
def handle_default_flow_method(name, *args, &block)
  method = Behavior.instance_method(name)
  method.bind(self).call(*args, &block)
end
handle_flow_method(name, *args, &block) click to toggle source
# File lib/decent_exposure/flow.rb, line 52
def handle_flow_method(name, *args, &block)
  fetch_ivar name do
    if options.key?(name)
      handle_options_override(name, *args, &block)
    else
      handle_default_flow_method(name, *args, &block)
    end
  end
end
handle_options_override(name, *args) click to toggle source
# File lib/decent_exposure/flow.rb, line 62
def handle_options_override(name, *args)
  value = options[name]

  if Proc === value
    args = args.first(value.parameters.length)
    controller.instance_exec(*args, &value)
  else
    fail ArgumentError, "Can't handle #{name.inspect} => #{value.inspect} option"
  end
end
params_method_name() click to toggle source
# File lib/decent_exposure/flow.rb, line 48
def params_method_name
  options.fetch(:build_params_method) { "#{name}_params" }
end