Module: ActiveRecord::Collections::Serialization
- Included in:
- ActiveRecord::Collection
- Defined in:
- lib/active_record/collections/serialization.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
- #as_json(options = nil) ⇒ Object
- #to_hash(include_limit = false) ⇒ Object (also: #to_h)
- #to_json(options = nil) ⇒ Object
- #to_param ⇒ Object
- #to_sql ⇒ Object
Class Method Details
.included(base) ⇒ Object
4 5 6 |
# File 'lib/active_record/collections/serialization.rb', line 4 def self.included(base) base.send :extend, ClassMethods end |
Instance Method Details
#as_json(options = nil) ⇒ Object
74 75 76 77 78 79 |
# File 'lib/active_record/collections/serialization.rb', line 74 def as_json(=nil) h = to_hash h[:collectable] = h[:collectable].try(:name) h[:collection] = h[:collection].name if h.has_key?(:collection) h.as_json() end |
#to_hash(include_limit = false) ⇒ Object Also known as: to_h
66 67 68 69 70 71 |
# File 'lib/active_record/collections/serialization.rb', line 66 def to_hash(include_limit=false) values = relation.values.merge({collectable: collectable}) values.merge!({limit: nil, offset: nil}) if !include_limit && !try(:is_batch?) values[:collection] = self.class if self.class < ActiveRecord::Collection ActiveRecord::Collections::Serializer.to_hash(values) end |
#to_json(options = nil) ⇒ Object
81 82 83 |
# File 'lib/active_record/collections/serialization.rb', line 81 def to_json(=nil) as_json.to_json() end |
#to_param ⇒ Object
85 86 87 |
# File 'lib/active_record/collections/serialization.rb', line 85 def to_param to_json end |
#to_sql ⇒ Object
62 63 64 |
# File 'lib/active_record/collections/serialization.rb', line 62 def to_sql relation.to_sql end |