Class: Hash
- Inherits:
-
Object
- Object
- Hash
- Defined in:
- lib/padrino-hstore/hash.rb
Instance Method Summary collapse
-
#from_hstore ⇒ Object
If the method from_hstore is called in a Hash, it just returns self.
-
#to_hstore ⇒ Object
Generates an hstore string format.
Instance Method Details
#from_hstore ⇒ Object
If the method from_hstore is called in a Hash, it just returns self.
25 26 27 |
# File 'lib/padrino-hstore/hash.rb', line 25 def from_hstore self end |
#to_hstore ⇒ Object
Generates an hstore string format. This is the format used to insert or update stuff in the database.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
# 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 |