Class: Draper::Factory
- Inherits:
-
Object
- Object
- Draper::Factory
- Defined in:
- lib/draper/factory.rb
Instance Method Summary collapse
-
#decorate(object, options = {}) ⇒ Decorator, CollectionDecorator
Decorates an object, inferring whether to create a singular or collection decorator from the type of object passed.
-
#initialize(options = {}) ⇒ Factory
constructor
Creates a decorator factory.
Constructor Details
#initialize(options = {}) ⇒ Factory
Creates a decorator factory.
12 13 14 15 16 |
# File 'lib/draper/factory.rb', line 12 def initialize( = {}) .assert_valid_keys(:with, :context) @decorator_class = .delete(:with) @default_options = end |
Instance Method Details
#decorate(object, options = {}) ⇒ Decorator, CollectionDecorator
Decorates an object, inferring whether to create a singular or collection decorator from the type of object passed.
29 30 31 32 |
# File 'lib/draper/factory.rb', line 29 def decorate(object, = {}) return nil if object.nil? Worker.new(decorator_class, object).call(.reverse_merge()) end |