Class: ActiveRecord::Collections::Serializer

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/collections/serializer.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#valuesObject (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

#bindObject



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

#collectableObject



10
11
12
# File 'lib/active_record/collections/serializer.rb', line 10

def collectable
  values[:collectable]
end

#collectionObject



14
15
16
# File 'lib/active_record/collections/serializer.rb', line 14

def collection
  values[:collection]
end

#distinctObject



22
23
24
# File 'lib/active_record/collections/serializer.rb', line 22

def distinct
  values[:distinct]
end

#groupObject



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

#includesObject



30
31
32
# File 'lib/active_record/collections/serializer.rb', line 30

def includes
  values[:includes]
end

#joinsObject



26
27
28
# File 'lib/active_record/collections/serializer.rb', line 26

def joins
  values[:joins]
end

#limitObject



46
47
48
# File 'lib/active_record/collections/serializer.rb', line 46

def limit
  values[:limit]
end

#offsetObject



50
51
52
# File 'lib/active_record/collections/serializer.rb', line 50

def offset
  values[:offset]
end

#orderObject



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

#referencesObject



34
35
36
# File 'lib/active_record/collections/serializer.rb', line 34

def references
  values[:references]
end

#selectObject



18
19
20
# File 'lib/active_record/collections/serializer.rb', line 18

def select
  values[:select]
end

#to_hashObject



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

#whereObject



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