Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

preliminary implementation of ability to serialize arrays

  • Loading branch information...
commit fbff40fd4d58063f043c68704bcf2864c934d46b 1 parent e6226b6
ambert ho ambertch authored
2  VERSION
View
@@ -1 +1 @@
-0.4.0
+0.4.1
2  activerecord-postgres-hstore.gemspec
View
@@ -8,7 +8,7 @@ Gem::Specification.new do |s|
s.version = "0.4.0"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
- s.authors = ["Juan Maiz", "Diogo Biazus"]
+ s.authors = ["Juan Maiz", "Diogo Biazus", "Ambert Ho"]
s.date = "2012-05-22"
s.description = "This gem adds support for the postgres hstore type. It is the _just right_ alternative for storing hashes instead of using seralization or dynamic tables."
s.email = "juanmaiz@gmail.com"
1  lib/activerecord-postgres-hstore.rb
View
@@ -2,3 +2,4 @@
require "activerecord-postgres-hstore/string"
require "activerecord-postgres-hstore/hash"
require "activerecord-postgres-hstore/coder"
+require "activerecord-postgres-hstore/array"
26 lib/activerecord-postgres-hstore/array.rb
View
@@ -0,0 +1,26 @@
+class Array
+
+ def to_hstore
+ return "" if empty?
+ map { |val|
+ iv = [val].map { |_|
+ e = _.to_s.gsub(/"/, '\"')
+ if _.nil?
+ 'NULL'
+ elsif e =~ /[,\s=>]/ || e.blank?
+ '"%s"' % e
+ else
+ e
+ end
+ }
+
+ "%s=>NULL" % iv
+ } * ","
+ end
+
+ # If the method from_hstore is called in a Hash, it just returns self.
+ def from_hstore
+ self
+ end
+
+end
4 lib/activerecord-postgres-hstore/hash.rb
View
@@ -21,9 +21,9 @@ def to_hstore
} * ","
end
- # If the method from_hstore is called in a Hash, it just returns self.
def from_hstore
- self
+ puts "*"*200
+ puts "I WAS CALLED"
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.