class Hash

Public Instance Methods

from_hstore() click to toggle source

If the method from_hstore is called in a Hash, it just returns self.

# File lib/padrino-hstore/hash.rb, line 25
def from_hstore
  self
end
to_hstore() click to toggle source

Generates an hstore string format. This is the format used to insert or update stuff in the database.

# File lib/padrino-hstore/hash.rb, line 5
def to_hstore
  return "" if empty?

  map { |idx, val| 
    iv = [idx,val].map { |_| 
      e = _.to_s.gsub(/"/, '\"')
      if _.nil?
        'NULL'
      elsif e =~ /[,\s=>]/ || e.blank?
        '"%s"' % e
      else
        e
      end
    }

    "%s=>%s" % iv
  } * ","
end