Class: Praxis::CollectionView
- Inherits:
-
Object
- Object
- Praxis::CollectionView
- Defined in:
- lib/praxis-blueprints/collection_view.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
-
#using ⇒ Object
readonly
Returns the value of attribute using.
Instance Method Summary collapse
- #describe ⇒ Object
- #dump(collection, context: Attributor::DEFAULT_ROOT_CONTEXT, **opts) ⇒ Object
- #example(context = Attributor::DEFAULT_ROOT_CONTEXT) ⇒ Object
-
#initialize(name, schema, using) ⇒ CollectionView
constructor
A new instance of CollectionView.
Constructor Details
#initialize(name, schema, using) ⇒ CollectionView
Returns a new instance of CollectionView.
6 7 8 9 10 |
# File 'lib/praxis-blueprints/collection_view.rb', line 6 def initialize(name, schema, using) @name = name @schema = schema @using = using end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/praxis-blueprints/collection_view.rb', line 4 def name @name end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
4 5 6 |
# File 'lib/praxis-blueprints/collection_view.rb', line 4 def schema @schema end |
#using ⇒ Object (readonly)
Returns the value of attribute using.
4 5 6 |
# File 'lib/praxis-blueprints/collection_view.rb', line 4 def using @using end |
Instance Method Details
#describe ⇒ Object
26 27 28 |
# File 'lib/praxis-blueprints/collection_view.rb', line 26 def describe using.describe.merge(type: :collection) end |
#dump(collection, context: Attributor::DEFAULT_ROOT_CONTEXT, **opts) ⇒ Object
12 13 14 15 16 17 |
# File 'lib/praxis-blueprints/collection_view.rb', line 12 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 |
#example(context = Attributor::DEFAULT_ROOT_CONTEXT) ⇒ Object
19 20 21 22 23 24 |
# File 'lib/praxis-blueprints/collection_view.rb', line 19 def example(context=Attributor::DEFAULT_ROOT_CONTEXT) collection = self.schema.example(context) opts = {} opts[:context] = context if context self.dump(collection, opts) end |