store_schema 0.1.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 5a05dab9a51e83ac7afde53a40dc65dddd2d388d
4
- data.tar.gz: 9036c033e270aebcd9f08fd56da0b7553db09b67
2
+ SHA256:
3
+ metadata.gz: 3b3aefc58fadcb7306065530489d378fa17d6e41c59c87454324d7c98340775f
4
+ data.tar.gz: 68e2db4745115fb7b7572a87a8d2ad04557fab8bc5677d0430bf9b3459e4d5fd
5
5
  SHA512:
6
- metadata.gz: 1c0a5cf4d0bf2a57a75c788aa619317fed9a7d5accedd181d027f6b9011b726d38a8c49389ab1e1a252668defa1c8f08b8a34ee281f21ce92962c5ba3610520c
7
- data.tar.gz: c764b979e4d63d8ce23898e309200a0671102eba64a8a56255c8e434c6866a87f7dd11ed2d635bef9ae94eb806b323d85898680eed88fc79563292f094122e54
6
+ metadata.gz: e4ee130a61a93e8d25ee12a8c5d6083cd45b3a807d3ce7be81394bfe81a5f65e8e2820bfe20c4ded0579181fc84e4286f59d0e89b80865f1aa1099f13e766de1
7
+ data.tar.gz: 32145b81ae75c951c052708d801b0e9c3e6cef3888737dba9dff65b5630f68d85d06adef536aaf860cb223dacd5421d34d1aedb597166bb64ea417123bc04e7f
data/CHANGELOG.md ADDED
@@ -0,0 +1,17 @@
1
+ ## v2.0.0
2
+
3
+ * Add support for Ruby 3
4
+ * Add support for Active Record 6.1
5
+ * Drop support for Active Record 5
6
+
7
+
8
+ ## v1.1.1
9
+
10
+ * Made all String objects immutable
11
+
12
+
13
+ ## v1.1.0
14
+
15
+ * Added support for Ruby 2.5 and 2.6
16
+ * Added support for ActiveRecord 5.2 and 6.0
17
+ * Dropped support for Ruby 2.4
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2015 Michael van Rooijen
1
+ Copyright (c) Michael van Rooijen
2
2
 
3
3
  MIT License
4
4
 
data/README.md CHANGED
@@ -1,10 +1,9 @@
1
1
  # Store Schema
2
2
 
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/meskyanichi/store_schema.png)](https://codeclimate.com/github/meskyanichi/store_schema)
5
- [![Build Status](https://travis-ci.org/meskyanichi/store_schema.svg)](https://travis-ci.org/meskyanichi/store_schema)
3
+ [![Gem Version](https://badge.fury.io/rb/store_schema.svg)](https://badge.fury.io/rb/store_schema)
4
+ [![Test Status](https://github.com/mrrooijen/store_schema/workflows/Test/badge.svg)](https://github.com/mrrooijen/store_schema/actions)
6
5
 
7
- StoreSchema, for Rails/ActiveRecord 4.0.0+, enhances `ActiveRecord::Base.store_accessor` with data conversion capabilities.
6
+ StoreSchema enhances `ActiveRecord::Base.store_accessor` with data type conversion capabilities.
8
7
 
9
8
  This library was developed for- and extracted from [HireFire].
10
9
 
@@ -13,9 +12,11 @@ The documentation can be found on [RubyDoc].
13
12
 
14
13
  ### Compatibility
15
14
 
16
- - Rails/ActiveRecord 4.0.0+
17
- - Ruby (MRI) 2.0+
18
- - Ruby (RBX) 2.2+
15
+ - Ruby 2.5+
16
+ - ActiveRecord 6.0+
17
+
18
+ It's likely that all ActiveRecord-supported databases will work.
19
+ However, we currently only test against PostgreSQL, MySQL and SQLite.
19
20
 
20
21
 
21
22
  ### Installation
@@ -29,8 +30,7 @@ gem "store_schema"
29
30
 
30
31
  ### Example
31
32
 
32
- This example assumes you have a `websites` table with a column named
33
- `config` of type `text`.
33
+ This example assumes that you have a `websites` table with a `config` column of type `text`.
34
34
 
35
35
  Define a model and use `store_schema`.
36
36
 
@@ -40,11 +40,11 @@ class Website < ActiveRecord::Base
40
40
  # Tell ActiveRecord that we want to serialize the :config attribute
41
41
  # and store the serialized data as text in the config column.
42
42
  #
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).
43
+ # By default, `store` serializes your data using the YAML coder. You can
44
+ # swap the YAML coder out for other coders, such as JSON.
45
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`.
46
+ # Note: If you're using PostgresSQL hstore- or json instead of a
47
+ # plain text column type, don't define `store :config`.
48
48
  #
49
49
  store :config, coder: JSON
50
50
 
@@ -52,10 +52,10 @@ class Website < ActiveRecord::Base
52
52
  # ActiveRecord::Migration.
53
53
  #
54
54
  store_schema :config do |s|
55
- s.string :name
56
- s.integer :visitors
57
- s.float :apdex
58
- s.boolean :ssl
55
+ s.string :name
56
+ s.integer :visitors
57
+ s.float :apdex
58
+ s.boolean :ssl
59
59
  s.datetime :published_at
60
60
  end
61
61
  end
@@ -66,91 +66,106 @@ the generated accessors.
66
66
 
67
67
  ```rb
68
68
  website = Website.create(
69
- name: "Example Website",
70
- visitors: 1337,
71
- apdex: 1.0,
72
- ssl: true,
73
- published_at: Time.now
69
+ :name => "Example Website",
70
+ :visitors => 9001,
71
+ :apdex => 1.0,
72
+ :ssl => true,
73
+ :published_at => Time.now
74
74
  )
75
75
 
76
- p website.name # => "Example Website" (String)
77
- p website.visitors # => 1337 (Fixnum)
78
- p website.apdex # => 1.0 (Float)
79
- p website.ssl # => true (TrueClass)
80
- p website.published_at # => "Thu, 18 Sep 2014 23:18:11 +0000" (DateTime)
76
+ website.name # => (String) "Example Website"
77
+ website.visitors # => (Integer) 9001
78
+ website.apdex # => (Float) 1.0
79
+ website.ssl # => (TrueClass) true
80
+ website.published_at # => (DateTime) "Thu, 18 Sep 2014 23:18:11 +0000"
81
81
 
82
- p website.config
82
+ website.config
83
83
  # =>
84
84
  # {
85
- # "name" => "Example Website",
86
- # "visitors" => "1337",
87
- # "apdex" => "1.0",
88
- # "ssl" => "t",
85
+ # "name" => "Example Website",
86
+ # "visitors" => "9001",
87
+ # "apdex" => "1.0",
88
+ # "ssl" => "t",
89
89
  # "published_at" => "2014-09-18 23:18:11.583168000"
90
90
  # }
91
91
  ```
92
92
 
93
- That's it. This is similar to just using `store_accessor`, except that
94
- `store_schema` is more strict as to what data types are stored. It attempts
95
- to stay consistent with ActiveRecord's column conventions such as storing
96
- booleans (`0`, `"0"`, `1`, `"1"`, `"t"`, `"T"`, `"f"`, `"F"`, `true`,
97
- `"true"`, `"TRUE"`, `false`, `"false"`, `"FALSE"`, `"on"`, `"ON"`, `"off"`,
98
- `"OFF"`) as `"t"` and `"f"`, storing `Time`, `Date` as `DateTime`,
99
- ensuring `Time` is UTC prior to being stored, and more.
100
-
101
- When accessing stored data, it properly converts them to their data types.
102
- For example, `"t"` is converted to a TrueClass, and
103
- `"2014-09-18 23:18:11.583168000"` is converted back to a DateTime.
104
- See above example.
105
-
106
- If you need to be able to query these serialized attributes,
107
- consider using [PostgreSQL's HStore Extension]. If you do not need to
108
- be able to query the serialized data, you can simply use a text-type column
109
- and use the `store <column>[, coder: JSON]` method in your model which works
110
- with any SQL database.
93
+ This is similar to using ActiveRecord's built-in `store_accessor`, except
94
+ that `store_schema` is more strict about which data types are stored. It attempts
95
+ to remain consistent with ActiveRecord's regular column storage conventions.
96
+
97
+ * String
98
+ * Assigned as: `String`
99
+ * Stored as: `String`
100
+ * Retrieved as: `String`
101
+ * Integer
102
+ * Assigned as: `Integer`
103
+ * Stored as: `String`
104
+ * Retrieved as: `Integer`
105
+ * Float
106
+ * Assigned as: `Float`
107
+ * Stored as: `String`
108
+ * Retrieved as: `Float`
109
+ * Boolean (TrueClass)
110
+ * Assigned as: `1`, `"1"`, `"t"`, `"T"`, `true`, `"true"`, `"TRUE"`, `"on"`, `"ON"`
111
+ * Stored as: `"t"`
112
+ * Retrieved as: `true`
113
+ * Boolean (FalseClass)
114
+ * Assigned as: `0`, `"0"`, `"f"`, `"F"`, `false`, `"false"`, `"FALSE"`, `"off"`, `"OFF"`
115
+ * Stored as: `"f"`
116
+ * Retrieved as: `false`
117
+ * DateTime
118
+ * Assigned as: `Date`, `Time`, `DateTime`
119
+ * Stored as: `"2014-09-18 23:18:11.583168000"` (using UTC time zone)
120
+ * Retrieved as: `DateTime`
121
+
122
+ If you need to be able to query these serialized attributes, consider using
123
+ the PostgreSQL hstore extension. Otherwise, you can simply use a text column type
124
+ and define `store <column>[, coder: JSON]` in your model and it should work with
125
+ any ActiveRecord-compatible database.
111
126
 
112
127
 
113
128
  ### Contributing
114
129
 
115
130
  Contributions are welcome, but please conform to these requirements:
116
131
 
117
- - Ruby (MRI) 2.0+
118
- - Ruby (RBX) 2.2+
119
- - ActiveRecord 4.0.0+
120
- - 100% Spec Coverage
121
- - Generated by when running the test suite
122
- - 100% [Passing Specs]
123
- - Run test suite with `$ rspec spec`
124
- - 4.0 [Code Climate Score]
125
- - Run `$ rubycritic lib` to generate the score locally and receive tips
126
- - No code smells
127
- - No duplication
132
+ - Ruby (MRI) 2.5+
133
+ - ActiveRecord 6.0+
134
+ - 100% Test Coverage
135
+ - Coverage results are generated after each test run at `coverage/index.html`
136
+ - 100% Passing Tests
137
+ - Run test suite with `$ rake test`
128
138
 
129
139
  To start contributing, fork the project, clone it, and install the development dependencies:
130
140
 
131
141
  ```
132
- git clone git@github.com:USERNAME/store_schema.git
133
- cd store_schema
134
- bundle
142
+ $ git clone git@github.com:USERNAME/store_schema.git
143
+ $ cd store_schema
144
+ $ bundle
135
145
  ```
136
146
 
137
- Ensure that everything works:
147
+ Tests are run against the following databases, so be sure they're installed prior to running the tests:
148
+
149
+ * PostgreSQL
150
+ * MySQL
151
+ * SQLite
152
+
153
+ To run the tests:
138
154
 
139
155
  ```
140
- rspec spec
141
- rubycritic lib
156
+ $ rake test
142
157
  ```
143
158
 
144
159
  To run the local documentation server:
145
160
 
146
161
  ```
147
- yard server --reload
162
+ $ rake doc
148
163
  ```
149
164
 
150
- Create a new branch and start hacking:
165
+ Create a new branch to start contributing:
151
166
 
152
167
  ```
153
- git checkout -b my-contributions
168
+ $ git checkout -b my-contribution master
154
169
  ```
155
170
 
156
171
  Submit a pull request.
@@ -158,14 +173,10 @@ Submit a pull request.
158
173
 
159
174
  ### Author / License
160
175
 
161
- Copyright (c) 2015 Michael van Rooijen ( [@meskyanichi] )<br />
162
- Released under the MIT [License].
163
-
164
- [@meskyanichi]: https://twitter.com/meskyanichi
165
- [HireFire]: http://hirefire.io
166
- [Passing Specs]: https://travis-ci.org/meskyanichi/store_schema
167
- [Code Climate Score]: https://codeclimate.com/github/meskyanichi/store_schema
168
- [RubyDoc]: http://rubydoc.info/github/meskyanichi/store_schema/master/frames
169
- [License]: https://github.com/meskyanichi/store_schema/blob/master/LICENSE
170
- [RubyGems.org]: https://rubygems.org/gems/store_schema
171
- [PostgreSQL's HStore Extension]: http://www.postgresql.org/docs/9.3/static/hstore.html
176
+ Released under the [MIT License] by [Michael van Rooijen].
177
+
178
+ [Michael van Rooijen]: https://twitter.com/mrrooijen
179
+ [HireFire]: https://www.hirefire.io
180
+ [Passing Specs]: https://travis-ci.org/mrrooijen/store_schema
181
+ [RubyDoc]: https://rubydoc.info/github/mrrooijen/store_schema/master/frames
182
+ [MIT License]: https://github.com/mrrooijen/store_schema/blob/master/LICENSE
data/lib/store_schema.rb CHANGED
@@ -1,9 +1,11 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module StoreSchema
2
- require "store_schema/accessor_definer"
3
- require "store_schema/configuration"
4
- require "store_schema/converter"
5
- require "store_schema/module"
6
- require "store_schema/version"
4
+ require_relative "store_schema/accessor_definer"
5
+ require_relative "store_schema/configuration"
6
+ require_relative "store_schema/converter"
7
+ require_relative "store_schema/module"
8
+ require_relative "store_schema/version"
7
9
  end
8
10
 
9
11
  if defined?(ActiveRecord::Base)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class StoreSchema::AccessorDefiner
2
4
 
3
5
  # @return [Class]
@@ -22,9 +24,9 @@ class StoreSchema::AccessorDefiner
22
24
  # @param attribute [Symbol] the name of the {#column}'s attribute
23
25
  #
24
26
  def initialize(klass, column, type, attribute)
25
- @klass = klass
26
- @column = column
27
- @type = type
27
+ @klass = klass
28
+ @column = column
29
+ @type = type
28
30
  @attribute = attribute
29
31
  end
30
32
 
@@ -32,6 +34,7 @@ class StoreSchema::AccessorDefiner
32
34
  #
33
35
  def define
34
36
  define_store_accessor
37
+ define_attribute
35
38
  define_getter
36
39
  define_setter
37
40
  end
@@ -44,6 +47,12 @@ class StoreSchema::AccessorDefiner
44
47
  klass.store_accessor(column, attribute)
45
48
  end
46
49
 
50
+ # Defines the attribute on the class using the {.attribute}.
51
+ #
52
+ def define_attribute
53
+ klass.attribute(attribute)
54
+ end
55
+
47
56
  # Enhances the store getter by adding data conversion capabilities.
48
57
  #
49
58
  def define_getter
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class StoreSchema::Configuration
2
4
 
3
5
  # @return [Symbol]
@@ -11,7 +13,7 @@ class StoreSchema::Configuration
11
13
  # @param column [Symbol] the table column to generate the accessors for
12
14
  #
13
15
  def initialize(column)
14
- @column = column
16
+ @column = column
15
17
  @attributes = {}
16
18
  end
17
19
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class StoreSchema::Converter
2
4
  require_relative "converter/string"
3
5
  require_relative "converter/integer"
@@ -9,11 +11,11 @@ class StoreSchema::Converter
9
11
  # and the converter classes.
10
12
  #
11
13
  MAPPING = {
12
- string: String,
13
- integer: Integer,
14
- float: Float,
15
- datetime: DateTime,
16
- boolean: Boolean
14
+ :string => String,
15
+ :integer => Integer,
16
+ :float => Float,
17
+ :datetime => DateTime,
18
+ :boolean => Boolean,
17
19
  }
18
20
 
19
21
  # @return [Object]
@@ -29,7 +31,7 @@ class StoreSchema::Converter
29
31
  #
30
32
  def initialize(value, type)
31
33
  @value = value
32
- @type = type
34
+ @type = type
33
35
  end
34
36
 
35
37
  # Converts {#value} from a Ruby-type value to a database-storable value.
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class StoreSchema::Converter::Base
2
4
 
3
5
  # @return [Object]
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative "base"
2
4
 
3
5
  class StoreSchema::Converter::Boolean < StoreSchema::Converter::Base
@@ -6,6 +8,10 @@ class StoreSchema::Converter::Boolean < StoreSchema::Converter::Base
6
8
  #
7
9
  DB_TRUE_VALUE = "t"
8
10
 
11
+ # @return [String] the database representation of a false value.
12
+ #
13
+ DB_FALSE_VALUE = "f"
14
+
9
15
  # @return [Array] all the values that are considered to be truthy.
10
16
  #
11
17
  TRUE_VALUES = [true, 1, "1", "t", "T", "true", "TRUE", "on", "ON"]
@@ -30,9 +36,9 @@ class StoreSchema::Converter::Boolean < StoreSchema::Converter::Base
30
36
  #
31
37
  def to_db
32
38
  if TRUE_VALUES.include?(value)
33
- "t"
39
+ DB_TRUE_VALUE
34
40
  elsif FALSE_VALUES.include?(value)
35
- "f"
41
+ DB_FALSE_VALUE
36
42
  else
37
43
  false
38
44
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative "base"
2
4
 
3
5
  class StoreSchema::Converter::DateTime < StoreSchema::Converter::Base
@@ -11,20 +13,18 @@ class StoreSchema::Converter::DateTime < StoreSchema::Converter::Base
11
13
  # @return [String, false] false if {#value} is an invalid date-type.
12
14
  #
13
15
  def to_db
14
- begin
15
- case value
16
- when ::DateTime, ::Date
17
- value.strftime(DATETIME_DB_FORMAT)
18
- when ::Time
19
- value.utc.strftime(DATETIME_DB_FORMAT)
20
- when ::String
21
- ::DateTime.parse(value).strftime(DATETIME_DB_FORMAT)
22
- else
23
- false
24
- end
25
- rescue
16
+ case value
17
+ when ::DateTime, ::Date
18
+ value.strftime(DATETIME_DB_FORMAT)
19
+ when ::Time
20
+ value.utc.strftime(DATETIME_DB_FORMAT)
21
+ when ::String
22
+ ::DateTime.parse(value).strftime(DATETIME_DB_FORMAT)
23
+ else
26
24
  false
27
25
  end
26
+ rescue
27
+ false
28
28
  end
29
29
 
30
30
  # Converts the {#value} to a Ruby-type value.
@@ -1,7 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative "base"
2
4
 
3
5
  class StoreSchema::Converter::Float < StoreSchema::Converter::Base
4
6
 
7
+ # @return [Regexp] an (int | float) value format.
8
+ #
9
+ INT_FLOAT_FORMAT = /^\d+|\d+\.\d+$/
10
+
5
11
  # Converts the {#value} to a database-storable value.
6
12
  #
7
13
  # @return [String, false] false if {#value} is an invalid date-type.
@@ -13,7 +19,7 @@ class StoreSchema::Converter::Float < StoreSchema::Converter::Base
13
19
  when ::Float
14
20
  value.to_s
15
21
  when ::String
16
- if value =~ /^\d+|\d+\.\d+$/
22
+ if value.match(INT_FLOAT_FORMAT)
17
23
  value.to_f.to_s
18
24
  else
19
25
  false
@@ -1,7 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative "base"
2
4
 
3
5
  class StoreSchema::Converter::Integer < StoreSchema::Converter::Base
4
6
 
7
+ # @return [Regexp] the int value format.
8
+ #
9
+ INT_FORMAT = /^\d+$/
10
+
5
11
  # Converts the {#value} to a database-storable value.
6
12
  #
7
13
  # @return [String, false] false if {#value} is an invalid date-type.
@@ -11,7 +17,7 @@ class StoreSchema::Converter::Integer < StoreSchema::Converter::Base
11
17
  when ::Integer
12
18
  value.to_s
13
19
  when ::String
14
- if value =~ /^\d+$/
20
+ if value.match(INT_FORMAT)
15
21
  value
16
22
  else
17
23
  false
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require_relative "base"
2
4
 
3
5
  class StoreSchema::Converter::String < StoreSchema::Converter::Base
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module StoreSchema::Module
2
4
 
3
5
  def self.included(base)
@@ -11,14 +13,14 @@ module StoreSchema::Module
11
13
  # # Gemfile
12
14
  # gem "store_schema"
13
15
  #
14
- # # app/models/project.rb
16
+ # # app/models/website.rb
15
17
  # class Website < ActiveRecord::Base
16
18
  #
17
19
  # store_schema :config do |s|
18
- # s.string :name
19
- # s.integer :visitors
20
- # s.float :apdex
21
- # s.boolean :ssl
20
+ # s.string :name
21
+ # s.integer :visitors
22
+ # s.float :apdex
23
+ # s.boolean :ssl
22
24
  # s.datetime :published_at
23
25
  # end
24
26
  # end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module StoreSchema
2
- VERSION = "0.1.0"
4
+ VERSION = "2.0.0"
3
5
  end
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.1.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael van Rooijen
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-21 00:00:00.000000000 Z
11
+ date: 2021-04-20 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: 4.0.0
19
+ version: 6.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: 4.0.0
26
+ version: 6.0.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -42,117 +42,110 @@ dependencies:
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 13.0.3
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: 13.0.3
55
55
  - !ruby/object:Gem::Dependency
56
- name: rspec
56
+ name: minitest
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: 5.14.4
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: 5.14.4
69
69
  - !ruby/object:Gem::Dependency
70
- name: sqlite3
70
+ name: pg
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 1.2.3
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: 1.2.3
83
83
  - !ruby/object:Gem::Dependency
84
- name: database_cleaner
84
+ name: mysql2
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: 0.5.3
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: 0.5.3
97
97
  - !ruby/object:Gem::Dependency
98
- name: pry
98
+ name: sqlite3
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ">="
101
+ - - "~>"
102
102
  - !ruby/object:Gem::Version
103
- version: '0'
103
+ version: 1.4.2
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ">="
108
+ - - "~>"
109
109
  - !ruby/object:Gem::Version
110
- version: '0'
110
+ version: 1.4.2
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: simplecov
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
- - - ">="
115
+ - - "~>"
116
116
  - !ruby/object:Gem::Version
117
- version: '0'
117
+ version: 0.21.2
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
121
121
  requirements:
122
- - - ">="
122
+ - - "~>"
123
123
  - !ruby/object:Gem::Version
124
- version: '0'
124
+ version: 0.21.2
125
125
  - !ruby/object:Gem::Dependency
126
126
  name: yard
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
- - - ">="
129
+ - - "~>"
130
130
  - !ruby/object:Gem::Version
131
- version: '0'
131
+ version: 0.9.26
132
132
  type: :development
133
133
  prerelease: false
134
134
  version_requirements: !ruby/object:Gem::Requirement
135
135
  requirements:
136
- - - ">="
136
+ - - "~>"
137
137
  - !ruby/object:Gem::Version
138
- version: '0'
139
- description:
138
+ version: 0.9.26
139
+ description:
140
140
  email:
141
141
  - michael@vanrooijen.io
142
142
  executables: []
143
143
  extensions: []
144
144
  extra_rdoc_files: []
145
145
  files:
146
- - ".gemfiles/4.0.gemfile"
147
- - ".gemfiles/4.1.gemfile"
148
- - ".gemfiles/4.2.gemfile"
149
- - ".gitignore"
150
- - ".rspec"
151
- - ".travis.yml"
152
- - Gemfile
146
+ - CHANGELOG.md
153
147
  - LICENSE
154
148
  - README.md
155
- - Rakefile
156
149
  - lib/store_schema.rb
157
150
  - lib/store_schema/accessor_definer.rb
158
151
  - lib/store_schema/configuration.rb
@@ -165,17 +158,11 @@ files:
165
158
  - lib/store_schema/converter/string.rb
166
159
  - lib/store_schema/module.rb
167
160
  - lib/store_schema/version.rb
168
- - spec/lib/store_schema_spec.rb
169
- - spec/spec_helper.rb
170
- - spec/support/db.rb
171
- - spec/support/env.rb
172
- - spec/support/models.rb
173
- - store_schema.gemspec
174
- homepage: http://meskyanichi.github.io/store_schema/
161
+ homepage: https://github.com/mrrooijen/store_schema
175
162
  licenses:
176
163
  - MIT
177
164
  metadata: {}
178
- post_install_message:
165
+ post_install_message:
179
166
  rdoc_options: []
180
167
  require_paths:
181
168
  - lib
@@ -183,22 +170,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
183
170
  requirements:
184
171
  - - ">="
185
172
  - !ruby/object:Gem::Version
186
- version: '0'
173
+ version: 2.5.0
187
174
  required_rubygems_version: !ruby/object:Gem::Requirement
188
175
  requirements:
189
176
  - - ">="
190
177
  - !ruby/object:Gem::Version
191
178
  version: '0'
192
179
  requirements: []
193
- rubyforge_project:
194
- rubygems_version: 2.4.5
195
- signing_key:
180
+ rubygems_version: 3.2.15
181
+ signing_key:
196
182
  specification_version: 4
197
- summary: Enhances ActiveRecord::Base.store_accessor with data conversion capabilities.
198
- test_files:
199
- - spec/lib/store_schema_spec.rb
200
- - spec/spec_helper.rb
201
- - spec/support/db.rb
202
- - spec/support/env.rb
203
- - spec/support/models.rb
204
- has_rdoc:
183
+ summary: Enhances `ActiveRecord::Base.store_accessor` with data type conversion capabilities.
184
+ test_files: []
@@ -1,3 +0,0 @@
1
- source "https://rubygems.org"
2
- gem "activerecord", "~> 4.0.0"
3
- gemspec path: "../"
@@ -1,3 +0,0 @@
1
- source "https://rubygems.org"
2
- gem "activerecord", "~> 4.1.0"
3
- gemspec path: "../"
@@ -1,3 +0,0 @@
1
- source "https://rubygems.org"
2
- gem "activerecord", "4.2.0.beta1"
3
- gemspec path: "../"
data/.gitignore DELETED
@@ -1,23 +0,0 @@
1
- *.gem
2
- *.rbc
3
- .bundle
4
- .config
5
- .yardoc
6
- Gemfile.lock
7
- InstalledFiles
8
- _yardoc
9
- coverage
10
- doc/
11
- lib/bundler/man
12
- pkg
13
- rdoc
14
- spec/reports
15
- test/tmp
16
- test/version_tmp
17
- tmp
18
- *.bundle
19
- *.so
20
- *.o
21
- *.a
22
- mkmf.log
23
- .DS_Store
data/.rspec DELETED
@@ -1,2 +0,0 @@
1
- --color
2
- --require spec_helper
data/.travis.yml DELETED
@@ -1,10 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.0.0
4
- - 2.1.0
5
- - 2.2.0
6
- - rbx-2.2
7
- gemfile:
8
- - .gemfiles/4.0.gemfile
9
- - .gemfiles/4.1.gemfile
10
- - .gemfiles/4.2.gemfile
data/Gemfile DELETED
@@ -1,2 +0,0 @@
1
- source "https://rubygems.org"
2
- gemspec
data/Rakefile DELETED
@@ -1,4 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
- RSpec::Core::RakeTask.new(:spec)
4
- task default: :spec
@@ -1,148 +0,0 @@
1
- require "spec_helper"
2
-
3
- RSpec.describe "StoreSchema" do
4
-
5
- let(:website) { Website.new }
6
-
7
- describe "nil" do
8
-
9
- it "should stay nil" do
10
- website.update_attribute(:name, nil)
11
- expect(website.reload.name).to be_nil
12
- end
13
- end
14
-
15
- describe "string" do
16
-
17
- it "should remain a string" do
18
- website.update_attribute(:name, "Store Schema")
19
- expect(website.reload.name).to eq("Store Schema")
20
- end
21
-
22
- it "should convert to nil if incompatible type" do
23
- website.update_attribute(:name, true)
24
- expect(website.name).to eq(nil)
25
- end
26
- end
27
-
28
- describe "integer" do
29
-
30
- it "should cast to string and back to integer" do
31
- website.update_attribute(:visitors, 1337)
32
- expect(website.config["visitors"]).to eq("1337")
33
- expect(website.visitors).to eq(1337)
34
- end
35
-
36
- it "should accept a string value of a digit" do
37
- website.update_attribute(:visitors, "1337")
38
- expect(website.config["visitors"]).to eq("1337")
39
- expect(website.visitors).to eq(1337)
40
- end
41
-
42
- it "should convert to nil if incompatible value" do
43
- website.update_attribute(:visitors, "abc")
44
- expect(website.visitors).to eq(nil)
45
- end
46
-
47
- it "should convert to nil if incompatible type" do
48
- website.update_attribute(:visitors, true)
49
- expect(website.visitors).to eq(nil)
50
- end
51
- end
52
-
53
- describe "float" do
54
-
55
- it "should cast to string and back to float" do
56
- website.update_attribute(:apdex, 0.9)
57
- expect(website.config["apdex"]).to eq("0.9")
58
- expect(website.apdex).to eq(0.9)
59
- end
60
-
61
- it "should accept a string value of a float" do
62
- website.update_attribute(:apdex, "0.9")
63
- expect(website.config["apdex"]).to eq("0.9")
64
- expect(website.apdex).to eq(0.9)
65
- end
66
-
67
- it "should accept an integer value" do
68
- website.update_attribute(:apdex, 1)
69
- expect(website.config["apdex"]).to eq("1.0")
70
- expect(website.apdex).to eq(1.0)
71
- end
72
-
73
- it "should accept a string value of an integer" do
74
- website.update_attribute(:apdex, "1")
75
- expect(website.config["apdex"]).to eq("1.0")
76
- expect(website.apdex).to eq(1.0)
77
- end
78
-
79
- it "should convert to nil if incompatible value" do
80
- website.update_attribute(:apdex, "abc")
81
- expect(website.apdex).to eq(nil)
82
- end
83
-
84
- it "should convert to nil if incompatible type" do
85
- website.update_attribute(:apdex, true)
86
- expect(website.apdex).to eq(nil)
87
- end
88
- end
89
-
90
- describe "boolean" do
91
-
92
- it "should cast to string and back to boolean" do
93
- StoreSchema::Converter::Boolean::TRUE_VALUES.each do |value|
94
- website.update_attribute(:ssl, value)
95
- expect(website.config["ssl"]).to eq("t")
96
- expect(website.ssl).to eq(true)
97
- end
98
-
99
- StoreSchema::Converter::Boolean::FALSE_VALUES.each do |value|
100
- website.update_attribute(:ssl, value)
101
- expect(website.config["ssl"]).to eq("f")
102
- expect(website.ssl).to eq(false)
103
- end
104
- end
105
-
106
- it "should convert to nil if incompatible type" do
107
- website.update_attribute(:ssl, "abc")
108
- expect(website.ssl).to eq(nil)
109
- end
110
- end
111
-
112
- describe "datetime" do
113
-
114
- it "should cast Date to string and back to datetime" do
115
- value = Date.new(2020)
116
- website.update_attribute(:published_at, value)
117
- expect(website.config["published_at"]).to eq("2020-01-01 00:00:00.000000000")
118
- expect(website.published_at).to eq("Wed, 01 Jan 2020 00:00:00.000000000 +0000")
119
- expect(website.published_at.class).to eq(DateTime)
120
- end
121
-
122
- it "should cast Time to string and back to datetime" do
123
- value = Time.utc(2020)
124
- website.update_attribute(:published_at, value)
125
- expect(website.config["published_at"]).to eq("2020-01-01 00:00:00.000000000")
126
- expect(website.published_at).to eq("Wed, 01 Jan 2020 00:00:00.000000000 +0000")
127
- expect(website.published_at.class).to eq(DateTime)
128
- end
129
-
130
- it "should cast DateTime to string and back to datetime" do
131
- value = DateTime.new(2020)
132
- website.update_attribute(:published_at, value)
133
- expect(website.config["published_at"]).to eq("2020-01-01 00:00:00.000000000")
134
- expect(website.published_at).to eq("Wed, 01 Jan 2020 00:00:00.000000000 +0000")
135
- expect(website.published_at.class).to eq(DateTime)
136
- end
137
-
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)
141
- end
142
-
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)
146
- end
147
- end
148
- end
data/spec/spec_helper.rb DELETED
@@ -1,14 +0,0 @@
1
- $LOAD_PATH.unshift(File.expand_path("../../lib", __FILE__))
2
- require File.expand_path("../support/env", __FILE__)
3
-
4
- require "database_cleaner"
5
- require "simplecov"
6
- SimpleCov.start
7
-
8
- require "store_schema"
9
- require File.expand_path("../support/models", __FILE__)
10
-
11
- RSpec.configure do |config|
12
- config.before { DatabaseCleaner.start }
13
- config.after { DatabaseCleaner.clean }
14
- end
data/spec/support/db.rb DELETED
@@ -1,16 +0,0 @@
1
- ActiveRecord::Base.establish_connection(
2
- adapter: "sqlite3", database: ":memory:"
3
- )
4
-
5
- class Schema < ActiveRecord::Migration
6
-
7
- def change
8
- create_table :websites do |t|
9
- t.text :config
10
- end
11
- end
12
- end
13
-
14
- silence_stream(STDOUT) do
15
- Schema.new.change
16
- end
data/spec/support/env.rb DELETED
@@ -1,8 +0,0 @@
1
- require "pry"
2
- require "sqlite3"
3
- require "active_record"
4
-
5
- ROOT_PATH = File.expand_path("../../..", __FILE__)
6
- SPEC_PATH = File.join(ROOT_PATH, "spec")
7
-
8
- require "#{SPEC_PATH}/support/db"
@@ -1,12 +0,0 @@
1
- class Website < ActiveRecord::Base
2
-
3
- store :config, coder: JSON
4
-
5
- store_schema :config do |s|
6
- s.string :name
7
- s.integer :visitors
8
- s.float :apdex
9
- s.boolean :ssl
10
- s.datetime :published_at
11
- end
12
- end
data/store_schema.gemspec DELETED
@@ -1,28 +0,0 @@
1
- lib = File.expand_path("../lib", __FILE__)
2
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
- require "store_schema/version"
4
-
5
- Gem::Specification.new do |spec|
6
- spec.name = "store_schema"
7
- spec.version = StoreSchema::VERSION
8
- spec.authors = ["Michael van Rooijen"]
9
- spec.email = ["michael@vanrooijen.io"]
10
- spec.summary = %q{Enhances ActiveRecord::Base.store_accessor with data conversion capabilities.}
11
- spec.homepage = "http://meskyanichi.github.io/store_schema/"
12
- spec.license = "MIT"
13
-
14
- spec.files = `git ls-files -z`.split("\x0")
15
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
- spec.require_paths = ["lib"]
18
-
19
- spec.add_dependency "activerecord", ">= 4.0.0"
20
- spec.add_development_dependency "bundler"
21
- spec.add_development_dependency "rake"
22
- spec.add_development_dependency "rspec"
23
- spec.add_development_dependency "sqlite3"
24
- spec.add_development_dependency "database_cleaner"
25
- spec.add_development_dependency "pry"
26
- spec.add_development_dependency "simplecov"
27
- spec.add_development_dependency "yard"
28
- end