store_schema 0.0.1 → 0.1.0
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.
- checksums.yaml +4 -4
- data/.travis.yml +1 -0
- data/LICENSE +1 -1
- data/README.md +21 -7
- data/lib/store_schema/accessor_definer.rb +5 -16
- data/lib/store_schema/converter/base.rb +1 -1
- data/lib/store_schema/converter/boolean.rb +1 -2
- data/lib/store_schema/converter/date_time.rb +1 -2
- data/lib/store_schema/converter/float.rb +1 -2
- data/lib/store_schema/converter/integer.rb +1 -2
- data/lib/store_schema/converter/string.rb +1 -2
- data/lib/store_schema/version.rb +1 -1
- data/spec/lib/{casted_store_accessor_spec.rb → store_schema_spec.rb} +24 -48
- data/spec/spec_helper.rb +2 -9
- data/spec/support/db.rb +0 -1
- data/spec/support/env.rb +0 -6
- data/spec/support/models.rb +1 -1
- data/store_schema.gemspec +0 -1
- metadata +5 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a05dab9a51e83ac7afde53a40dc65dddd2d388d
|
4
|
+
data.tar.gz: 9036c033e270aebcd9f08fd56da0b7553db09b67
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c0a5cf4d0bf2a57a75c788aa619317fed9a7d5accedd181d027f6b9011b726d38a8c49389ab1e1a252668defa1c8f08b8a34ee281f21ce92962c5ba3610520c
|
7
|
+
data.tar.gz: c764b979e4d63d8ce23898e309200a0671102eba64a8a56255c8e434c6866a87f7dd11ed2d635bef9ae94eb806b323d85898680eed88fc79563292f094122e54
|
data/.travis.yml
CHANGED
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
|
-
#
|
1
|
+
# Store Schema
|
2
2
|
|
3
|
+
[](http://badge.fury.io/rb/store_schema)
|
3
4
|
[](https://codeclimate.com/github/meskyanichi/store_schema)
|
4
5
|
[](https://travis-ci.org/meskyanichi/store_schema)
|
5
6
|
|
@@ -7,6 +8,8 @@ StoreSchema, for Rails/ActiveRecord 4.0.0+, enhances `ActiveRecord::Base.store_a
|
|
7
8
|
|
8
9
|
This library was developed for- and extracted from [HireFire].
|
9
10
|
|
11
|
+
The documentation can be found on [RubyDoc].
|
12
|
+
|
10
13
|
|
11
14
|
### Compatibility
|
12
15
|
|
@@ -17,7 +20,7 @@ This library was developed for- and extracted from [HireFire].
|
|
17
20
|
|
18
21
|
### Installation
|
19
22
|
|
20
|
-
|
23
|
+
Add the gem to your Gemfile and run `bundle`.
|
21
24
|
|
22
25
|
```rb
|
23
26
|
gem "store_schema"
|
@@ -37,10 +40,13 @@ class Website < ActiveRecord::Base
|
|
37
40
|
# Tell ActiveRecord that we want to serialize the :config attribute
|
38
41
|
# and store the serialized data as text in the config column.
|
39
42
|
#
|
40
|
-
#
|
41
|
-
#
|
43
|
+
# By default, `store` serializes your data as YAML. You can swap this out for
|
44
|
+
# any other coder you want. For example JSON or Oj (high performance JSON).
|
45
|
+
#
|
46
|
+
# If you're using PostgreSQL's hstore or json column-type instead of the
|
47
|
+
# text column-type, you should'nt define `store :config`.
|
42
48
|
#
|
43
|
-
|
49
|
+
store :config, coder: JSON
|
44
50
|
|
45
51
|
# Define a schema for the store. This syntax is similar to
|
46
52
|
# ActiveRecord::Migration.
|
@@ -100,7 +106,8 @@ See above example.
|
|
100
106
|
If you need to be able to query these serialized attributes,
|
101
107
|
consider using [PostgreSQL's HStore Extension]. If you do not need to
|
102
108
|
be able to query the serialized data, you can simply use a text-type column
|
103
|
-
and use the `
|
109
|
+
and use the `store <column>[, coder: JSON]` method in your model which works
|
110
|
+
with any SQL database.
|
104
111
|
|
105
112
|
|
106
113
|
### Contributing
|
@@ -134,6 +141,12 @@ rspec spec
|
|
134
141
|
rubycritic lib
|
135
142
|
```
|
136
143
|
|
144
|
+
To run the local documentation server:
|
145
|
+
|
146
|
+
```
|
147
|
+
yard server --reload
|
148
|
+
```
|
149
|
+
|
137
150
|
Create a new branch and start hacking:
|
138
151
|
|
139
152
|
```
|
@@ -145,13 +158,14 @@ Submit a pull request.
|
|
145
158
|
|
146
159
|
### Author / License
|
147
160
|
|
148
|
-
Copyright (c)
|
161
|
+
Copyright (c) 2015 Michael van Rooijen ( [@meskyanichi] )<br />
|
149
162
|
Released under the MIT [License].
|
150
163
|
|
151
164
|
[@meskyanichi]: https://twitter.com/meskyanichi
|
152
165
|
[HireFire]: http://hirefire.io
|
153
166
|
[Passing Specs]: https://travis-ci.org/meskyanichi/store_schema
|
154
167
|
[Code Climate Score]: https://codeclimate.com/github/meskyanichi/store_schema
|
168
|
+
[RubyDoc]: http://rubydoc.info/github/meskyanichi/store_schema/master/frames
|
155
169
|
[License]: https://github.com/meskyanichi/store_schema/blob/master/LICENSE
|
156
170
|
[RubyGems.org]: https://rubygems.org/gems/store_schema
|
157
171
|
[PostgreSQL's HStore Extension]: http://www.postgresql.org/docs/9.3/static/hstore.html
|
@@ -1,5 +1,4 @@
|
|
1
1
|
class StoreSchema::AccessorDefiner
|
2
|
-
class InvalidValueType < StandardError; end
|
3
2
|
|
4
3
|
# @return [Class]
|
5
4
|
#
|
@@ -64,25 +63,15 @@ class StoreSchema::AccessorDefiner
|
|
64
63
|
# Enhances the store setter by adding data conversion capabilities.
|
65
64
|
#
|
66
65
|
def define_setter
|
67
|
-
_klass = klass
|
68
|
-
_column = column
|
69
66
|
_type = type
|
70
|
-
_attribute = attribute
|
71
67
|
|
72
68
|
klass.send(:define_method, "#{attribute}=") do |value|
|
73
|
-
|
74
|
-
super(value)
|
75
|
-
else
|
76
|
-
converted_value = StoreSchema::Converter
|
77
|
-
.new(value, _type).to_db
|
69
|
+
converted_value = StoreSchema::Converter.new(value, _type).to_db
|
78
70
|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
"#{value} (#{value.class}) for " +
|
84
|
-
"#{_klass}##{_column}.#{_attribute} (#{_type})"
|
85
|
-
end
|
71
|
+
if converted_value
|
72
|
+
super(converted_value)
|
73
|
+
else
|
74
|
+
super(nil)
|
86
75
|
end
|
87
76
|
end
|
88
77
|
end
|
data/lib/store_schema/version.rb
CHANGED
@@ -19,12 +19,9 @@ RSpec.describe "StoreSchema" do
|
|
19
19
|
expect(website.reload.name).to eq("Store Schema")
|
20
20
|
end
|
21
21
|
|
22
|
-
it "
|
23
|
-
|
24
|
-
|
25
|
-
StoreSchema::AccessorDefiner::InvalidValueType,
|
26
|
-
"true (TrueClass) for Website#config.name (string)"
|
27
|
-
)
|
22
|
+
it "should convert to nil if incompatible type" do
|
23
|
+
website.update_attribute(:name, true)
|
24
|
+
expect(website.name).to eq(nil)
|
28
25
|
end
|
29
26
|
end
|
30
27
|
|
@@ -42,20 +39,14 @@ RSpec.describe "StoreSchema" do
|
|
42
39
|
expect(website.visitors).to eq(1337)
|
43
40
|
end
|
44
41
|
|
45
|
-
it "
|
46
|
-
|
47
|
-
|
48
|
-
StoreSchema::AccessorDefiner::InvalidValueType,
|
49
|
-
"abc (String) for Website#config.visitors (integer)"
|
50
|
-
)
|
42
|
+
it "should convert to nil if incompatible value" do
|
43
|
+
website.update_attribute(:visitors, "abc")
|
44
|
+
expect(website.visitors).to eq(nil)
|
51
45
|
end
|
52
46
|
|
53
|
-
it "
|
54
|
-
|
55
|
-
|
56
|
-
StoreSchema::AccessorDefiner::InvalidValueType,
|
57
|
-
"true (TrueClass) for Website#config.visitors (integer)"
|
58
|
-
)
|
47
|
+
it "should convert to nil if incompatible type" do
|
48
|
+
website.update_attribute(:visitors, true)
|
49
|
+
expect(website.visitors).to eq(nil)
|
59
50
|
end
|
60
51
|
end
|
61
52
|
|
@@ -85,20 +76,14 @@ RSpec.describe "StoreSchema" do
|
|
85
76
|
expect(website.apdex).to eq(1.0)
|
86
77
|
end
|
87
78
|
|
88
|
-
it "
|
89
|
-
|
90
|
-
|
91
|
-
StoreSchema::AccessorDefiner::InvalidValueType,
|
92
|
-
"abc (String) for Website#config.apdex (float)"
|
93
|
-
)
|
79
|
+
it "should convert to nil if incompatible value" do
|
80
|
+
website.update_attribute(:apdex, "abc")
|
81
|
+
expect(website.apdex).to eq(nil)
|
94
82
|
end
|
95
83
|
|
96
|
-
it "
|
97
|
-
|
98
|
-
|
99
|
-
StoreSchema::AccessorDefiner::InvalidValueType,
|
100
|
-
"true (TrueClass) for Website#config.apdex (float)"
|
101
|
-
)
|
84
|
+
it "should convert to nil if incompatible type" do
|
85
|
+
website.update_attribute(:apdex, true)
|
86
|
+
expect(website.apdex).to eq(nil)
|
102
87
|
end
|
103
88
|
end
|
104
89
|
|
@@ -118,12 +103,9 @@ RSpec.describe "StoreSchema" do
|
|
118
103
|
end
|
119
104
|
end
|
120
105
|
|
121
|
-
it "
|
122
|
-
|
123
|
-
|
124
|
-
StoreSchema::AccessorDefiner::InvalidValueType,
|
125
|
-
"abc (String) for Website#config.ssl (boolean)"
|
126
|
-
)
|
106
|
+
it "should convert to nil if incompatible type" do
|
107
|
+
website.update_attribute(:ssl, "abc")
|
108
|
+
expect(website.ssl).to eq(nil)
|
127
109
|
end
|
128
110
|
end
|
129
111
|
|
@@ -153,20 +135,14 @@ RSpec.describe "StoreSchema" do
|
|
153
135
|
expect(website.published_at.class).to eq(DateTime)
|
154
136
|
end
|
155
137
|
|
156
|
-
it "
|
157
|
-
|
158
|
-
|
159
|
-
StoreSchema::AccessorDefiner::InvalidValueType,
|
160
|
-
"abc (String) for Website#config.published_at (datetime)"
|
161
|
-
)
|
138
|
+
it "should convert to nil if incompatible value" do
|
139
|
+
website.update_attribute(:published_at, "abc")
|
140
|
+
expect(website.published_at).to eq(nil)
|
162
141
|
end
|
163
142
|
|
164
|
-
it "
|
165
|
-
|
166
|
-
|
167
|
-
StoreSchema::AccessorDefiner::InvalidValueType,
|
168
|
-
"true (TrueClass) for Website#config.published_at (datetime)"
|
169
|
-
)
|
143
|
+
it "should convert to nil if incompatible type" do
|
144
|
+
website.update_attribute(:published_at, true)
|
145
|
+
expect(website.published_at).to eq(nil)
|
170
146
|
end
|
171
147
|
end
|
172
148
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -9,13 +9,6 @@ require "store_schema"
|
|
9
9
|
require File.expand_path("../support/models", __FILE__)
|
10
10
|
|
11
11
|
RSpec.configure do |config|
|
12
|
-
config.
|
13
|
-
|
14
|
-
config.before do
|
15
|
-
DatabaseCleaner.start
|
16
|
-
end
|
17
|
-
|
18
|
-
config.after do
|
19
|
-
DatabaseCleaner.clean
|
20
|
-
end
|
12
|
+
config.before { DatabaseCleaner.start }
|
13
|
+
config.after { DatabaseCleaner.clean }
|
21
14
|
end
|
data/spec/support/db.rb
CHANGED
data/spec/support/env.rb
CHANGED
@@ -1,14 +1,8 @@
|
|
1
|
-
require "fileutils"
|
2
|
-
require "logger"
|
3
1
|
require "pry"
|
4
2
|
require "sqlite3"
|
5
3
|
require "active_record"
|
6
4
|
|
7
5
|
ROOT_PATH = File.expand_path("../../..", __FILE__)
|
8
6
|
SPEC_PATH = File.join(ROOT_PATH, "spec")
|
9
|
-
TMP_PATH = File.join(ROOT_PATH, "tmp")
|
10
|
-
LOG_PATH = File.join(TMP_PATH, "store_schema.log")
|
11
|
-
|
12
|
-
FileUtils.mkdir_p(TMP_PATH)
|
13
7
|
|
14
8
|
require "#{SPEC_PATH}/support/db"
|
data/spec/support/models.rb
CHANGED
data/store_schema.gemspec
CHANGED
@@ -20,7 +20,6 @@ Gem::Specification.new do |spec|
|
|
20
20
|
spec.add_development_dependency "bundler"
|
21
21
|
spec.add_development_dependency "rake"
|
22
22
|
spec.add_development_dependency "rspec"
|
23
|
-
spec.add_development_dependency "mocha"
|
24
23
|
spec.add_development_dependency "sqlite3"
|
25
24
|
spec.add_development_dependency "database_cleaner"
|
26
25
|
spec.add_development_dependency "pry"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: store_schema
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael van Rooijen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -66,20 +66,6 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: mocha
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
69
|
- !ruby/object:Gem::Dependency
|
84
70
|
name: sqlite3
|
85
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -179,7 +165,7 @@ files:
|
|
179
165
|
- lib/store_schema/converter/string.rb
|
180
166
|
- lib/store_schema/module.rb
|
181
167
|
- lib/store_schema/version.rb
|
182
|
-
- spec/lib/
|
168
|
+
- spec/lib/store_schema_spec.rb
|
183
169
|
- spec/spec_helper.rb
|
184
170
|
- spec/support/db.rb
|
185
171
|
- spec/support/env.rb
|
@@ -205,12 +191,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
205
191
|
version: '0'
|
206
192
|
requirements: []
|
207
193
|
rubyforge_project:
|
208
|
-
rubygems_version: 2.4.
|
194
|
+
rubygems_version: 2.4.5
|
209
195
|
signing_key:
|
210
196
|
specification_version: 4
|
211
197
|
summary: Enhances ActiveRecord::Base.store_accessor with data conversion capabilities.
|
212
198
|
test_files:
|
213
|
-
- spec/lib/
|
199
|
+
- spec/lib/store_schema_spec.rb
|
214
200
|
- spec/spec_helper.rb
|
215
201
|
- spec/support/db.rb
|
216
202
|
- spec/support/env.rb
|