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