active_record_hstore_serializer 0.0.2 → 0.0.3
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/README.md +24 -0
- data/active_record_hstore_serializer.gemspec +2 -2
- data/lib/active_record_hstore_serializer/hash.rb +15 -1
- metadata +39 -22
- data/README +0 -1
data/README.md
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
Enable Postgres HStore column serialization for your ActiveRecord / Rails 3.1+ project.
|
2
|
+
|
3
|
+
Huge thanks and credit to https://github.com/softa/activerecord-postgres-hstore for code and inspiration.
|
4
|
+
|
5
|
+
|
6
|
+
Example
|
7
|
+
-------
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
|
11
|
+
class Car < ActiveRecord::Base
|
12
|
+
serialize :data, HstoreSerializer
|
13
|
+
end
|
14
|
+
|
15
|
+
toyota = Car.create(:data => {:doors => 2, :color => "grey"})
|
16
|
+
|
17
|
+
# Finding. Notice that all values get stored as strings, hence the typecasting
|
18
|
+
Car.where(["data -> 'doors' = ?", "2"])
|
19
|
+
|
20
|
+
# Updating / Inserting
|
21
|
+
car.data['make'] = "Toyota"
|
22
|
+
car.save
|
23
|
+
```
|
24
|
+
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'active_record_hstore_serializer'
|
3
|
-
s.version = '0.0.
|
3
|
+
s.version = '0.0.3'
|
4
4
|
s.date = '2011-11-19'
|
5
5
|
s.summary = "Serialize attributes using HStore in ActiveRecord / Rails 3.1+"
|
6
6
|
s.description = "Leverage Postgres HStore for awesome attribute serialization."
|
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
|
|
11
11
|
s.files = [
|
12
12
|
".gitignore",
|
13
13
|
"LICENSE",
|
14
|
-
"README",
|
14
|
+
"README.md",
|
15
15
|
"lib/active_record_hstore_serializer.rb",
|
16
16
|
"lib/active_record_hstore_serializer/hash.rb",
|
17
17
|
"lib/active_record_hstore_serializer/string.rb",
|
@@ -2,7 +2,21 @@ class Hash
|
|
2
2
|
|
3
3
|
def to_hstore
|
4
4
|
return "" if empty?
|
5
|
-
|
5
|
+
|
6
|
+
map { |idx, val|
|
7
|
+
iv = [idx,val].map { |_|
|
8
|
+
e = _.to_s.gsub(/"/, '\"')
|
9
|
+
if _.nil?
|
10
|
+
'NULL'
|
11
|
+
elsif e =~ /[,\s=>]/ || e.blank?
|
12
|
+
'"%s"' % e
|
13
|
+
else
|
14
|
+
e
|
15
|
+
end
|
16
|
+
}
|
17
|
+
|
18
|
+
"%s=>%s" % iv
|
19
|
+
} * ","
|
6
20
|
end
|
7
21
|
|
8
22
|
# If the method from_hstore is called in a Hash, it just returns self.
|
metadata
CHANGED
@@ -1,52 +1,69 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_record_hstore_serializer
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 3
|
9
|
+
version: 0.0.3
|
6
10
|
platform: ruby
|
7
|
-
authors:
|
11
|
+
authors:
|
8
12
|
- Cody Caughlan
|
9
13
|
autorequire:
|
10
14
|
bindir: bin
|
11
15
|
cert_chain: []
|
12
|
-
|
16
|
+
|
17
|
+
date: 2011-11-19 00:00:00 -08:00
|
18
|
+
default_executable:
|
13
19
|
dependencies: []
|
20
|
+
|
14
21
|
description: Leverage Postgres HStore for awesome attribute serialization.
|
15
22
|
email: toolbag@gmail.com
|
16
23
|
executables: []
|
24
|
+
|
17
25
|
extensions: []
|
26
|
+
|
18
27
|
extra_rdoc_files: []
|
19
|
-
|
28
|
+
|
29
|
+
files:
|
20
30
|
- .gitignore
|
21
31
|
- LICENSE
|
22
|
-
- README
|
32
|
+
- README.md
|
23
33
|
- lib/active_record_hstore_serializer.rb
|
24
34
|
- lib/active_record_hstore_serializer/hash.rb
|
25
35
|
- lib/active_record_hstore_serializer/string.rb
|
26
36
|
- lib/active_record_hstore_serializer/hstore_serializer.rb
|
27
37
|
- active_record_hstore_serializer.gemspec
|
38
|
+
has_rdoc: true
|
28
39
|
homepage: https://github.com/ruckus/active_record_hstore_serializer
|
29
40
|
licenses: []
|
41
|
+
|
30
42
|
post_install_message:
|
31
43
|
rdoc_options: []
|
32
|
-
|
44
|
+
|
45
|
+
require_paths:
|
33
46
|
- lib
|
34
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
requirements:
|
43
|
-
- -
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
requirements:
|
49
|
+
- - ">="
|
50
|
+
- !ruby/object:Gem::Version
|
51
|
+
segments:
|
52
|
+
- 0
|
53
|
+
version: "0"
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
segments:
|
59
|
+
- 0
|
60
|
+
version: "0"
|
46
61
|
requirements: []
|
62
|
+
|
47
63
|
rubyforge_project:
|
48
|
-
rubygems_version: 1.
|
64
|
+
rubygems_version: 1.3.6
|
49
65
|
signing_key:
|
50
66
|
specification_version: 3
|
51
67
|
summary: Serialize attributes using HStore in ActiveRecord / Rails 3.1+
|
52
68
|
test_files: []
|
69
|
+
|
data/README
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
Enable Postgres HStore column serialization for your ActiveRecord / Rails 3.1+ project
|