Sha256: e2fbef996d9472856ef502b510aacd25f0f178c495ebfbf7b0300ad548e3c36a

Contents?: true

Size: 623 Bytes

Versions: 3

Compression:

Stored size: 623 Bytes

Contents

module Representable
  class Decorator
    attr_reader :represented

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

    include Representable # include after class methods so Decorator::prepare can't be overwritten by Representable::prepare.

    def initialize(represented)
      @represented = represented
    end

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

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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
representable-1.5.0 lib/representable/decorator.rb
representable-1.4.2 lib/representable/decorator.rb
representable-1.4.1 lib/representable/decorator.rb