store_schema 0.1.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gemfiles/{4.0.gemfile → 5.1.gemfile} +1 -1
- data/.travis.yml +4 -7
- data/LICENSE +1 -1
- data/README.md +13 -16
- data/lib/store_schema/accessor_definer.rb +7 -0
- data/lib/store_schema/converter/boolean.rb +6 -2
- data/lib/store_schema/converter/date_time.rb +10 -12
- data/lib/store_schema/converter/float.rb +5 -1
- data/lib/store_schema/converter/integer.rb +5 -1
- data/lib/store_schema/version.rb +1 -1
- data/spec/lib/store_schema_spec.rb +1 -1
- data/spec/support/db.rb +2 -4
- data/store_schema.gemspec +3 -2
- metadata +21 -10
- data/.gemfiles/4.1.gemfile +0 -3
- data/.gemfiles/4.2.gemfile +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e03d59d9f1597b0d33ac37f1f4023b7627163816
|
4
|
+
data.tar.gz: aff94d3ea629c869496c3428c2c720dd7ce38cc0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3966267cfc6d928223d54e72bd9b51d47b3a553f785d24aacd2c24ee8e4f1d942b90956154f0f26be05f82f55b44654c8713ac983ec52731e0d360faa18bdab9
|
7
|
+
data.tar.gz: bffe743f0985c51232607254bb65dd618cebe53e2c9cfd979970afa204d0ebdf4ab189dcca69b1a54aba8e2d7e553d80268440ba4d6078f93b54e8e73fd2e483
|
data/.travis.yml
CHANGED
data/LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# Store Schema
|
2
2
|
|
3
3
|
[![Gem Version](https://badge.fury.io/rb/store_schema.svg)](http://badge.fury.io/rb/store_schema)
|
4
|
-
[![Code Climate](https://codeclimate.com/github/
|
5
|
-
[![Build Status](https://travis-ci.org/
|
4
|
+
[![Code Climate](https://codeclimate.com/github/mrrooijen/store_schema.png)](https://codeclimate.com/github/mrrooijen/store_schema)
|
5
|
+
[![Build Status](https://travis-ci.org/mrrooijen/store_schema.svg)](https://travis-ci.org/mrrooijen/store_schema)
|
6
6
|
|
7
|
-
StoreSchema, for Rails/ActiveRecord
|
7
|
+
StoreSchema, for Rails/ActiveRecord 5.1.0+, enhances `ActiveRecord::Base.store_accessor` with data conversion capabilities.
|
8
8
|
|
9
9
|
This library was developed for- and extracted from [HireFire].
|
10
10
|
|
@@ -13,9 +13,8 @@ The documentation can be found on [RubyDoc].
|
|
13
13
|
|
14
14
|
### Compatibility
|
15
15
|
|
16
|
-
- Rails/ActiveRecord
|
17
|
-
- Ruby (MRI) 2.0+
|
18
|
-
- Ruby (RBX) 2.2+
|
16
|
+
- Rails/ActiveRecord 5.1.0+
|
17
|
+
- Ruby (MRI) 2.4.0+
|
19
18
|
|
20
19
|
|
21
20
|
### Installation
|
@@ -114,9 +113,8 @@ with any SQL database.
|
|
114
113
|
|
115
114
|
Contributions are welcome, but please conform to these requirements:
|
116
115
|
|
117
|
-
- Ruby (MRI) 2.0+
|
118
|
-
-
|
119
|
-
- ActiveRecord 4.0.0+
|
116
|
+
- Ruby (MRI) 2.4.0+
|
117
|
+
- ActiveRecord 5.1.0+
|
120
118
|
- 100% Spec Coverage
|
121
119
|
- Generated by when running the test suite
|
122
120
|
- 100% [Passing Specs]
|
@@ -158,14 +156,13 @@ Submit a pull request.
|
|
158
156
|
|
159
157
|
### Author / License
|
160
158
|
|
161
|
-
|
162
|
-
Released under the MIT [License].
|
159
|
+
Released under the [MIT License] by [Michael van Rooijen].
|
163
160
|
|
164
|
-
[
|
161
|
+
[Michael van Rooijen]: https://twitter.com/mrrooijen
|
165
162
|
[HireFire]: http://hirefire.io
|
166
|
-
[Passing Specs]: https://travis-ci.org/
|
167
|
-
[Code Climate Score]: https://codeclimate.com/github/
|
168
|
-
[RubyDoc]: http://rubydoc.info/github/
|
169
|
-
[License]: https://github.com/
|
163
|
+
[Passing Specs]: https://travis-ci.org/mrrooijen/store_schema
|
164
|
+
[Code Climate Score]: https://codeclimate.com/github/mrrooijen/store_schema
|
165
|
+
[RubyDoc]: http://rubydoc.info/github/mrrooijen/store_schema/master/frames
|
166
|
+
[MIT License]: https://github.com/mrrooijen/store_schema/blob/master/LICENSE
|
170
167
|
[RubyGems.org]: https://rubygems.org/gems/store_schema
|
171
168
|
[PostgreSQL's HStore Extension]: http://www.postgresql.org/docs/9.3/static/hstore.html
|
@@ -32,6 +32,7 @@ class StoreSchema::AccessorDefiner
|
|
32
32
|
#
|
33
33
|
def define
|
34
34
|
define_store_accessor
|
35
|
+
define_attribute
|
35
36
|
define_getter
|
36
37
|
define_setter
|
37
38
|
end
|
@@ -44,6 +45,12 @@ class StoreSchema::AccessorDefiner
|
|
44
45
|
klass.store_accessor(column, attribute)
|
45
46
|
end
|
46
47
|
|
48
|
+
# Defines the attribute on the class using the {.attribute}.
|
49
|
+
#
|
50
|
+
def define_attribute
|
51
|
+
klass.attribute(attribute)
|
52
|
+
end
|
53
|
+
|
47
54
|
# Enhances the store getter by adding data conversion capabilities.
|
48
55
|
#
|
49
56
|
def define_getter
|
@@ -6,6 +6,10 @@ class StoreSchema::Converter::Boolean < StoreSchema::Converter::Base
|
|
6
6
|
#
|
7
7
|
DB_TRUE_VALUE = "t"
|
8
8
|
|
9
|
+
# @return [String] the database representation of a false value.
|
10
|
+
#
|
11
|
+
DB_FALSE_VALUE = "f"
|
12
|
+
|
9
13
|
# @return [Array] all the values that are considered to be truthy.
|
10
14
|
#
|
11
15
|
TRUE_VALUES = [true, 1, "1", "t", "T", "true", "TRUE", "on", "ON"]
|
@@ -30,9 +34,9 @@ class StoreSchema::Converter::Boolean < StoreSchema::Converter::Base
|
|
30
34
|
#
|
31
35
|
def to_db
|
32
36
|
if TRUE_VALUES.include?(value)
|
33
|
-
|
37
|
+
DB_TRUE_VALUE
|
34
38
|
elsif FALSE_VALUES.include?(value)
|
35
|
-
|
39
|
+
DB_FALSE_VALUE
|
36
40
|
else
|
37
41
|
false
|
38
42
|
end
|
@@ -11,20 +11,18 @@ class StoreSchema::Converter::DateTime < StoreSchema::Converter::Base
|
|
11
11
|
# @return [String, false] false if {#value} is an invalid date-type.
|
12
12
|
#
|
13
13
|
def to_db
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
else
|
23
|
-
false
|
24
|
-
end
|
25
|
-
rescue
|
14
|
+
case value
|
15
|
+
when ::DateTime, ::Date
|
16
|
+
value.strftime(DATETIME_DB_FORMAT)
|
17
|
+
when ::Time
|
18
|
+
value.utc.strftime(DATETIME_DB_FORMAT)
|
19
|
+
when ::String
|
20
|
+
::DateTime.parse(value).strftime(DATETIME_DB_FORMAT)
|
21
|
+
else
|
26
22
|
false
|
27
23
|
end
|
24
|
+
rescue
|
25
|
+
false
|
28
26
|
end
|
29
27
|
|
30
28
|
# Converts the {#value} to a Ruby-type value.
|
@@ -2,6 +2,10 @@ require_relative "base"
|
|
2
2
|
|
3
3
|
class StoreSchema::Converter::Float < StoreSchema::Converter::Base
|
4
4
|
|
5
|
+
# @return [Regexp] an (int | float) value format.
|
6
|
+
#
|
7
|
+
INT_FLOAT_FORMAT = /^\d+|\d+\.\d+$/
|
8
|
+
|
5
9
|
# Converts the {#value} to a database-storable value.
|
6
10
|
#
|
7
11
|
# @return [String, false] false if {#value} is an invalid date-type.
|
@@ -13,7 +17,7 @@ class StoreSchema::Converter::Float < StoreSchema::Converter::Base
|
|
13
17
|
when ::Float
|
14
18
|
value.to_s
|
15
19
|
when ::String
|
16
|
-
if value
|
20
|
+
if value.match(INT_FLOAT_FORMAT)
|
17
21
|
value.to_f.to_s
|
18
22
|
else
|
19
23
|
false
|
@@ -2,6 +2,10 @@ require_relative "base"
|
|
2
2
|
|
3
3
|
class StoreSchema::Converter::Integer < StoreSchema::Converter::Base
|
4
4
|
|
5
|
+
# @return [Regexp] the int value format.
|
6
|
+
#
|
7
|
+
INT_FORMAT = /^\d+$/
|
8
|
+
|
5
9
|
# Converts the {#value} to a database-storable value.
|
6
10
|
#
|
7
11
|
# @return [String, false] false if {#value} is an invalid date-type.
|
@@ -11,7 +15,7 @@ class StoreSchema::Converter::Integer < StoreSchema::Converter::Base
|
|
11
15
|
when ::Integer
|
12
16
|
value.to_s
|
13
17
|
when ::String
|
14
|
-
if value
|
18
|
+
if value.match(INT_FORMAT)
|
15
19
|
value
|
16
20
|
else
|
17
21
|
false
|
data/lib/store_schema/version.rb
CHANGED
data/spec/support/db.rb
CHANGED
@@ -2,7 +2,7 @@ ActiveRecord::Base.establish_connection(
|
|
2
2
|
adapter: "sqlite3", database: ":memory:"
|
3
3
|
)
|
4
4
|
|
5
|
-
class Schema < ActiveRecord::Migration
|
5
|
+
class Schema < ActiveRecord::Migration[4.2]
|
6
6
|
|
7
7
|
def change
|
8
8
|
create_table :websites do |t|
|
@@ -11,6 +11,4 @@ class Schema < ActiveRecord::Migration
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
|
15
|
-
Schema.new.change
|
16
|
-
end
|
14
|
+
Schema.new.change
|
data/store_schema.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.authors = ["Michael van Rooijen"]
|
9
9
|
spec.email = ["michael@vanrooijen.io"]
|
10
10
|
spec.summary = %q{Enhances ActiveRecord::Base.store_accessor with data conversion capabilities.}
|
11
|
-
spec.homepage = "http://
|
11
|
+
spec.homepage = "http://mrrooijen.github.io/store_schema/"
|
12
12
|
spec.license = "MIT"
|
13
13
|
|
14
14
|
spec.files = `git ls-files -z`.split("\x0")
|
@@ -16,11 +16,12 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
17
|
spec.require_paths = ["lib"]
|
18
18
|
|
19
|
-
spec.add_dependency "activerecord", ">=
|
19
|
+
spec.add_dependency "activerecord", ">= 5.0.0"
|
20
20
|
spec.add_development_dependency "bundler"
|
21
21
|
spec.add_development_dependency "rake"
|
22
22
|
spec.add_development_dependency "rspec"
|
23
23
|
spec.add_development_dependency "sqlite3"
|
24
|
+
spec.add_development_dependency "json"
|
24
25
|
spec.add_development_dependency "database_cleaner"
|
25
26
|
spec.add_development_dependency "pry"
|
26
27
|
spec.add_development_dependency "simplecov"
|
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:
|
4
|
+
version: 1.0.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: 2017-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 5.0.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 5.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: json
|
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
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
- !ruby/object:Gem::Dependency
|
84
98
|
name: database_cleaner
|
85
99
|
requirement: !ruby/object:Gem::Requirement
|
@@ -143,9 +157,7 @@ executables: []
|
|
143
157
|
extensions: []
|
144
158
|
extra_rdoc_files: []
|
145
159
|
files:
|
146
|
-
- ".gemfiles/
|
147
|
-
- ".gemfiles/4.1.gemfile"
|
148
|
-
- ".gemfiles/4.2.gemfile"
|
160
|
+
- ".gemfiles/5.1.gemfile"
|
149
161
|
- ".gitignore"
|
150
162
|
- ".rspec"
|
151
163
|
- ".travis.yml"
|
@@ -171,7 +183,7 @@ files:
|
|
171
183
|
- spec/support/env.rb
|
172
184
|
- spec/support/models.rb
|
173
185
|
- store_schema.gemspec
|
174
|
-
homepage: http://
|
186
|
+
homepage: http://mrrooijen.github.io/store_schema/
|
175
187
|
licenses:
|
176
188
|
- MIT
|
177
189
|
metadata: {}
|
@@ -191,7 +203,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
191
203
|
version: '0'
|
192
204
|
requirements: []
|
193
205
|
rubyforge_project:
|
194
|
-
rubygems_version: 2.
|
206
|
+
rubygems_version: 2.6.8
|
195
207
|
signing_key:
|
196
208
|
specification_version: 4
|
197
209
|
summary: Enhances ActiveRecord::Base.store_accessor with data conversion capabilities.
|
@@ -201,4 +213,3 @@ test_files:
|
|
201
213
|
- spec/support/db.rb
|
202
214
|
- spec/support/env.rb
|
203
215
|
- spec/support/models.rb
|
204
|
-
has_rdoc:
|
data/.gemfiles/4.1.gemfile
DELETED
data/.gemfiles/4.2.gemfile
DELETED