nested-hstore 0.0.5 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +19 -12
- data/lib/active_record/coders/nested_hstore.rb +35 -13
- data/lib/nested-hstore.rb +1 -1
- data/lib/nested_hstore/version.rb +1 -1
- metadata +35 -32
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: eda2a7d25d1dd73e0a08a5c24c8114d83875aab5
|
4
|
+
data.tar.gz: 9d94ea5139bb1dbced1e4f24587bfaa30f9c6c2e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7145d03f36c19e1ba99a30c5b7b54e2697e0dca24974ab66af5c29db63cbf1c749f294589443b0eec211d9ae4714abadcce1831c0d45fd183ba91a61b35ae05f
|
7
|
+
data.tar.gz: 9952d1be97003b74974995ccbdef9a981d102dd98188336d8e830cacafa72ec23a1054e9fd845b59b4d463c268fe2451818c0e203046df47b3eb64900787ccba
|
data/README.md
CHANGED
@@ -12,21 +12,26 @@ Postgres hstores offer a number of benefits, but they don't natively support mul
|
|
12
12
|
It also lets you store data types other than hashes in an hstore. All of the following values will be returned verbatim:
|
13
13
|
|
14
14
|
```ruby
|
15
|
+
class User < ActiveRecord::Base
|
16
|
+
serialize :my_property, ActiveRecord::Coders::NestedHstore
|
17
|
+
end
|
18
|
+
|
15
19
|
# Nested hash
|
16
|
-
|
17
|
-
'
|
20
|
+
user.my_property = {
|
21
|
+
'name' => 'Jane Doe',
|
18
22
|
'comment_ids' => [34, 67, 82],
|
19
|
-
'
|
23
|
+
'location' => {
|
20
24
|
'id' => 15,
|
21
|
-
'
|
25
|
+
'city' => 'San Francisco',
|
26
|
+
'state' => 'CA'
|
22
27
|
}
|
23
28
|
}
|
24
29
|
|
25
30
|
# Array
|
26
|
-
|
31
|
+
user.my_property = [34, 67, 82]
|
27
32
|
|
28
33
|
# Array of nested hashes
|
29
|
-
|
34
|
+
user.my_property = [
|
30
35
|
{
|
31
36
|
'id' => 15,
|
32
37
|
'username' => 'janedoe'
|
@@ -38,27 +43,29 @@ post.my_hstore = [
|
|
38
43
|
]
|
39
44
|
|
40
45
|
# Integer
|
41
|
-
|
46
|
+
user.my_property = 43
|
42
47
|
|
43
48
|
# Float
|
44
|
-
|
49
|
+
user.my_property = 43.1
|
45
50
|
|
46
51
|
# String
|
47
|
-
|
52
|
+
user.my_property = 'janedoe'
|
48
53
|
```
|
49
54
|
|
50
55
|
Installation
|
51
56
|
------------
|
52
57
|
|
58
|
+
*If you're using ActiveRecord 2.x or 3.x, set up [activerecord-postgres-hstore](https://github.com/diogob/activerecord-postgres-hstore) if you haven't already. This isn't necessary for ActiveRecord 4.x.*
|
59
|
+
|
53
60
|
Include it in your Gemfile:
|
54
61
|
|
55
62
|
gem 'nested-hstore'
|
56
63
|
|
57
|
-
|
64
|
+
Serialize each property using `ActiveRecord::Coders::NestedHstore`:
|
58
65
|
|
59
66
|
```ruby
|
60
|
-
class
|
61
|
-
serialize :
|
67
|
+
class User < ActiveRecord::Base
|
68
|
+
serialize :my_property, ActiveRecord::Coders::NestedHstore
|
62
69
|
end
|
63
70
|
```
|
64
71
|
|
@@ -1,24 +1,46 @@
|
|
1
1
|
module ActiveRecord
|
2
2
|
module Coders
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
if ActiveRecord::VERSION::MAJOR < 4
|
4
|
+
require 'activerecord-postgres-hstore'
|
5
|
+
|
6
|
+
class NestedHstore < Hstore
|
7
|
+
def initialize(default=nil)
|
8
|
+
super(default)
|
9
|
+
@nested_serializer = ::NestedHstore::Serializer.new
|
10
|
+
end
|
8
11
|
|
9
|
-
|
12
|
+
private
|
10
13
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
+
def to_hstore obj
|
15
|
+
super(@nested_serializer.serialize(obj))
|
16
|
+
end
|
14
17
|
|
15
|
-
|
16
|
-
if ActiveRecord::VERSION::MAJOR >= 4 && hstore.is_a?(Hash)
|
17
|
-
@nested_serializer.deserialize(hstore)
|
18
|
-
else
|
18
|
+
def from_hstore hstore
|
19
19
|
@nested_serializer.deserialize(super)
|
20
20
|
end
|
21
21
|
end
|
22
|
+
else
|
23
|
+
class NestedHstore
|
24
|
+
def self.load(hstore)
|
25
|
+
new.load(hstore)
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.dump(hstore)
|
29
|
+
new.dump(hstore)
|
30
|
+
end
|
31
|
+
|
32
|
+
def initialize
|
33
|
+
@nested_serializer = ::NestedHstore::Serializer.new
|
34
|
+
end
|
35
|
+
|
36
|
+
def load(hash)
|
37
|
+
@nested_serializer.deserialize(hash)
|
38
|
+
end
|
39
|
+
|
40
|
+
def dump(value)
|
41
|
+
@nested_serializer.serialize(value)
|
42
|
+
end
|
43
|
+
end
|
22
44
|
end
|
23
45
|
end
|
24
46
|
end
|
data/lib/nested-hstore.rb
CHANGED
metadata
CHANGED
@@ -1,94 +1,97 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nested-hstore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
5
|
-
prerelease:
|
4
|
+
version: 0.1.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Tom Benner
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2014-
|
11
|
+
date: 2014-12-27 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: activerecord
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: '0'
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: '0'
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: activerecord-postgres-hstore
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: '0'
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: '0'
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: activesupport
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - ">="
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :runtime
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - ">="
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: appraisal
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - ">="
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '0'
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - ">="
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: rspec
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
|
-
- -
|
73
|
+
- - ">="
|
84
74
|
- !ruby/object:Gem::Version
|
85
75
|
version: '0'
|
86
76
|
type: :development
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
|
-
- -
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pg
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
92
95
|
- !ruby/object:Gem::Version
|
93
96
|
version: '0'
|
94
97
|
description: Store nested hashes and other types in ActiveRecord hstores
|
@@ -98,36 +101,36 @@ executables: []
|
|
98
101
|
extensions: []
|
99
102
|
extra_rdoc_files: []
|
100
103
|
files:
|
104
|
+
- MIT-LICENSE
|
105
|
+
- README.md
|
106
|
+
- Rakefile
|
101
107
|
- lib/active_record/coders/nested_hstore.rb
|
102
108
|
- lib/nested-hstore.rb
|
103
109
|
- lib/nested_hstore/serializer.rb
|
104
110
|
- lib/nested_hstore/version.rb
|
105
|
-
- MIT-LICENSE
|
106
|
-
- Rakefile
|
107
|
-
- README.md
|
108
111
|
homepage: https://github.com/tombenner/nested-hstore
|
109
112
|
licenses:
|
110
113
|
- MIT
|
114
|
+
metadata: {}
|
111
115
|
post_install_message:
|
112
116
|
rdoc_options: []
|
113
117
|
require_paths:
|
114
118
|
- lib
|
115
119
|
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
-
none: false
|
117
120
|
requirements:
|
118
|
-
- -
|
121
|
+
- - ">="
|
119
122
|
- !ruby/object:Gem::Version
|
120
123
|
version: '0'
|
121
124
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
|
-
none: false
|
123
125
|
requirements:
|
124
|
-
- -
|
126
|
+
- - ">="
|
125
127
|
- !ruby/object:Gem::Version
|
126
128
|
version: '0'
|
127
129
|
requirements: []
|
128
130
|
rubyforge_project:
|
129
|
-
rubygems_version:
|
131
|
+
rubygems_version: 2.4.5
|
130
132
|
signing_key:
|
131
|
-
specification_version:
|
133
|
+
specification_version: 4
|
132
134
|
summary: Store nested hashes and other types in ActiveRecord hstores
|
133
135
|
test_files: []
|
136
|
+
has_rdoc:
|