Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

correctly return an array if an array was serialized as keys (therefo…

…re all values nil)
  • Loading branch information...
commit 86f1931aa6132975c7a58ce350f127d62fc7fc89 1 parent fbff40f
RPX Corporation authored
View
7 lib/activerecord-postgres-hstore/array.rb
@@ -17,10 +17,5 @@ def to_hstore
"%s=>NULL" % iv
} * ","
end
-
- # If the method from_hstore is called in a Hash, it just returns self.
- def from_hstore
- self
- end
-
+
end
View
5 lib/activerecord-postgres-hstore/hash.rb
@@ -21,9 +21,4 @@ def to_hstore
} * ","
end
- def from_hstore
- puts "*"*200
- puts "I WAS CALLED"
- end
-
end
View
14 lib/activerecord-postgres-hstore/string.rb
@@ -18,7 +18,7 @@ def valid_hstore?
# Creates a hash from a valid double quoted hstore format, 'cause this is the format
# that postgresql spits out.
- def from_hstore
+ def from_hstore
token_pairs = (scan(hstore_pair)).map { |k,v| [k,v =~ /^NULL$/i ? nil : v] }
token_pairs = token_pairs.map { |k,v|
[k,v].map { |t|
@@ -29,10 +29,20 @@ def from_hstore
end
}
}
- Hash[ token_pairs ]
+
+ return appropriate_format token_pairs
end
private
+
+ # correctly return an array if all values are nil
+ def appropriate_format token_pairs
+ if token_pairs.collect(&:last).compact.empty?
+ return token_pairs.flatten.compact
+ else
+ return Hash[ token_pairs ]
+ end
+ end
def hstore_pair
quoted_string = /"[^"\\]*(?:\\.[^"\\]*)*"/
Please sign in to comment.
Something went wrong with that request. Please try again.