Sha256: 7d79beeaa6d79c148c95abe62685facfa0ac51a34a916ccaced6679df9dc7048

Contents?: true

Size: 724 Bytes

Versions: 9

Compression:

Stored size: 724 Bytes

Contents

module Praxis

  class CollectionView
    attr_reader :name, :schema, :using

    def initialize(name, schema, using)
      @name = name
      @schema = schema
      @using = using
    end

    def dump(collection, context: Attributor::DEFAULT_ROOT_CONTEXT,**opts)
      collection.collect.with_index do |object, i|
        subcontext = context + ["at(#{i})"]
        using.dump(object, context: subcontext, **opts)
      end
    end

    def example(context=Attributor::DEFAULT_ROOT_CONTEXT)
      collection = self.schema.example(context)
      opts = {}
      opts[:context] = context if context
      self.dump(collection, opts)
    end

    def describe
      using.describe.merge(type: :collection)
    end

  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
praxis-blueprints-2.2 lib/praxis-blueprints/collection_view.rb
praxis-blueprints-2.1 lib/praxis-blueprints/collection_view.rb
praxis-blueprints-2.0.1 lib/praxis-blueprints/collection_view.rb
praxis-blueprints-2.0 lib/praxis-blueprints/collection_view.rb
praxis-blueprints-1.3.1 lib/praxis-blueprints/collection_view.rb
praxis-blueprints-1.3.0 lib/praxis-blueprints/collection_view.rb
praxis-blueprints-1.2.0 lib/praxis-blueprints/collection_view.rb
praxis-blueprints-1.1.1 lib/praxis-blueprints/collection_view.rb
praxis-blueprints-1.1.0 lib/praxis-blueprints/collection_view.rb