module Representable::Cached

Using this module only makes sense with Decorator representers.

Public Instance Methods

representable_mapper(format, options) click to toggle source

The main point here is that the decorator instance simply saves its mapper. Since the mapper in turn stores the bindings, we have a straight-forward way of “caching” the bindings without having to mess around on the class level: this all happens in the decorator instance.

Every binding in turn stores its nested representer (if it has one), implementing a recursive caching.

Decorator -> Mapper -> [Binding->Decorator, Binding]

Calls superclass method
# File lib/representable/cached.rb, line 11
def representable_mapper(format, options)
  @mapper ||= super.tap do |mapper|
    mapper.bindings(represented, options).each { |binding| binding.extend(Binding) }
  end
end
update!(represented) click to toggle source

replace represented for each property in this representer.

# File lib/representable/cached.rb, line 18
def update!(represented)
  @represented = represented
  self
end