Class: Perpetuity::Postgres::JSONArray
- Inherits:
-
Object
- Object
- Perpetuity::Postgres::JSONArray
- Defined in:
- lib/perpetuity/postgres/json_array.rb
Instance Method Summary collapse
-
#initialize(value, position = :outer) ⇒ JSONArray
constructor
A new instance of JSONArray.
- #serialize_elements ⇒ Object
- #to_a ⇒ Object
- #to_inner_array ⇒ Object
- #to_s ⇒ Object
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_elements ⇒ Object
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_a ⇒ Object
34 35 36 |
# File 'lib/perpetuity/postgres/json_array.rb', line 34 def to_a @value end |
#to_inner_array ⇒ Object
20 21 22 |
# File 'lib/perpetuity/postgres/json_array.rb', line 20 def to_inner_array "[#{serialize_elements}]" end |
#to_s ⇒ Object
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 |