class Perpetuity::Postgres::JSONHash

Public Class Methods

new(value, location=:outer) click to toggle source
# File lib/perpetuity/postgres/json_hash.rb, line 7
def initialize value, location=:outer
  @value = value
  @location = location
end

Public Instance Methods

==(other) click to toggle source
# File lib/perpetuity/postgres/json_hash.rb, line 45
def == other
  other.is_a? self.class and
  other.to_hash == to_hash
end
serialize_elements() click to toggle source
# File lib/perpetuity/postgres/json_hash.rb, line 24
def serialize_elements
  @value.map do |key, value|
    string = ''
    string << JSONStringValue.new(key) << ':'

    string << if [String, Class].include? value.class
      JSONStringValue.new(value.to_s)
    elsif [true, false].include? value
      value.to_s
    elsif value.nil?
      'null'
    else
      SQLValue.new(value).to_s
    end
  end.join(',')
end
to_hash() click to toggle source
# File lib/perpetuity/postgres/json_hash.rb, line 20
def to_hash
  @value
end
to_s() click to toggle source
# File lib/perpetuity/postgres/json_hash.rb, line 12
def to_s
  if @location == :outer
    "'{#{serialize_elements}}'"
  else
    "{#{serialize_elements}}"
  end
end
to_str() click to toggle source
# File lib/perpetuity/postgres/json_hash.rb, line 41
def to_str
  to_s
end