Module: Presenters::Helper

Included in:
Presenter
Defined in:
lib/presenters/helper.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.present(instance, class_type = nil) {|presenter| ... } ⇒ Object

Yields:

  • (presenter)


19
20
21
22
23
24
# File 'lib/presenters/helper.rb', line 19

def self.present(instance, class_type = nil, &block)
  class_type = class_type || Object.const_get("#{instance.class}Presenter")
  presenter = class_type.new(instance)
  yield(presenter) if block_given?
  return presenter
end

Instance Method Details

#present(*args, &block) ⇒ Object



3
4
5
# File 'lib/presenters/helper.rb', line 3

def present(*args, &block)
  Helper.present(*args, &block)
end

#present_each(instances, class_type = nil, &block) ⇒ Object



7
8
9
10
11
# File 'lib/presenters/helper.rb', line 7

def present_each(instances, class_type = nil, &block)
  instances.each do |instance|
    present(instance, class_type, &block)
  end
end

#presenters(instances, class_type = nil) ⇒ Object



13
14
15
16
17
# File 'lib/presenters/helper.rb', line 13

def presenters(instances, class_type = nil)
  instances.map do |instance|
    present(instance)
  end
end