Class: StrongPresenter::Factory
- Inherits:
-
Object
- Object
- StrongPresenter::Factory
- Defined in:
- lib/strong_presenter/factory.rb
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Factory
constructor
Creates a presenter factory.
-
#wrap(object) ⇒ Presenter, CollectionPresenter
Wraps an object with a presenter, inferring whether to create a singular or collection presenter from the type of object passed.
Constructor Details
#initialize(options = {}) ⇒ Factory
Creates a presenter factory.
8 9 10 11 |
# File 'lib/strong_presenter/factory.rb', line 8 def initialize( = {}) .assert_valid_keys(:with) @presenter_class = .delete(:with) end |
Instance Method Details
#wrap(object) ⇒ Presenter, CollectionPresenter
Wraps an object with a presenter, inferring whether to create a singular or collection presenter from the type of object passed.
19 20 21 22 |
# File 'lib/strong_presenter/factory.rb', line 19 def wrap(object) return nil if object.nil? Worker.new(presenter_class, object).call { |presenter| yield presenter if block_given? } end |