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
- #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
#to_hash(include_limit = false) ⇒ Object Also known as: to_h
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/active_record/collections/serialization.rb', line 33 def to_hash(include_limit=false) h = { select: relation.select_values, distinct: relation.distinct_value, joins: relation.joins_values, references: relation.references_values, includes: relation.includes_values, where: relation.where_values.map { |v| v.is_a?(String) ? v : v.to_sql }, order: relation.order_values.map { |v| v.is_a?(String) ? v : v.to_sql }, bind: relation.bind_values.map { |b| {name: b.first.name, value: b.last} } } if include_limit || try(:is_batch?) h[:limit] = relation.limit_value h[:offset] = relation.offset_value end h end |
#to_json(options = nil) ⇒ Object
52 53 54 |
# File 'lib/active_record/collections/serialization.rb', line 52 def to_json(=nil) to_hash.to_json end |
#to_param ⇒ Object
56 57 58 |
# File 'lib/active_record/collections/serialization.rb', line 56 def to_param to_json end |
#to_sql ⇒ Object
29 30 31 |
# File 'lib/active_record/collections/serialization.rb', line 29 def to_sql relation.to_sql end |