class ActionPresenter::Base

Attributes

object[R]
options[R]

Public Class Methods

delegate_presented(name, options = {}) click to toggle source
# File lib/action_presenter/base.rb, line 18
def self.delegate_presented(name, options = {})
  delegate_opts = options.slice(:to, :prefix, :allow_nil)
                  .reverse_merge(to: :object)
  delegate name, delegate_opts
  
  define_method "#{name}_with_presenter" do
    object = public_send("#{name}_without_presenter")
    return if object.nil?
    helper_options = options.except(*delegate_opts.keys)
    if object.respond_to?(:each)
      present_collection object, helper_options
    else
      present object, helper_options
    end
  end
  
  alias_method_chain name, :presenter
end
new(template, *args) click to toggle source
# File lib/action_presenter/base.rb, line 2
def initialize(template, *args)
  @_template = template
  @options = args.extract_options!
  @object = args.first
end
presents(name) click to toggle source
# File lib/action_presenter/base.rb, line 12
def self.presents(name)
  define_method name do
    object
  end
end

Public Instance Methods

inspect() click to toggle source
# File lib/action_presenter/base.rb, line 37
def inspect
  object_str = " object: #{object.inspect}" unless object.nil?
  "#<#{self.class.name}#{object_str}>"
end
method_missing(name, *args, &block) click to toggle source
Calls superclass method
# File lib/action_presenter/base.rb, line 42
def method_missing(name, *args, &block)
  if object && object.respond_to?(name, false)
    object.send(name, *args, &block)
  else
    super
  end
end
respond_to_missing?(name, include_private = false) click to toggle source
Calls superclass method
# File lib/action_presenter/base.rb, line 50
def respond_to_missing?(name, include_private = false)
  (object && object.respond_to?(name, include_private)) || super
end
to_model() click to toggle source
# File lib/action_presenter/base.rb, line 54
def to_model
  object
end

Protected Instance Methods

h()
Alias for: template
template() click to toggle source
# File lib/action_presenter/base.rb, line 59
def template
  @_template
end
Also aliased as: h