activerecord-typedstore 0.4.2 → 0.4.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/README.md +51 -0
- data/lib/active_record/typed_store/coder.rb +4 -0
- data/lib/active_record/typed_store/extension.rb +0 -4
- data/lib/active_record/typed_store/version.rb +1 -1
- data/spec/active_record/typed_store_spec.rb +18 -1
- data/spec/support/models.rb +3 -2
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: feff41b09759e6bba17c41f3b4ab635286d7852f
|
4
|
+
data.tar.gz: 8ea136dccb104e0a43ad7267d425bdc2016cf5d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 64a75b48fe0f9bd9e768b1fe5947f43ffee8eeef182057493e31958ede64d4f2f8c78292343c3cb8e74d48b605070cd953cbe0b3a96bcdd1b0d733a8294b0ae2
|
7
|
+
data.tar.gz: 4e983b5546295199cc3cbc7dcf5ce5109693bd272b7185b9d4d1af05db5538ac5443f5b05834fe911f799ed9602e2c241bc39524bbc9e0d229cd808c458f0b35
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -99,6 +99,57 @@ Actually the only difference is that you wont be able to query on these attribut
|
|
99
99
|
|
100
100
|
If not, please fill an issue.
|
101
101
|
|
102
|
+
## Serialization methods
|
103
|
+
|
104
|
+
Just like for store, you can use any custom coder:
|
105
|
+
|
106
|
+
```ruby
|
107
|
+
module Base64MarshalCoder
|
108
|
+
extend self
|
109
|
+
|
110
|
+
def load(data)
|
111
|
+
return {} unless data
|
112
|
+
Marshal.load(Base64.decode64(data))
|
113
|
+
end
|
114
|
+
|
115
|
+
def dump(data)
|
116
|
+
Base64.encode64(Marshal.dump(data || {}))
|
117
|
+
end
|
118
|
+
|
119
|
+
end
|
120
|
+
|
121
|
+
typed_store :settings, coder: Base64MarshalCoder do |s|
|
122
|
+
# ...
|
123
|
+
end
|
124
|
+
```
|
125
|
+
|
126
|
+
If you want to use Postgres HStore or JSON column types, then you need a very simple coder:
|
127
|
+
```ruby
|
128
|
+
module DumbCoder
|
129
|
+
extend self
|
130
|
+
|
131
|
+
def load(data)
|
132
|
+
data || {}
|
133
|
+
end
|
134
|
+
|
135
|
+
def dump(data)
|
136
|
+
data || {}
|
137
|
+
end
|
138
|
+
|
139
|
+
end
|
140
|
+
```
|
141
|
+
|
142
|
+
## HStore limitations
|
143
|
+
|
144
|
+
If you want to persist your store in a Postgres HStore, then there is some limitations imposed by the current HStore implementation in Postgres.
|
145
|
+
Since HStore can only store strings:
|
146
|
+
|
147
|
+
- `array` attributes won't work
|
148
|
+
- `any` attributes will be converted to string
|
149
|
+
|
150
|
+
If you use HStore because you need to be able to query the store from SQL, and any of these limitations are an issue for you,
|
151
|
+
than you could probably use the JSON column type, which do not suffer from these limitations and is also queriable.
|
152
|
+
|
102
153
|
## Contributing
|
103
154
|
|
104
155
|
1. Fork it
|
@@ -70,10 +70,6 @@ module ActiveRecord::TypedStore
|
|
70
70
|
typed_store_attributes.values.select(&:accessor?).map(&:name).map(&:to_s)
|
71
71
|
end
|
72
72
|
|
73
|
-
def hstore?(store_attribute)
|
74
|
-
columns_hash[store_attribute.to_s].try(:type) == :hstore
|
75
|
-
end
|
76
|
-
|
77
73
|
def create_time_zone_conversion_attribute?(name, column)
|
78
74
|
column ||= typed_store_attributes[name]
|
79
75
|
super(name, column)
|
@@ -529,6 +529,23 @@ shared_examples 'a store' do |retain_type=true|
|
|
529
529
|
|
530
530
|
end
|
531
531
|
|
532
|
+
describe 'updated defaults' do
|
533
|
+
|
534
|
+
it 'update defaults for outdated serials' do
|
535
|
+
model.save!
|
536
|
+
expect(model.settings[:brand_new]).to be_nil
|
537
|
+
new_column = ActiveRecord::TypedStore::Column.new(:brand_new, :boolean, null: false, default: true)
|
538
|
+
begin
|
539
|
+
model.class::SettingsHash.columns['brand_new'] = new_column
|
540
|
+
model.reload
|
541
|
+
expect(model.settings[:brand_new]).to be_true
|
542
|
+
ensure
|
543
|
+
model.class::SettingsHash.columns.delete('brand_new')
|
544
|
+
end
|
545
|
+
end
|
546
|
+
|
547
|
+
end
|
548
|
+
|
532
549
|
end
|
533
550
|
|
534
551
|
shared_examples 'a db backed model' do
|
@@ -628,7 +645,7 @@ describe PostgresqlRegularARModel do
|
|
628
645
|
end if defined?(PostgresqlRegularARModel)
|
629
646
|
|
630
647
|
describe PostgresHstoreTypedStoreModel do
|
631
|
-
if AR_VERSION >=
|
648
|
+
if AR_VERSION >= AR_4_1
|
632
649
|
pending('TODO: Rails edge HStore compatibiliy')
|
633
650
|
else
|
634
651
|
it_should_behave_like 'any model'
|
data/spec/support/models.rb
CHANGED
@@ -94,7 +94,7 @@ class ColumnCoder
|
|
94
94
|
end
|
95
95
|
|
96
96
|
def load(data)
|
97
|
-
return {}
|
97
|
+
return {} if data.blank?
|
98
98
|
@coder.load(data)
|
99
99
|
end
|
100
100
|
|
@@ -135,7 +135,7 @@ if ENV['POSTGRES']
|
|
135
135
|
class PostgresHstoreTypedStoreModel < ActiveRecord::Base
|
136
136
|
establish_connection ENV['POSTGRES_URL'] || 'test_postgresql'
|
137
137
|
store :untyped_settings, accessors: [:title]
|
138
|
-
typed_store :settings do |s|
|
138
|
+
typed_store :settings, coder: ColumnCoder.new(AsJson) do |s|
|
139
139
|
define_store_columns(s)
|
140
140
|
end
|
141
141
|
end
|
@@ -176,6 +176,7 @@ module MarshalCoder
|
|
176
176
|
extend self
|
177
177
|
|
178
178
|
def load(serial)
|
179
|
+
return unless serial.present?
|
179
180
|
Marshal.load(Base64.decode64(serial))
|
180
181
|
end
|
181
182
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-typedstore
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jean Boussier
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-03-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|