Sha256: 3f9c0d61c66c0206f11b2e29d937c8ce6475cfe06097998552ae58312bfe0f13

Contents?: true

Size: 936 Bytes

Versions: 12

Compression:

Stored size: 936 Bytes

Contents

module Representable
  # Gives us Representer::for_collection and its configuration directive
  # ::collection_representer.
  module ForCollection
    def for_collection
      # this is done at run-time, not a big fan of this. however, it saves us from inheritance/self problems.
      @collection_representer ||= collection_representer!({}) # DON'T make it inheritable as it would inherit the wrong singular.
    end

  private
    def collection_representer!(options)
      singular = self

      # what happens here is basically
      # Module.new { include Representable::JSON::Collection; ... }
      nested_builder.(
        _base:     default_nested_class,
        _features: [singular.collection_representer_class],
        _block:    ->(*) { items options.merge(:extend => singular) }
      )
    end

    def collection_representer(options={})
      @collection_representer = collection_representer!(options)
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
representable-3.0.4 lib/representable/for_collection.rb
representable-3.0.3 lib/representable/for_collection.rb
representable-3.0.2 lib/representable/for_collection.rb
representable-3.0.1 lib/representable/for_collection.rb
representable-3.0.0 lib/representable/for_collection.rb
representable-2.4.1 lib/representable/for_collection.rb
representable-2.4.0 lib/representable/for_collection.rb
representable-2.4.0.rc5 lib/representable/for_collection.rb
representable-2.4.0.rc4 lib/representable/for_collection.rb
representable-2.4.0.rc3 lib/representable/for_collection.rb
representable-2.4.0.rc2 lib/representable/for_collection.rb
representable-2.4.0.rc1 lib/representable/for_collection.rb