Class: ActiveRecord::Collections::Serializer
- Inherits:
-
Object
- Object
- ActiveRecord::Collections::Serializer
- Defined in:
- lib/active_record/collections/serializer.rb
Instance Attribute Summary collapse
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Class Method Summary collapse
Instance Method Summary collapse
- #bind ⇒ Object
- #collectable ⇒ Object
- #collection ⇒ Object
- #distinct ⇒ Object
- #group ⇒ Object
- #includes ⇒ Object
- #joins ⇒ Object
- #limit ⇒ Object
- #offset ⇒ Object
- #order ⇒ Object
- #references ⇒ Object
- #select ⇒ Object
- #to_hash ⇒ Object
- #where ⇒ Object
Instance Attribute Details
#values ⇒ Object (readonly)
Returns the value of attribute values.
4 5 6 |
# File 'lib/active_record/collections/serializer.rb', line 4 def values @values end |
Class Method Details
.to_hash(*args) ⇒ Object
6 7 8 |
# File 'lib/active_record/collections/serializer.rb', line 6 def self.to_hash(*args) new(*args).to_hash end |
Instance Method Details
#bind ⇒ Object
54 55 56 |
# File 'lib/active_record/collections/serializer.rb', line 54 def bind @bind ||= values[:bind].map { |b| {name: b.first.name.to_s, value: b.last} } end |
#collectable ⇒ Object
10 11 12 |
# File 'lib/active_record/collections/serializer.rb', line 10 def collectable values[:collectable] end |
#collection ⇒ Object
14 15 16 |
# File 'lib/active_record/collections/serializer.rb', line 14 def collection values[:collection] end |
#distinct ⇒ Object
22 23 24 |
# File 'lib/active_record/collections/serializer.rb', line 22 def distinct values[:distinct] end |
#group ⇒ Object
38 39 40 |
# File 'lib/active_record/collections/serializer.rb', line 38 def group values[:group].map { |v| (v.is_a?(String) || v.is_a?(Symbol)) ? v : v.to_sql } end |
#includes ⇒ Object
30 31 32 |
# File 'lib/active_record/collections/serializer.rb', line 30 def includes values[:includes] end |
#joins ⇒ Object
26 27 28 |
# File 'lib/active_record/collections/serializer.rb', line 26 def joins values[:joins] end |
#limit ⇒ Object
46 47 48 |
# File 'lib/active_record/collections/serializer.rb', line 46 def limit values[:limit] end |
#offset ⇒ Object
50 51 52 |
# File 'lib/active_record/collections/serializer.rb', line 50 def offset values[:offset] end |
#order ⇒ Object
42 43 44 |
# File 'lib/active_record/collections/serializer.rb', line 42 def order values[:order].map { |v| (v.is_a?(String) || v.is_a?(Symbol)) ? v : v.to_sql } end |
#references ⇒ Object
34 35 36 |
# File 'lib/active_record/collections/serializer.rb', line 34 def references values[:references] end |
#select ⇒ Object
18 19 20 |
# File 'lib/active_record/collections/serializer.rb', line 18 def select values[:select] end |
#to_hash ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/active_record/collections/serializer.rb', line 79 def to_hash { collectable: collectable, collection: collection, select: select, distinct: distinct, joins: joins, includes: includes, references: references, where: where, bind: bind, group: group, order: order, limit: limit, offset: offset } end |
#where ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/active_record/collections/serializer.rb', line 58 def where return @where unless @where.nil? @where = values[:where].map { |node| serialize_node(node) } hashed = {} @where.select! do |w| if w.is_a?(Hash) if hashed.has_key?(w.keys.first) hashed[w.keys.first].merge!(w.values.first) else hashed[w.keys.first] = w.values.first end false else true end end @where.unshift(hashed) @where end |