Class: ScopedSerializer::CollectionSerializer

Inherits:
ArraySerializer show all
Defined in:
lib/scoped_serializer/collection_serializer.rb

Instance Attribute Summary

Attributes inherited from ArraySerializer

#array, #options

Instance Method Summary collapse

Methods inherited from ArraySerializer

#meta, #serializable_hash

Methods inherited from BaseSerializer

#as_json, #default_root_key, #meta, #meta_hash, #set_scope, #to_xls

Constructor Details

#initialize(*args) ⇒ CollectionSerializer

Returns a new instance of CollectionSerializer.



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/scoped_serializer/collection_serializer.rb', line 4

def initialize(*args)
  super

  options = args.extract_options!

  # Allow to define own model class
  @model_class = options.delete(:model_class) || @array.klass

  # Configure root element
  @options[:root] = default_root_key(@model_class).pluralize if @options[:root].nil?
end

Instance Method Details

#to_csv(options = {}) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/scoped_serializer/collection_serializer.rb', line 16

def to_csv(options={})
  attributes = ScopedSerializer.find_serializer_by_class(@model_class)
         .find_scope(options[:scope] || :default)
         .attributes

  super(options.merge(:columns => attributes))
end