Sha256: 40b31344eb32146644331a76764491f6fec259d529e6751b6c750b7c3d1929b0

Contents?: true

Size: 866 Bytes

Versions: 20

Compression:

Stored size: 866 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; ... }
      build_inline(nil, [singular.collection_representer_class], "", {}) {
        items options.merge(:extend => singular)
      }
    end

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

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
representable-2.3.0 lib/representable/for_collection.rb
representable-2.2.3 lib/representable/for_collection.rb
representable-2.2.2 lib/representable/for_collection.rb
representable-2.2.1 lib/representable/for_collection.rb
representable-2.2.0 lib/representable/for_collection.rb
representable-2.1.8 lib/representable/for_collection.rb
representable-2.1.7 lib/representable/for_collection.rb
representable-2.1.6 lib/representable/for_collection.rb
representable-2.1.5 lib/representable/for_collection.rb
representable-2.1.4 lib/representable/for_collection.rb
representable-2.1.3 lib/representable/for_collection.rb
representable-2.1.1 lib/representable/for_collection.rb
representable-2.1.0 lib/representable/for_collection.rb
representable-2.0.4 lib/representable/for_collection.rb
representable-2.0.3 lib/representable/for_collection.rb
representable-2.0.2 lib/representable/for_collection.rb
representable-2.0.1 lib/representable/for_collection.rb
representable-2.0.0 lib/representable/for_collection.rb
representable-2.0.0.rc2 lib/representable/for_collection.rb
representable-2.0.0.rc1 lib/representable/for_collection.rb