Class: Perpetuity::Postgres::JSONArray

Inherits:
Object
  • Object
show all
Defined in:
lib/perpetuity/postgres/json_array.rb

Instance Method Summary collapse

Constructor Details

#initialize(value, position = :outer) ⇒ JSONArray

Returns a new instance of JSONArray.



7
8
9
10
# File 'lib/perpetuity/postgres/json_array.rb', line 7

def initialize value, position=:outer
  @value = value
  @position = position
end

Instance Method Details

#serialize_elementsObject



24
25
26
27
28
29
30
31
32
# File 'lib/perpetuity/postgres/json_array.rb', line 24

def serialize_elements
  @value.map do |element|
    if element.is_a? String
      JSONStringValue.new(element)
    else
      SQLValue.new(element)
    end
  end.join(',')
end

#to_aObject



34
35
36
# File 'lib/perpetuity/postgres/json_array.rb', line 34

def to_a
  @value
end

#to_inner_arrayObject



20
21
22
# File 'lib/perpetuity/postgres/json_array.rb', line 20

def to_inner_array
  "[#{serialize_elements}]"
end

#to_sObject



12
13
14
15
16
17
18
# File 'lib/perpetuity/postgres/json_array.rb', line 12

def to_s
  if @position == :outer
    "'#{to_inner_array}'"
  else
    to_inner_array
  end
end