Class: Representable::Decorator

Inherits:
Object
  • Object
show all
Includes:
Representable
Defined in:
lib/representable/decorator.rb,
lib/representable/decorator/coercion.rb

Defined Under Namespace

Modules: Coercion

Constant Summary

Constants included from Representable

VERSION

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Representable

included, #update_properties_from

Constructor Details

#initialize(represented) ⇒ Decorator

Returns a new instance of Decorator.



12
13
14
# File 'lib/representable/decorator.rb', line 12

def initialize(represented)
  @represented = represented
end

Instance Attribute Details

#representedObject (readonly) Also known as: decorated

Returns the value of attribute represented.



3
4
5
# File 'lib/representable/decorator.rb', line 3

def represented
  @represented
end

Class Method Details

.prepare(represented) ⇒ Object



6
7
8
# File 'lib/representable/decorator.rb', line 6

def self.prepare(represented)
  new(represented)  # was: PrepareStrategy::Decorate.
end

Instance Method Details

#representable_binding_for(attr, format, options) ⇒ Object



16
17
18
19
20
# File 'lib/representable/decorator.rb', line 16

def representable_binding_for(attr, format, options)
  context = attr.options[:decorator_scope] ? self : represented  # DISCUSS: should Decorator know this kinda stuff?

  format.build(attr, represented, options, context)
end