activerecord-postgres-hstore 0.4.0 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +0 -1
- data/Gemfile.lock +48 -49
- data/README.md +31 -17
- data/VERSION +1 -1
- data/activerecord-postgres-hstore.gemspec +2 -5
- data/lib/activerecord-postgres-hstore/activerecord.rb +21 -5
- data/lib/activerecord-postgres-hstore/hash.rb +24 -14
- data/lib/activerecord-postgres-hstore/string.rb +1 -1
- data/spec/activerecord-postgres-hstore_spec.rb +23 -1
- metadata +19 -30
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,54 +1,54 @@
|
|
|
1
1
|
GEM
|
|
2
2
|
remote: http://rubygems.org/
|
|
3
3
|
specs:
|
|
4
|
-
actionmailer (3.2.
|
|
5
|
-
actionpack (= 3.2.
|
|
4
|
+
actionmailer (3.2.8)
|
|
5
|
+
actionpack (= 3.2.8)
|
|
6
6
|
mail (~> 2.4.4)
|
|
7
|
-
actionpack (3.2.
|
|
8
|
-
activemodel (= 3.2.
|
|
9
|
-
activesupport (= 3.2.
|
|
7
|
+
actionpack (3.2.8)
|
|
8
|
+
activemodel (= 3.2.8)
|
|
9
|
+
activesupport (= 3.2.8)
|
|
10
10
|
builder (~> 3.0.0)
|
|
11
11
|
erubis (~> 2.7.0)
|
|
12
|
-
journey (~> 1.0.
|
|
12
|
+
journey (~> 1.0.4)
|
|
13
13
|
rack (~> 1.4.0)
|
|
14
14
|
rack-cache (~> 1.2)
|
|
15
15
|
rack-test (~> 0.6.1)
|
|
16
|
-
sprockets (~> 2.1.
|
|
17
|
-
activemodel (3.2.
|
|
18
|
-
activesupport (= 3.2.
|
|
16
|
+
sprockets (~> 2.1.3)
|
|
17
|
+
activemodel (3.2.8)
|
|
18
|
+
activesupport (= 3.2.8)
|
|
19
19
|
builder (~> 3.0.0)
|
|
20
|
-
activerecord (3.2.
|
|
21
|
-
activemodel (= 3.2.
|
|
22
|
-
activesupport (= 3.2.
|
|
20
|
+
activerecord (3.2.8)
|
|
21
|
+
activemodel (= 3.2.8)
|
|
22
|
+
activesupport (= 3.2.8)
|
|
23
23
|
arel (~> 3.0.2)
|
|
24
24
|
tzinfo (~> 0.3.29)
|
|
25
|
-
activeresource (3.2.
|
|
26
|
-
activemodel (= 3.2.
|
|
27
|
-
activesupport (= 3.2.
|
|
28
|
-
activesupport (3.2.
|
|
25
|
+
activeresource (3.2.8)
|
|
26
|
+
activemodel (= 3.2.8)
|
|
27
|
+
activesupport (= 3.2.8)
|
|
28
|
+
activesupport (3.2.8)
|
|
29
29
|
i18n (~> 0.6)
|
|
30
30
|
multi_json (~> 1.0)
|
|
31
31
|
arel (3.0.2)
|
|
32
|
-
builder (3.0.
|
|
32
|
+
builder (3.0.3)
|
|
33
33
|
diff-lcs (1.1.3)
|
|
34
34
|
erubis (2.7.0)
|
|
35
35
|
git (1.2.5)
|
|
36
36
|
hike (1.2.1)
|
|
37
|
-
i18n (0.6.
|
|
38
|
-
jeweler (1.8.
|
|
37
|
+
i18n (0.6.1)
|
|
38
|
+
jeweler (1.8.4)
|
|
39
39
|
bundler (~> 1.0)
|
|
40
40
|
git (>= 1.2.5)
|
|
41
41
|
rake
|
|
42
42
|
rdoc
|
|
43
|
-
journey (1.0.
|
|
44
|
-
json (1.7.
|
|
43
|
+
journey (1.0.4)
|
|
44
|
+
json (1.7.5)
|
|
45
45
|
mail (2.4.4)
|
|
46
46
|
i18n (>= 0.4.0)
|
|
47
47
|
mime-types (~> 1.16)
|
|
48
48
|
treetop (~> 1.4.8)
|
|
49
|
-
mime-types (1.
|
|
50
|
-
multi_json (1.3.
|
|
51
|
-
pg (0.
|
|
49
|
+
mime-types (1.19)
|
|
50
|
+
multi_json (1.3.6)
|
|
51
|
+
pg (0.14.1)
|
|
52
52
|
polyglot (0.3.3)
|
|
53
53
|
rack (1.4.1)
|
|
54
54
|
rack-cache (1.2)
|
|
@@ -57,43 +57,43 @@ GEM
|
|
|
57
57
|
rack
|
|
58
58
|
rack-test (0.6.1)
|
|
59
59
|
rack (>= 1.0)
|
|
60
|
-
rails (3.2.
|
|
61
|
-
actionmailer (= 3.2.
|
|
62
|
-
actionpack (= 3.2.
|
|
63
|
-
activerecord (= 3.2.
|
|
64
|
-
activeresource (= 3.2.
|
|
65
|
-
activesupport (= 3.2.
|
|
60
|
+
rails (3.2.8)
|
|
61
|
+
actionmailer (= 3.2.8)
|
|
62
|
+
actionpack (= 3.2.8)
|
|
63
|
+
activerecord (= 3.2.8)
|
|
64
|
+
activeresource (= 3.2.8)
|
|
65
|
+
activesupport (= 3.2.8)
|
|
66
66
|
bundler (~> 1.0)
|
|
67
|
-
railties (= 3.2.
|
|
68
|
-
railties (3.2.
|
|
69
|
-
actionpack (= 3.2.
|
|
70
|
-
activesupport (= 3.2.
|
|
67
|
+
railties (= 3.2.8)
|
|
68
|
+
railties (3.2.8)
|
|
69
|
+
actionpack (= 3.2.8)
|
|
70
|
+
activesupport (= 3.2.8)
|
|
71
71
|
rack-ssl (~> 1.3.2)
|
|
72
72
|
rake (>= 0.8.7)
|
|
73
73
|
rdoc (~> 3.4)
|
|
74
|
-
thor (
|
|
74
|
+
thor (>= 0.14.6, < 2.0)
|
|
75
75
|
rake (0.9.2.2)
|
|
76
|
-
rcov (0.9.11)
|
|
77
76
|
rdoc (3.12)
|
|
78
77
|
json (~> 1.4)
|
|
79
|
-
rspec (2.
|
|
80
|
-
rspec-core (~> 2.
|
|
81
|
-
rspec-expectations (~> 2.
|
|
82
|
-
rspec-mocks (~> 2.
|
|
83
|
-
rspec-core (2.
|
|
84
|
-
rspec-expectations (2.
|
|
78
|
+
rspec (2.11.0)
|
|
79
|
+
rspec-core (~> 2.11.0)
|
|
80
|
+
rspec-expectations (~> 2.11.0)
|
|
81
|
+
rspec-mocks (~> 2.11.0)
|
|
82
|
+
rspec-core (2.11.1)
|
|
83
|
+
rspec-expectations (2.11.3)
|
|
85
84
|
diff-lcs (~> 1.1.3)
|
|
86
|
-
rspec-mocks (2.
|
|
87
|
-
shoulda (3.
|
|
88
|
-
shoulda-context (~> 1.0
|
|
89
|
-
shoulda-matchers (~> 1.
|
|
85
|
+
rspec-mocks (2.11.2)
|
|
86
|
+
shoulda (3.1.1)
|
|
87
|
+
shoulda-context (~> 1.0)
|
|
88
|
+
shoulda-matchers (~> 1.2)
|
|
90
89
|
shoulda-context (1.0.0)
|
|
91
|
-
shoulda-matchers (1.
|
|
90
|
+
shoulda-matchers (1.3.0)
|
|
91
|
+
activesupport (>= 3.0.0)
|
|
92
92
|
sprockets (2.1.3)
|
|
93
93
|
hike (~> 1.2)
|
|
94
94
|
rack (~> 1.0)
|
|
95
95
|
tilt (~> 1.1, != 1.3.0)
|
|
96
|
-
thor (0.
|
|
96
|
+
thor (0.16.0)
|
|
97
97
|
tilt (1.3.3)
|
|
98
98
|
treetop (1.4.10)
|
|
99
99
|
polyglot
|
|
@@ -109,7 +109,6 @@ DEPENDENCIES
|
|
|
109
109
|
pg
|
|
110
110
|
rails
|
|
111
111
|
rake
|
|
112
|
-
rcov
|
|
113
112
|
rdoc
|
|
114
113
|
rspec
|
|
115
114
|
shoulda
|
data/README.md
CHANGED
|
@@ -13,22 +13,22 @@ Requirements
|
|
|
13
13
|
------------
|
|
14
14
|
|
|
15
15
|
Postgresql 8.4+ (also tested with 9.0) with contrib and Rails 3. (It
|
|
16
|
-
might work on 2.3.x with minor patches…)
|
|
16
|
+
might work on 2.3.x with minor patches…)
|
|
17
17
|
On Ubuntu, this is easy: `sudo apt-get install postgresql-contrib-9.0`
|
|
18
18
|
|
|
19
|
-
On Mac <del> …you are screwed. Use a VM. </del> you should use [the binary package kindly provided by EnterpriseDB](http://www.enterprisedb.com/products-services-training/pgdownload#osx)
|
|
19
|
+
On Mac <del> …you are screwed. Use a VM. </del> you should use [the binary package kindly provided by EnterpriseDB](http://www.enterprisedb.com/products-services-training/pgdownload#osx)
|
|
20
20
|
[Homebrew’s](https://github.com/mxcl/homebrew) Postgres installation also includes the contrib packages: `brew install postgres`
|
|
21
21
|
|
|
22
22
|
Notes for Rails 3.1 and above
|
|
23
23
|
-----------------------------
|
|
24
24
|
|
|
25
|
-
The master branch already support a custom serialization coder.
|
|
25
|
+
The master branch already support a custom serialization coder.
|
|
26
26
|
If you want to use it just put in your Gemfile:
|
|
27
27
|
|
|
28
28
|
gem 'activerecord-postgres-hstore', git: 'git://github.com/softa/activerecord-postgres-hstore.git'
|
|
29
29
|
|
|
30
30
|
If you install them gem from the master branch you also have to insert a
|
|
31
|
-
line in each model that uses hstore.
|
|
31
|
+
line in each model that uses hstore.
|
|
32
32
|
Assuming a model called **Person**, with a **data** field on it, the
|
|
33
33
|
code should look like:
|
|
34
34
|
|
|
@@ -63,7 +63,7 @@ e.g.:
|
|
|
63
63
|
database: hstorage_dev
|
|
64
64
|
encoding: unicode
|
|
65
65
|
username: postgres
|
|
66
|
-
password:
|
|
66
|
+
password:
|
|
67
67
|
pool: 5
|
|
68
68
|
|
|
69
69
|
Now you need to create a migration that adds hstore support for your
|
|
@@ -80,11 +80,11 @@ Finally you can create your own tables using hstore type. It’s easy:
|
|
|
80
80
|
rails g model Person name:string data:hstore
|
|
81
81
|
rake db:migrate
|
|
82
82
|
|
|
83
|
-
You’re done.
|
|
83
|
+
You’re done.
|
|
84
84
|
Well, not yet. Don’t forget to add indexes. Like this:
|
|
85
85
|
|
|
86
|
-
`CREATE INDEX people_gist_data ON people USING GIST(data);`
|
|
87
|
-
or
|
|
86
|
+
`CREATE INDEX people_gist_data ON people USING GIST(data);`
|
|
87
|
+
or
|
|
88
88
|
`CREATE INDEX people_gin_data ON people USING GIN(data);`
|
|
89
89
|
|
|
90
90
|
To understand the difference between the two types of indexes take a
|
|
@@ -94,7 +94,7 @@ Usage
|
|
|
94
94
|
-----
|
|
95
95
|
|
|
96
96
|
Once you have it installed, you just need to learn a little bit of new
|
|
97
|
-
sqls for selecting stuff (creating and updating is transparent).
|
|
97
|
+
sqls for selecting stuff (creating and updating is transparent).
|
|
98
98
|
Find records that contains a key named 'foo’:
|
|
99
99
|
|
|
100
100
|
Person.where("data ? 'foo'")
|
|
@@ -106,10 +106,10 @@ Find records where 'foo’ is equal to 'bar’:
|
|
|
106
106
|
This same sql is at least twice as fast (using indexes) if you do it
|
|
107
107
|
that way:
|
|
108
108
|
|
|
109
|
-
Person.where("data
|
|
110
|
-
|
|
109
|
+
Person.where("data @> 'foo=>bar'")
|
|
110
|
+
|
|
111
111
|
Find records where 'foo’ is not equal to 'bar’:
|
|
112
|
-
|
|
112
|
+
|
|
113
113
|
Person.where("data -> 'foo' <> 'bar'")
|
|
114
114
|
|
|
115
115
|
Find records where 'foo’ is like 'bar’:
|
|
@@ -128,7 +128,7 @@ The destroy\_key method returns 'self’, so you can chain it:
|
|
|
128
128
|
|
|
129
129
|
person.destroy_key(:data, :foo).destroy_key(:data, :bar).save
|
|
130
130
|
|
|
131
|
-
But there is a shortcuts for that:
|
|
131
|
+
But there is a shortcuts for that:
|
|
132
132
|
|
|
133
133
|
person.destroy_keys(:data, :foo, :bar)
|
|
134
134
|
|
|
@@ -140,6 +140,20 @@ and with many keys:
|
|
|
140
140
|
|
|
141
141
|
Person.delete_keys(:data, :foo, :bar)
|
|
142
142
|
|
|
143
|
+
Caveats
|
|
144
|
+
-------
|
|
145
|
+
|
|
146
|
+
hstore keys and values have to be strings. This means `true` will become `"true"` and `42` will become `"42"` after you save the record. Only `nil` values are preserved.
|
|
147
|
+
|
|
148
|
+
It is also confusing when querying:
|
|
149
|
+
|
|
150
|
+
Person.where("data -> 'foo' = :value", value: true).to_sql
|
|
151
|
+
#=> SELECT "people".* FROM "people" WHERE ("data -> 'foo' = 't'") # notice 't'
|
|
152
|
+
|
|
153
|
+
To avoid the above, make sure all named parameters are strings:
|
|
154
|
+
|
|
155
|
+
Person.where("data -> 'foo' = :value", value: some_var.to_s)
|
|
156
|
+
|
|
143
157
|
Have fun.
|
|
144
158
|
|
|
145
159
|
Help
|
|
@@ -151,10 +165,10 @@ twitter: [@dbiazus](https://twitter.com/#!/dbiazus) or [@joaomilho](https://twit
|
|
|
151
165
|
Note on Patches/Pull Requests
|
|
152
166
|
-----------------------------
|
|
153
167
|
|
|
154
|
-
* Fork the project.
|
|
155
|
-
* Make your feature addition or bug fix.
|
|
156
|
-
* Add tests for it. This is important so I don’t break it in a future version unintentionally.
|
|
157
|
-
* Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
|
168
|
+
* Fork the project.
|
|
169
|
+
* Make your feature addition or bug fix.
|
|
170
|
+
* Add tests for it. This is important so I don’t break it in a future version unintentionally.
|
|
171
|
+
* Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
|
158
172
|
* Send me a pull request. Bonus points for topic branches.
|
|
159
173
|
|
|
160
174
|
Copyright
|
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
0.4.
|
|
1
|
+
0.4.1
|
|
@@ -5,11 +5,11 @@
|
|
|
5
5
|
|
|
6
6
|
Gem::Specification.new do |s|
|
|
7
7
|
s.name = "activerecord-postgres-hstore"
|
|
8
|
-
s.version = "0.4.
|
|
8
|
+
s.version = "0.4.1"
|
|
9
9
|
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
|
11
11
|
s.authors = ["Juan Maiz", "Diogo Biazus"]
|
|
12
|
-
s.date = "2012-
|
|
12
|
+
s.date = "2012-09-14"
|
|
13
13
|
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."
|
|
14
14
|
s.email = "juanmaiz@gmail.com"
|
|
15
15
|
s.extra_rdoc_files = [
|
|
@@ -110,7 +110,6 @@ Gem::Specification.new do |s|
|
|
|
110
110
|
s.add_development_dependency(%q<jeweler>, ["~> 1.8.3"])
|
|
111
111
|
s.add_development_dependency(%q<rdoc>, [">= 0"])
|
|
112
112
|
s.add_development_dependency(%q<rspec>, [">= 0"])
|
|
113
|
-
s.add_development_dependency(%q<rcov>, [">= 0"])
|
|
114
113
|
else
|
|
115
114
|
s.add_dependency(%q<rails>, [">= 0"])
|
|
116
115
|
s.add_dependency(%q<rake>, [">= 0"])
|
|
@@ -120,7 +119,6 @@ Gem::Specification.new do |s|
|
|
|
120
119
|
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
|
121
120
|
s.add_dependency(%q<rdoc>, [">= 0"])
|
|
122
121
|
s.add_dependency(%q<rspec>, [">= 0"])
|
|
123
|
-
s.add_dependency(%q<rcov>, [">= 0"])
|
|
124
122
|
end
|
|
125
123
|
else
|
|
126
124
|
s.add_dependency(%q<rails>, [">= 0"])
|
|
@@ -131,7 +129,6 @@ Gem::Specification.new do |s|
|
|
|
131
129
|
s.add_dependency(%q<jeweler>, ["~> 1.8.3"])
|
|
132
130
|
s.add_dependency(%q<rdoc>, [">= 0"])
|
|
133
131
|
s.add_dependency(%q<rspec>, [">= 0"])
|
|
134
|
-
s.add_dependency(%q<rcov>, [">= 0"])
|
|
135
132
|
end
|
|
136
133
|
end
|
|
137
134
|
|
|
@@ -66,7 +66,7 @@ module ActiveRecord
|
|
|
66
66
|
destroy_keys(attribute, *keys).save
|
|
67
67
|
end
|
|
68
68
|
|
|
69
|
-
if Rails.version < '3.1.0'
|
|
69
|
+
if defined?(Rails) && Rails.version < '3.1.0'
|
|
70
70
|
# This method is replaced for Rails 3 compatibility.
|
|
71
71
|
# All I do is add the condition when the field is a hash that converts the value
|
|
72
72
|
# to hstore format.
|
|
@@ -117,6 +117,22 @@ module ActiveRecord
|
|
|
117
117
|
|
|
118
118
|
end
|
|
119
119
|
|
|
120
|
+
class Table
|
|
121
|
+
|
|
122
|
+
# Adds hstore type for migrations. So you can add columns to a table like:
|
|
123
|
+
# change_table :people do |t|
|
|
124
|
+
# ...
|
|
125
|
+
# t.hstore :info
|
|
126
|
+
# ...
|
|
127
|
+
# end
|
|
128
|
+
def hstore(*args)
|
|
129
|
+
options = args.extract_options!
|
|
130
|
+
column_names = args
|
|
131
|
+
column_names.each { |name| column(name, 'hstore', options) }
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
end
|
|
135
|
+
|
|
120
136
|
class PostgreSQLColumn < Column
|
|
121
137
|
# Does the type casting from hstore columns using String#from_hstore or Hash#from_hstore.
|
|
122
138
|
def type_cast_code_with_hstore(var_name)
|
|
@@ -127,7 +143,7 @@ module ActiveRecord
|
|
|
127
143
|
def simplified_type_with_hstore(field_type)
|
|
128
144
|
field_type == 'hstore' ? :hstore : simplified_type_without_hstore(field_type)
|
|
129
145
|
end
|
|
130
|
-
|
|
146
|
+
|
|
131
147
|
alias_method_chain :type_cast_code, :hstore
|
|
132
148
|
alias_method_chain :simplified_type, :hstore
|
|
133
149
|
end
|
|
@@ -140,14 +156,14 @@ module ActiveRecord
|
|
|
140
156
|
# Quotes correctly a hstore column value.
|
|
141
157
|
def quote_with_hstore(value, column = nil)
|
|
142
158
|
if value && column && column.sql_type == 'hstore'
|
|
143
|
-
raise HstoreTypeMismatch, "#{column.name} must have a Hash or a valid hstore value (#{value})" unless value.kind_of?(Hash) || value.valid_hstore?
|
|
159
|
+
raise HstoreTypeMismatch, "#{column.name} must have a Hash or a valid hstore value (#{value})" unless value.kind_of?(Hash) || value.valid_hstore?
|
|
144
160
|
return quote_without_hstore(value.to_hstore, column)
|
|
145
161
|
end
|
|
146
162
|
quote_without_hstore(value,column)
|
|
147
163
|
end
|
|
148
|
-
|
|
164
|
+
|
|
149
165
|
alias_method_chain :quote, :hstore
|
|
150
|
-
alias_method_chain :native_database_types, :hstore
|
|
166
|
+
alias_method_chain :native_database_types, :hstore
|
|
151
167
|
end
|
|
152
168
|
end
|
|
153
169
|
end
|
|
@@ -1,24 +1,34 @@
|
|
|
1
1
|
class Hash
|
|
2
|
+
HSTORE_ESCAPED = /[,\s=>\\]/
|
|
3
|
+
|
|
4
|
+
# Escapes values such that they will work in an hstore string
|
|
5
|
+
def hstore_escape(str)
|
|
6
|
+
if str.nil?
|
|
7
|
+
return 'NULL'
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
str = str.to_s.dup
|
|
11
|
+
# backslash is an escape character for strings, and an escape character for gsub, so you need 6 backslashes to get 2 in the output.
|
|
12
|
+
# see http://stackoverflow.com/questions/1542214/weird-backslash-substitution-in-ruby for the gory details
|
|
13
|
+
str.gsub!(/\\/, '\\\\\\')
|
|
14
|
+
# escape backslashes before injecting more backslashes
|
|
15
|
+
str.gsub!(/"/, '\"')
|
|
16
|
+
|
|
17
|
+
if str =~ HSTORE_ESCAPED or str.empty?
|
|
18
|
+
str = '"%s"' % str
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
return str
|
|
22
|
+
end
|
|
2
23
|
|
|
3
24
|
# Generates an hstore string format. This is the format used
|
|
4
25
|
# to insert or update stuff in the database.
|
|
5
26
|
def to_hstore
|
|
6
27
|
return "" if empty?
|
|
7
28
|
|
|
8
|
-
map
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
if _.nil?
|
|
12
|
-
'NULL'
|
|
13
|
-
elsif e =~ /[,\s=>]/ || e.blank?
|
|
14
|
-
'"%s"' % e
|
|
15
|
-
else
|
|
16
|
-
e
|
|
17
|
-
end
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
"%s=>%s" % iv
|
|
21
|
-
} * ","
|
|
29
|
+
map do |idx, val|
|
|
30
|
+
"%s=>%s" % [hstore_escape(idx), hstore_escape(val)]
|
|
31
|
+
end * ","
|
|
22
32
|
end
|
|
23
33
|
|
|
24
34
|
# If the method from_hstore is called in a Hash, it just returns self.
|
|
@@ -63,13 +63,29 @@ describe "ActiverecordPostgresHstore" do
|
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
it "should quote keys and values correctly with combinations of single and double quotes" do
|
|
66
|
-
{ %q("a') => %q(b "a' b) }.to_hstore.should eq(%q(\"a'=>"b \"a' b"))
|
|
66
|
+
{ %q("a') => %q(b "a' b) }.to_hstore.should eq(%q("\"a'"=>"b \"a' b"))
|
|
67
67
|
end
|
|
68
68
|
|
|
69
69
|
it "should unquote keys and values correctly with combinations of single and double quotes" do
|
|
70
70
|
%q("\"a'"=>"b \"a' b").from_hstore.should eq({%q("a') => %q(b "a' b)})
|
|
71
71
|
end
|
|
72
72
|
|
|
73
|
+
it "should quote keys and values correctly with backslashes" do
|
|
74
|
+
{ %q(\\) => %q(\\) }.to_hstore.should eq(%q("\\\\"=>"\\\\"))
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
it "should unquote keys and values correctly with backslashes" do
|
|
78
|
+
%q("\\\\"=>"\\\\").from_hstore.should eq({ %q(\\) => %q(\\) })
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
it "should quote keys and values correctly with combinations of backslashes and quotes" do
|
|
82
|
+
{ %q(' \\ ") => %q(" \\ ') }.to_hstore.should eq(%q("' \\\\ \""=>"\" \\\\ '"))
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
it "should unquote keys and values correctly with combinations of backslashes and quotes" do
|
|
86
|
+
%q("' \\\\ \""=>"\" \\\\ '").from_hstore.should eq({ %q(' \\ ") => %q(" \\ ') })
|
|
87
|
+
end
|
|
88
|
+
|
|
73
89
|
it "should convert empty hash" do
|
|
74
90
|
{}.to_hstore.should eq("")
|
|
75
91
|
end
|
|
@@ -78,5 +94,11 @@ describe "ActiverecordPostgresHstore" do
|
|
|
78
94
|
''.from_hstore.should eq({})
|
|
79
95
|
' '.from_hstore.should eq({})
|
|
80
96
|
end
|
|
97
|
+
|
|
98
|
+
it "should not change values with line breaks" do
|
|
99
|
+
input = { "a" => "foo\n\nbar" }
|
|
100
|
+
output = input.to_hstore
|
|
101
|
+
output.from_hstore.should eq(input)
|
|
102
|
+
end
|
|
81
103
|
|
|
82
104
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: activerecord-postgres-hstore
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.4.
|
|
4
|
+
version: 0.4.1
|
|
5
5
|
prerelease:
|
|
6
6
|
platform: ruby
|
|
7
7
|
authors:
|
|
@@ -10,11 +10,11 @@ authors:
|
|
|
10
10
|
autorequire:
|
|
11
11
|
bindir: bin
|
|
12
12
|
cert_chain: []
|
|
13
|
-
date: 2012-
|
|
13
|
+
date: 2012-09-14 00:00:00.000000000Z
|
|
14
14
|
dependencies:
|
|
15
15
|
- !ruby/object:Gem::Dependency
|
|
16
16
|
name: rails
|
|
17
|
-
requirement: &
|
|
17
|
+
requirement: &2157171100 !ruby/object:Gem::Requirement
|
|
18
18
|
none: false
|
|
19
19
|
requirements:
|
|
20
20
|
- - ! '>='
|
|
@@ -22,10 +22,10 @@ dependencies:
|
|
|
22
22
|
version: '0'
|
|
23
23
|
type: :runtime
|
|
24
24
|
prerelease: false
|
|
25
|
-
version_requirements: *
|
|
25
|
+
version_requirements: *2157171100
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
27
|
name: rake
|
|
28
|
-
requirement: &
|
|
28
|
+
requirement: &2157170000 !ruby/object:Gem::Requirement
|
|
29
29
|
none: false
|
|
30
30
|
requirements:
|
|
31
31
|
- - ! '>='
|
|
@@ -33,10 +33,10 @@ dependencies:
|
|
|
33
33
|
version: '0'
|
|
34
34
|
type: :runtime
|
|
35
35
|
prerelease: false
|
|
36
|
-
version_requirements: *
|
|
36
|
+
version_requirements: *2157170000
|
|
37
37
|
- !ruby/object:Gem::Dependency
|
|
38
38
|
name: pg
|
|
39
|
-
requirement: &
|
|
39
|
+
requirement: &2157169120 !ruby/object:Gem::Requirement
|
|
40
40
|
none: false
|
|
41
41
|
requirements:
|
|
42
42
|
- - ! '>='
|
|
@@ -44,10 +44,10 @@ dependencies:
|
|
|
44
44
|
version: '0'
|
|
45
45
|
type: :runtime
|
|
46
46
|
prerelease: false
|
|
47
|
-
version_requirements: *
|
|
47
|
+
version_requirements: *2157169120
|
|
48
48
|
- !ruby/object:Gem::Dependency
|
|
49
49
|
name: shoulda
|
|
50
|
-
requirement: &
|
|
50
|
+
requirement: &2157168140 !ruby/object:Gem::Requirement
|
|
51
51
|
none: false
|
|
52
52
|
requirements:
|
|
53
53
|
- - ! '>='
|
|
@@ -55,10 +55,10 @@ dependencies:
|
|
|
55
55
|
version: '0'
|
|
56
56
|
type: :development
|
|
57
57
|
prerelease: false
|
|
58
|
-
version_requirements: *
|
|
58
|
+
version_requirements: *2157168140
|
|
59
59
|
- !ruby/object:Gem::Dependency
|
|
60
60
|
name: bundler
|
|
61
|
-
requirement: &
|
|
61
|
+
requirement: &2157166860 !ruby/object:Gem::Requirement
|
|
62
62
|
none: false
|
|
63
63
|
requirements:
|
|
64
64
|
- - ~>
|
|
@@ -66,10 +66,10 @@ dependencies:
|
|
|
66
66
|
version: 1.1.3
|
|
67
67
|
type: :development
|
|
68
68
|
prerelease: false
|
|
69
|
-
version_requirements: *
|
|
69
|
+
version_requirements: *2157166860
|
|
70
70
|
- !ruby/object:Gem::Dependency
|
|
71
71
|
name: jeweler
|
|
72
|
-
requirement: &
|
|
72
|
+
requirement: &2157165660 !ruby/object:Gem::Requirement
|
|
73
73
|
none: false
|
|
74
74
|
requirements:
|
|
75
75
|
- - ~>
|
|
@@ -77,10 +77,10 @@ dependencies:
|
|
|
77
77
|
version: 1.8.3
|
|
78
78
|
type: :development
|
|
79
79
|
prerelease: false
|
|
80
|
-
version_requirements: *
|
|
80
|
+
version_requirements: *2157165660
|
|
81
81
|
- !ruby/object:Gem::Dependency
|
|
82
82
|
name: rdoc
|
|
83
|
-
requirement: &
|
|
83
|
+
requirement: &2157164420 !ruby/object:Gem::Requirement
|
|
84
84
|
none: false
|
|
85
85
|
requirements:
|
|
86
86
|
- - ! '>='
|
|
@@ -88,10 +88,10 @@ dependencies:
|
|
|
88
88
|
version: '0'
|
|
89
89
|
type: :development
|
|
90
90
|
prerelease: false
|
|
91
|
-
version_requirements: *
|
|
91
|
+
version_requirements: *2157164420
|
|
92
92
|
- !ruby/object:Gem::Dependency
|
|
93
93
|
name: rspec
|
|
94
|
-
requirement: &
|
|
94
|
+
requirement: &2157163540 !ruby/object:Gem::Requirement
|
|
95
95
|
none: false
|
|
96
96
|
requirements:
|
|
97
97
|
- - ! '>='
|
|
@@ -99,18 +99,7 @@ dependencies:
|
|
|
99
99
|
version: '0'
|
|
100
100
|
type: :development
|
|
101
101
|
prerelease: false
|
|
102
|
-
version_requirements: *
|
|
103
|
-
- !ruby/object:Gem::Dependency
|
|
104
|
-
name: rcov
|
|
105
|
-
requirement: &2159223260 !ruby/object:Gem::Requirement
|
|
106
|
-
none: false
|
|
107
|
-
requirements:
|
|
108
|
-
- - ! '>='
|
|
109
|
-
- !ruby/object:Gem::Version
|
|
110
|
-
version: '0'
|
|
111
|
-
type: :development
|
|
112
|
-
prerelease: false
|
|
113
|
-
version_requirements: *2159223260
|
|
102
|
+
version_requirements: *2157163540
|
|
114
103
|
description: This gem adds support for the postgres hstore type. It is the _just right_
|
|
115
104
|
alternative for storing hashes instead of using seralization or dynamic tables.
|
|
116
105
|
email: juanmaiz@gmail.com
|
|
@@ -209,7 +198,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
209
198
|
version: '0'
|
|
210
199
|
segments:
|
|
211
200
|
- 0
|
|
212
|
-
hash:
|
|
201
|
+
hash: 3203326444745733758
|
|
213
202
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
214
203
|
none: false
|
|
215
204
|
requirements:
|