Sha256: a3e3fa22d400a94f4380646b2b7edbe04433f670557892fbb9091a3b7449f925

Contents?: true

Size: 536 Bytes

Versions: 1

Compression:

Stored size: 536 Bytes

Contents

module ApplicationHelper
  def present(object_or_class, klass = nil)
    presenter = nil

    if object_or_class.methods.include?(:new)
      klass ||= "#{object_or_class}Presenter".constantize
      presenter = klass
      presenter.initialize(object_or_class, self)
    else
      klass ||= "#{object_or_class.class}Presenter".constantize
      presenter = klass.new(object_or_class, self)
    end

    if block_given?
      block.arity > 0 ? yield(presenter) : presenter.instance_eval(&block)
    end

    return presenter
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
base_presenter-0.0.9 lib/application_helper.rb