Class: ScopedSerializer::ArraySerializer
- Inherits:
-
BaseSerializer
- Object
- BaseSerializer
- ScopedSerializer::ArraySerializer
- Defined in:
- lib/scoped_serializer/array_serializer.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#array ⇒ Object
readonly
Returns the value of attribute array.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
-
#scope_name ⇒ Object
readonly
Returns the value of attribute scope_name.
Instance Method Summary collapse
-
#initialize(array, scope_name = :default, options = {}) ⇒ ArraySerializer
constructor
A new instance of ArraySerializer.
- #meta ⇒ Object
- #serializable_hash(options = {}) ⇒ Object
Methods inherited from BaseSerializer
#as_json, #default_root_key, #meta_hash, #set_scope
Constructor Details
#initialize(array, scope_name = :default, options = {}) ⇒ ArraySerializer
Returns a new instance of ArraySerializer.
6 7 8 9 10 |
# File 'lib/scoped_serializer/array_serializer.rb', line 6 def initialize(array, scope_name=:default, ={}) @array = array @scope_name = scope_name = || {} end |
Instance Attribute Details
#array ⇒ Object (readonly)
Returns the value of attribute array.
4 5 6 |
# File 'lib/scoped_serializer/array_serializer.rb', line 4 def array @array end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
4 5 6 |
# File 'lib/scoped_serializer/array_serializer.rb', line 4 def end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
4 5 6 |
# File 'lib/scoped_serializer/array_serializer.rb', line 4 def scope @scope end |
#scope_name ⇒ Object (readonly)
Returns the value of attribute scope_name.
4 5 6 |
# File 'lib/scoped_serializer/array_serializer.rb', line 4 def scope_name @scope_name end |
Instance Method Details
#meta ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/scoped_serializer/array_serializer.rb', line 18 def data = super if @array.respond_to?(:total_count) data = {}.merge(data).merge({ :total_count => @array.total_count }) end data end |
#serializable_hash(options = {}) ⇒ Object
12 13 14 15 16 |
# File 'lib/scoped_serializer/array_serializer.rb', line 12 def serializable_hash(={}) array.collect do |object| ScopedSerializer.for(object, @scope_name, .merge(:root => false)).as_json end end |