Sha256: 21b838f1bc609b95a377bb8f106fd38e03d26cf5606500546c714cf4b21bd93e

Contents?: true

Size: 1.17 KB

Versions: 5

Compression:

Stored size: 1.17 KB

Contents

require "uber/inheritable_attr"
require "representable"

module Representable
  class Decorator
    attr_reader :represented
    alias_method :decorated, :represented

    # TODO: when moving all class methods into ClassMethods, i get a segfault.
    def self.prepare(represented)
      new(represented)
    end

    def self.default_nested_class #FIXME. SHOULD we move that into NestedBuilder?
      Representable::Decorator
    end

    # extend ::Declarative::Heritage::Inherited # DISCUSS: currently, that is handled via Representable::inherited.

    # This is called from inheritable_attr when inheriting a decorator class to a subclass.
    # Explicitly subclassing the Decorator makes sure representable_attrs is a clean version.
    def self.clone
      Class.new(self)
    end

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

    extend Uber::InheritableAttr
    inheritable_attr :map
    self.map = Binding::Map.new

    def initialize(represented)
      @represented = represented
    end

    def self.nested_builder
      ::Declarative::Schema::DSL::NestedBuilder
    end
  end
end

Version data entries

5 entries across 5 versions & 3 rubygems

Version Path
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/representable-3.2.0/lib/representable/decorator.rb
fluent-plugin-google-cloud-logging-on-prem-0.1.0 vendor/ruby/3.1.0/gems/representable-3.2.0/lib/representable/decorator.rb
representable-3.2.0 lib/representable/decorator.rb
representable-3.1.1 lib/representable/decorator.rb
representable-3.1.0 lib/representable/decorator.rb