store_attribute 0.5.2 → 0.5.3

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: 191063cf9091064962abf3548153b75656a55665
4
- data.tar.gz: cbc5f2bfc1b33f186296fd9b6c0cc1b8d08fb1df
2
+ SHA256:
3
+ metadata.gz: 26bfe00fc2e06215356a2e050700f0d257e56401249c97487e26f58133f4ea0e
4
+ data.tar.gz: 5e9ba6def76cf0f0aa77130db602929da9725f1483508e244557e90e8bd22892
5
5
  SHA512:
6
- metadata.gz: ae7b28363deb33a59141481eba79eecebd530c7810e9b29a79e9b2a618ca4e5dd8fa6e0211d5ae3d167fe29bff286a175aac0094a8b353e8ae59f484e1caadeb
7
- data.tar.gz: bd3858caaa4d37e67bc586a18e1607a2d5c88f2385d9760fc59c9b15ad8fb403694f7a354248299928644acd4cec19bfbc4771f091fbdfd8c75348c6930b9ac0
6
+ metadata.gz: 3de11ae80f51e606826b3dbbdd92afa4a7443ec24ef595c616908adb23f2588908052f5db52d963164843aa0868c30747b54921e9fdac2b7deaede4b770413b3
7
+ data.tar.gz: 6032541f1dd51712f9755b9ca8ccfa25b145c670d319a3dde909917fb0b7447069600a3fdd7c8fce40e131733fa6495e7be420f7a77aa5f60a88c36c28301f3a
data/.rubocop.yml CHANGED
@@ -1,51 +1,54 @@
1
+ require:
2
+ - standard/cop/semantic_blocks
3
+ - rubocop-md
4
+
5
+ inherit_gem:
6
+ standard: config/base.yml
7
+
1
8
  AllCops:
2
- # Include gemspec and Rakefile
3
- Include:
4
- - 'lib/**/*.rb'
5
- - 'lib/**/*.rake'
6
- - 'spec/**/*.rb'
7
9
  Exclude:
8
- - 'bin/**/*'
9
- - 'spec/dummy/**/*'
10
+ - 'bin/*'
10
11
  - 'tmp/**/*'
12
+ - 'Gemfile'
13
+ - 'vendor/**/*'
14
+ - 'gemfiles/**/*'
11
15
  - 'bench/**/*'
12
16
  DisplayCopNames: true
13
- StyleGuideCopsOnly: false
17
+ TargetRubyVersion: 2.4
14
18
 
15
- Style/AccessorMethodName:
19
+ Standard/SemanticBlocks:
16
20
  Enabled: false
17
21
 
18
- Style/TrivialAccessors:
19
- Enabled: false
22
+ Style/FrozenStringLiteralComment:
23
+ Enabled: true
20
24
 
21
- Style/Documentation:
22
- Exclude:
23
- - 'spec/**/*.rb'
25
+ Style/TrailingCommaInArrayLiteral:
26
+ EnforcedStyleForMultiline: no_comma
24
27
 
25
- Style/StringLiterals:
26
- Enabled: false
28
+ Style/TrailingCommaInHashLiteral:
29
+ EnforcedStyleForMultiline: no_comma
27
30
 
28
- Style/SpaceInsideStringInterpolation:
29
- EnforcedStyle: no_space
31
+ Layout/AlignParameters:
32
+ EnforcedStyle: with_first_parameter
30
33
 
31
- Style/BlockDelimiters:
34
+ Lint/Void:
32
35
  Exclude:
33
- - 'spec/**/*.rb'
36
+ - '**/*.md'
34
37
 
35
- Lint/AmbiguousRegexpLiteral:
36
- Enabled: false
37
-
38
- Metrics/MethodLength:
38
+ # See https://github.com/rubocop-hq/rubocop/issues/4222
39
+ Lint/AmbiguousBlockAssociation:
39
40
  Exclude:
40
- - 'spec/**/*.rb'
41
+ - 'spec/**/*'
42
+ - '**/*.md'
41
43
 
42
- Metrics/LineLength:
43
- Max: 100
44
+ Lint/DuplicateMethods:
44
45
  Exclude:
45
- - 'spec/**/*.rb'
46
+ - '**/*.md'
46
47
 
47
- Rails/Date:
48
- Enabled: false
48
+ Naming/FileName:
49
+ Exclude:
50
+ - '**/*.md'
49
51
 
50
- Rails/TimeZone:
51
- Enabled: false
52
+ Layout/InitialIndentation:
53
+ Exclude:
54
+ - 'CHANGELOG.md'
data/.travis.yml CHANGED
@@ -12,6 +12,8 @@ matrix:
12
12
  include:
13
13
  - rvm: 2.4.1
14
14
  gemfile: gemfiles/rails5.gemfile
15
+ - rvm: 2.6.2
16
+ gemfile: gemfiles/rails6.gemfile
15
17
  - rvm: ruby-head
16
18
  gemfile: gemfiles/railsmaster.gemfile
17
19
  allow_failures:
data/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  ActiveRecord extension which adds typecasting to store accessors.
6
6
 
7
- Compatible with Rails 4.2 and Rails 5.
7
+ Compatible with Rails 4.2 and Rails 5+.
8
8
 
9
9
  <a href="https://evilmartians.com/">
10
10
  <img src="https://evilmartians.com/badges/sponsored-by-evil-martians.svg" alt="Sponsored by Evil Martians" width="236" height="54"></a>
@@ -14,11 +14,11 @@ Compatible with Rails 4.2 and Rails 5.
14
14
  In your Gemfile:
15
15
 
16
16
  ```ruby
17
- # for Rails 5
18
- gem "store_attribute", "~>0.5.0"
17
+ # for Rails 5+ (6 is supported)
18
+ gem "store_attribute", "~> 0.5.0"
19
19
 
20
20
  # for Rails 4.2
21
- gem "store_attribute", "~>0.4.0"
21
+ gem "store_attribute", "~> 0.4.0"
22
22
  ```
23
23
 
24
24
  ### Usage
@@ -26,14 +26,14 @@ gem "store_attribute", "~>0.4.0"
26
26
  You can use `store_attribute` method to add additional accessors with a type to an existing store on a model.
27
27
 
28
28
  ```ruby
29
- store_attribute(store_name, name, type, options = {})
29
+ store_attribute(store_name, name, type, options)
30
30
  ```
31
31
 
32
32
  Where:
33
33
  - `store_name` The name of the store.
34
34
  - `name` The name of the accessor to the store.
35
35
  - `type` A symbol such as `:string` or `:integer`, or a type object to be used for the accessor.
36
- - `options` A hash of cast type options such as `precision`, `limit`, `scale`.
36
+ - `options` (optional) A hash of cast type options such as `precision`, `limit`, `scale`.
37
37
 
38
38
  Type casting occurs every time you write data through accessor or update store itself
39
39
  and when object is loaded from database.
@@ -49,10 +49,10 @@ class MegaUser < User
49
49
  store_attribute :settings, :active, :boolean
50
50
  end
51
51
 
52
- u = MegaUser.new(active: false, login_at: '2015-01-01 00:01', ratio: "63.4608")
52
+ u = MegaUser.new(active: false, login_at: "2015-01-01 00:01", ratio: "63.4608")
53
53
 
54
54
  u.login_at.is_a?(DateTime) # => true
55
- u.login_at = DateTime.new(2015,1,1,11,0,0)
55
+ u.login_at = DateTime.new(2015, 1, 1, 11, 0, 0)
56
56
  u.ratio # => 63
57
57
  u.active # => false
58
58
  # And we also have a predicate method
@@ -60,17 +60,17 @@ u.active? # => false
60
60
  u.reload
61
61
 
62
62
  # After loading record from db store contains casted data
63
- u.settings['login_at'] == DateTime.new(2015,1,1,11,0,0) # => true
63
+ u.settings["login_at"] == DateTime.new(2015, 1, 1, 11, 0, 0) # => true
64
64
 
65
65
  # If you update store explicitly then the value returned
66
66
  # by accessor isn't type casted
67
- u.settings['ration'] = "3.141592653"
67
+ u.settings["ratio"] = "3.141592653"
68
68
  u.ratio # => "3.141592653"
69
69
 
70
70
  # On the other hand, writing through accessor set correct data within store
71
71
  u.ratio = "3.141592653"
72
72
  u.ratio # => 3
73
- u.settings['ratio'] # => 3
73
+ u.settings["ratio"] # => 3
74
74
  ```
75
75
 
76
76
  You can also specify type using usual `store_accessor` method:
data/Rakefile CHANGED
@@ -1,6 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+ require "rubocop/rake_task"
2
6
 
3
- require 'rspec/core/rake_task'
4
7
  RSpec::Core::RakeTask.new(:spec)
8
+ RuboCop::RakeTask.new
5
9
 
6
- task :default => :spec
10
+ task default: [:rubocop, :spec]
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rails', '6.0.0.beta3'
4
+
5
+ gemspec path: '..'
@@ -1,6 +1,5 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'arel', github: 'rails/arel'
4
3
  gem 'rails', github: 'rails/rails'
5
4
 
6
5
  gemspec path: '..'
@@ -1,2 +1,4 @@
1
- require 'store_attribute/version'
2
- require 'store_attribute/active_record'
1
+ # frozen_string_literal: true
2
+
3
+ require "store_attribute/version"
4
+ require "store_attribute/active_record"
@@ -1 +1,3 @@
1
- require 'store_attribute/active_record/store'
1
+ # frozen_string_literal: true
2
+
3
+ require "store_attribute/active_record/store"
@@ -1,5 +1,7 @@
1
- require 'active_record/store'
2
- require 'store_attribute/active_record/type/typed_store'
1
+ # frozen_string_literal: true
2
+
3
+ require "active_record/store"
4
+ require "store_attribute/active_record/type/typed_store"
3
5
 
4
6
  module ActiveRecord
5
7
  module Store
@@ -26,6 +28,7 @@ module ActiveRecord
26
28
  _orig_store(store_name, options)
27
29
  store_accessor(store_name, *accessors) if accessors
28
30
  end
31
+
29
32
  # Adds additional accessors to an existing store on this model.
30
33
  #
31
34
  # +store_name+ The name of the store.
@@ -1,4 +1,6 @@
1
- require 'active_record/type'
1
+ # frozen_string_literal: true
2
+
3
+ require "active_record/type"
2
4
 
3
5
  module ActiveRecord
4
6
  module Type # :nodoc:
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module StoreAttribute # :nodoc:
2
- VERSION = "0.5.2".freeze
4
+ VERSION = "0.5.3"
3
5
  end
@@ -1,11 +1,13 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
2
4
 
3
5
  describe StoreAttribute do
4
6
  before do
5
7
  @connection = ActiveRecord::Base.connection
6
8
 
7
9
  @connection.transaction do
8
- @connection.create_table('users') do |t|
10
+ @connection.create_table("users") do |t|
9
11
  t.jsonb :jparams, default: {}, null: false
10
12
  t.text :custom
11
13
  t.hstore :hdata, default: {}, null: false
@@ -16,23 +18,23 @@ describe StoreAttribute do
16
18
  end
17
19
 
18
20
  after do
19
- @connection.drop_table 'users', if_exists: true
21
+ @connection.drop_table "users", if_exists: true
20
22
  end
21
23
 
22
24
  let(:time) { DateTime.new(2015, 2, 14, 17, 0, 0) }
23
- let(:time_str) { '2015-02-14 17:00' }
24
- let(:time_str_utc) { '2015-02-14 17:00:00 UTC' }
25
+ let(:time_str) { "2015-02-14 17:00" }
26
+ let(:time_str_utc) { "2015-02-14 17:00:00 UTC" }
25
27
 
26
28
  context "hstore" do
27
29
  it "typecasts on build" do
28
- user = User.new(visible: 't', login_at: time_str)
30
+ user = User.new(visible: "t", login_at: time_str)
29
31
  expect(user.visible).to eq true
30
32
  expect(user).to be_visible
31
33
  expect(user.login_at).to eq time
32
34
  end
33
35
 
34
36
  it "typecasts on reload" do
35
- user = User.new(visible: 't', login_at: time_str)
37
+ user = User.new(visible: "t", login_at: time_str)
36
38
  user.save!
37
39
  user = User.find(user.id)
38
40
 
@@ -54,8 +56,8 @@ describe StoreAttribute do
54
56
  expect(user.login_at).to eq time
55
57
 
56
58
  ron = RawUser.find(user.id)
57
- expect(ron.hdata['visible']).to eq 'false'
58
- expect(ron.hdata['login_at']).to eq time_str_utc
59
+ expect(ron.hdata["visible"]).to eq "false"
60
+ expect(ron.hdata["login_at"]).to eq time_str_utc
59
61
  end
60
62
 
61
63
  it "handles options" do
@@ -63,8 +65,8 @@ describe StoreAttribute do
63
65
  end
64
66
 
65
67
  it "YAML roundtrip" do
66
- user = User.create!(visible: '0', login_at: time_str)
67
- dumped = YAML.load(YAML.dump(user))
68
+ user = User.create!(visible: "0", login_at: time_str)
69
+ dumped = YAML.load(YAML.dump(user)) # rubocop:disable Security/YAMLLoad
68
70
 
69
71
  expect(dumped.visible).to be false
70
72
  expect(dumped.login_at).to eq time
@@ -74,26 +76,26 @@ describe StoreAttribute do
74
76
  context "jsonb" do
75
77
  it "typecasts on build" do
76
78
  jamie = User.new(
77
- active: 'true',
79
+ active: "true",
78
80
  salary: 3.1999,
79
- birthday: '2000-01-01'
81
+ birthday: "2000-01-01"
80
82
  )
81
83
  expect(jamie).to be_active
82
84
  expect(jamie.salary).to eq 3
83
85
  expect(jamie.birthday).to eq Date.new(2000, 1, 1)
84
- expect(jamie.jparams['birthday']).to eq Date.new(2000, 1, 1)
85
- expect(jamie.jparams['active']).to eq true
86
+ expect(jamie.jparams["birthday"]).to eq Date.new(2000, 1, 1)
87
+ expect(jamie.jparams["active"]).to eq true
86
88
  end
87
89
 
88
90
  it "typecasts on reload" do
89
- jamie = User.create!(jparams: { 'active' => '1', 'birthday' => '01/01/2000', 'salary' => '3.14' })
91
+ jamie = User.create!(jparams: {"active" => "1", "birthday" => "01/01/2000", "salary" => "3.14"})
90
92
  jamie = User.find(jamie.id)
91
93
 
92
94
  expect(jamie).to be_active
93
95
  expect(jamie.salary).to eq 3
94
96
  expect(jamie.birthday).to eq Date.new(2000, 1, 1)
95
- expect(jamie.jparams['birthday']).to eq Date.new(2000, 1, 1)
96
- expect(jamie.jparams['active']).to eq true
97
+ expect(jamie.jparams["birthday"]).to eq Date.new(2000, 1, 1)
98
+ expect(jamie.jparams["active"]).to eq true
97
99
  end
98
100
 
99
101
  it "works with accessors" do
@@ -101,9 +103,9 @@ describe StoreAttribute do
101
103
  john.active = 1
102
104
 
103
105
  expect(john).to be_active
104
- expect(john.jparams['active']).to eq true
106
+ expect(john.jparams["active"]).to eq true
105
107
 
106
- john.jparams = { active: 'true', salary: '123.123', birthday: '01/01/2012' }
108
+ john.jparams = {active: "true", salary: "123.123", birthday: "01/01/2012"}
107
109
  expect(john).to be_active
108
110
  expect(john.birthday).to eq Date.new(2012, 1, 1)
109
111
  expect(john.salary).to eq 123
@@ -111,9 +113,9 @@ describe StoreAttribute do
111
113
  john.save!
112
114
 
113
115
  ron = RawUser.find(john.id)
114
- expect(ron.jparams['active']).to eq true
115
- expect(ron.jparams['birthday']).to eq '2012-01-01'
116
- expect(ron.jparams['salary']).to eq 123
116
+ expect(ron.jparams["active"]).to eq true
117
+ expect(ron.jparams["birthday"]).to eq "2012-01-01"
118
+ expect(ron.jparams["salary"]).to eq 123
117
119
  end
118
120
 
119
121
  it "re-typecast old data" do
@@ -127,8 +129,8 @@ describe StoreAttribute do
127
129
  jamie.save!
128
130
 
129
131
  ron = RawUser.find(jamie.id)
130
- expect(ron.jparams['active']).to eq true
131
- expect(ron.jparams['salary']).to eq 12
132
+ expect(ron.jparams["active"]).to eq true
133
+ expect(ron.jparams["salary"]).to eq 12
132
134
  end
133
135
  end
134
136
 
@@ -139,7 +141,7 @@ describe StoreAttribute do
139
141
  end
140
142
 
141
143
  it "typecasts on reload" do
142
- jamie = User.create!(custom: { price: '$12' })
144
+ jamie = User.create!(custom: {price: "$12"})
143
145
  expect(jamie.reload.price).to eq 1200
144
146
 
145
147
  jamie = User.find(jamie.id)
@@ -150,22 +152,22 @@ describe StoreAttribute do
150
152
 
151
153
  context "store subtype" do
152
154
  it "typecasts on build" do
153
- user = User.new(inner_json: { x: 1 })
154
- expect(user.inner_json).to eq('x' => 1)
155
+ user = User.new(inner_json: {x: 1})
156
+ expect(user.inner_json).to eq("x" => 1)
155
157
  end
156
158
 
157
159
  it "typecasts on update" do
158
160
  user = User.new
159
- user.update!(inner_json: { x: 1 })
160
- expect(user.inner_json).to eq('x' => 1)
161
+ user.update!(inner_json: {x: 1})
162
+ expect(user.inner_json).to eq("x" => 1)
161
163
 
162
- expect(user.reload.inner_json).to eq('x' => 1)
164
+ expect(user.reload.inner_json).to eq("x" => 1)
163
165
  end
164
166
 
165
167
  it "typecasts on reload" do
166
- jamie = User.create!(inner_json: { x: 1 })
168
+ jamie = User.create!(inner_json: {x: 1})
167
169
  jamie = User.find(jamie.id)
168
- expect(jamie.inner_json).to eq('x' => 1)
170
+ expect(jamie.inner_json).to eq("x" => 1)
169
171
  end
170
172
  end
171
173
  end
data/spec/spec_helper.rb CHANGED
@@ -1,28 +1,30 @@
1
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
1
+ # frozen_string_literal: true
2
+
3
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "..", "lib"))
2
4
  $LOAD_PATH.unshift(File.dirname(__FILE__))
3
5
 
4
- if ENV['COVER']
5
- require 'simplecov'
6
- SimpleCov.root File.join(File.dirname(__FILE__), '..')
6
+ if ENV["COVER"]
7
+ require "simplecov"
8
+ SimpleCov.root File.join(File.dirname(__FILE__), "..")
7
9
  SimpleCov.start
8
10
  end
9
11
 
10
- require 'rspec'
11
- require 'pry-byebug'
12
- require 'active_record'
13
- require 'pg'
14
- require 'store_attribute'
12
+ require "rspec"
13
+ require "pry-byebug"
14
+ require "active_record"
15
+ require "pg"
16
+ require "store_attribute"
15
17
 
16
18
  RAILS_5_1 = ActiveRecord.version.release >= Gem::Version.new("5.1.0")
17
19
 
18
20
  ActiveRecord::Base.establish_connection(
19
- adapter: 'postgresql',
20
- database: 'store_attribute_test'
21
+ adapter: "postgresql",
22
+ database: "store_attribute_test"
21
23
  )
22
24
  connection = ActiveRecord::Base.connection
23
25
 
24
- unless connection.extension_enabled?('hstore')
25
- connection.enable_extension 'hstore'
26
+ unless connection.extension_enabled?("hstore")
27
+ connection.enable_extension "hstore"
26
28
  connection.commit_db_transaction
27
29
  end
28
30
 
@@ -38,6 +40,6 @@ RSpec.configure do |config|
38
40
  config.example_status_persistence_file_path = "tmp/rspec_examples.txt"
39
41
 
40
42
  if config.files_to_run.one?
41
- config.default_formatter = 'doc'
43
+ config.default_formatter = "doc"
42
44
  end
43
45
  end
@@ -1,4 +1,6 @@
1
- require 'spec_helper'
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
2
4
 
3
5
  describe ActiveRecord::Type::TypedStore do
4
6
  let(:json_type) { ActiveRecord::Type::Serialized.new(ActiveRecord::Type::Text.new, ActiveRecord::Coders::JSON) }
@@ -9,46 +11,46 @@ describe ActiveRecord::Type::TypedStore do
9
11
  describe "#cast" do
10
12
  it "without key types", :aggregate_failures do
11
13
  expect(subject.cast([1, 2])).to eq [1, 2]
12
- expect(subject.cast('a' => 'b')).to eq('a' => 'b')
14
+ expect(subject.cast("a" => "b")).to eq("a" => "b")
13
15
  end
14
16
 
15
17
  it "with type keys" do
16
- subject.add_typed_key('date', :date)
18
+ subject.add_typed_key("date", :date)
17
19
 
18
20
  date = ::Date.new(2016, 6, 22)
19
- expect(subject.cast(date: '2016-06-22')).to eq('date' => date)
21
+ expect(subject.cast(date: "2016-06-22")).to eq("date" => date)
20
22
  end
21
23
  end
22
24
 
23
25
  describe "#deserialize" do
24
26
  it "without key types", :aggregate_failures do
25
- expect(subject.deserialize('[1,2]')).to eq [1, 2]
26
- expect(subject.deserialize('{"a":"b"}')).to eq('a' => 'b')
27
+ expect(subject.deserialize("[1,2]")).to eq [1, 2]
28
+ expect(subject.deserialize('{"a":"b"}')).to eq("a" => "b")
27
29
  end
28
30
 
29
31
  it "with type keys" do
30
- subject.add_typed_key('date', :date)
32
+ subject.add_typed_key("date", :date)
31
33
 
32
34
  date = ::Date.new(2016, 6, 22)
33
- expect(subject.deserialize('{"date":"2016-06-22"}')).to eq('date' => date)
35
+ expect(subject.deserialize('{"date":"2016-06-22"}')).to eq("date" => date)
34
36
  end
35
37
  end
36
38
 
37
39
  describe "#serialize" do
38
40
  it "without key types", :aggregate_failures do
39
- expect(subject.serialize([1, 2])).to eq '[1,2]'
40
- expect(subject.serialize('a' => 'b')).to eq '{"a":"b"}'
41
+ expect(subject.serialize([1, 2])).to eq "[1,2]"
42
+ expect(subject.serialize("a" => "b")).to eq '{"a":"b"}'
41
43
  end
42
44
 
43
45
  it "with type keys" do
44
- subject.add_typed_key('date', :date)
46
+ subject.add_typed_key("date", :date)
45
47
 
46
48
  date = ::Date.new(2016, 6, 22)
47
49
  expect(subject.serialize(date: date)).to eq '{"date":"2016-06-22"}'
48
50
  end
49
51
 
50
52
  it "with type key with option" do
51
- subject.add_typed_key('val', :integer, limit: 1)
53
+ subject.add_typed_key("val", :integer, limit: 1)
52
54
 
53
55
  expect { subject.serialize(val: 1024) }.to raise_error(RangeError)
54
56
  end
@@ -56,13 +58,13 @@ describe ActiveRecord::Type::TypedStore do
56
58
 
57
59
  describe ".create_from_type" do
58
60
  it "creates with valid types", :aggregate_failures do
59
- type = described_class.create_from_type(json_type, 'date', :date)
60
- new_type = described_class.create_from_type(type, 'val', :integer)
61
+ type = described_class.create_from_type(json_type, "date", :date)
62
+ new_type = described_class.create_from_type(type, "val", :integer)
61
63
 
62
64
  date = ::Date.new(2016, 6, 22)
63
65
 
64
- expect(type.cast(date: '2016-06-22', val: '1.2')).to eq('date' => date, 'val' => '1.2')
65
- expect(new_type.cast(date: '2016-06-22', val: '1.2')).to eq('date' => date, 'val' => 1)
66
+ expect(type.cast(date: "2016-06-22", val: "1.2")).to eq("date" => date, "val" => "1.2")
67
+ expect(new_type.cast(date: "2016-06-22", val: "1.2")).to eq("date" => date, "val" => 1)
66
68
  end
67
69
  end
68
70
  end
@@ -73,8 +75,8 @@ describe ActiveRecord::Type::TypedStore do
73
75
  ActiveRecord::Type::Serialized.new(
74
76
  ActiveRecord::Type::Text.new,
75
77
  ActiveRecord::Store::IndifferentCoder.new(
76
- 'test',
77
- ActiveRecord::Coders::YAMLColumn.new('test', Hash)
78
+ "test",
79
+ ActiveRecord::Coders::YAMLColumn.new("test", Hash)
78
80
  )
79
81
  )
80
82
  end
@@ -92,16 +94,16 @@ describe ActiveRecord::Type::TypedStore do
92
94
  let(:subject) { described_class.new(yaml_type) }
93
95
 
94
96
  it "works", :aggregate_failures do
95
- subject.add_typed_key('date', :date)
97
+ subject.add_typed_key("date", :date)
96
98
 
97
99
  date = ::Date.new(2016, 6, 22)
98
100
 
99
- expect(subject.cast(date: '2016-06-22')).to eq('date' => date)
100
- expect(subject.cast('date' => '2016-06-22')).to eq('date' => date)
101
- expect(subject.deserialize("---\n:date: 2016-06-22\n")).to eq('date' => date)
102
- expect(subject.deserialize("---\ndate: 2016-06-22\n")).to eq('date' => date)
101
+ expect(subject.cast(date: "2016-06-22")).to eq("date" => date)
102
+ expect(subject.cast("date" => "2016-06-22")).to eq("date" => date)
103
+ expect(subject.deserialize("---\n:date: 2016-06-22\n")).to eq("date" => date)
104
+ expect(subject.deserialize("---\ndate: 2016-06-22\n")).to eq("date" => date)
103
105
  expect(subject.serialize(date: date)).to eq "--- !ruby/hash:ActiveSupport::HashWithIndifferentAccess\ndate: 2016-06-22\n"
104
- expect(subject.serialize('date' => date)).to eq "--- !ruby/hash:ActiveSupport::HashWithIndifferentAccess\ndate: 2016-06-22\n"
106
+ expect(subject.serialize("date" => date)).to eq "--- !ruby/hash:ActiveSupport::HashWithIndifferentAccess\ndate: 2016-06-22\n"
105
107
  end
106
108
  end
107
109
  end
@@ -1,7 +1,9 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class MoneyType < ActiveRecord::Type::Integer
2
4
  def cast(value)
3
- if !value.is_a?(Numeric) && value.include?('$')
4
- price_in_dollars = value.delete('$').to_f
5
+ if !value.is_a?(Numeric) && value.include?("$")
6
+ price_in_dollars = value.delete("$").to_f
5
7
  super(price_in_dollars * 100)
6
8
  else
7
9
  super
data/spec/support/user.rb CHANGED
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class RawUser < ActiveRecord::Base
2
- self.table_name = 'users'
4
+ self.table_name = "users"
3
5
  end
4
6
 
5
7
  class User < ActiveRecord::Base
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  $:.push File.expand_path("../lib", __FILE__)
2
4
 
3
5
  # Maintain your gem's version:
@@ -17,11 +19,16 @@ Gem::Specification.new do |s|
17
19
  s.files = `git ls-files`.split($/)
18
20
  s.require_paths = ["lib"]
19
21
 
20
- s.add_runtime_dependency "activerecord", "~>5.0"
22
+ s.required_ruby_version = ">= 2.4.0"
23
+
24
+ s.add_runtime_dependency "activerecord", ">= 5.0"
21
25
 
22
- s.add_development_dependency "pg", "~>0.18"
23
- s.add_development_dependency "rake", "~> 10.1"
26
+ s.add_development_dependency "pg", ">= 0.18"
27
+ s.add_development_dependency "rake", ">= 10.1"
24
28
  s.add_development_dependency "simplecov", ">= 0.3.8"
25
29
  s.add_development_dependency "pry-byebug"
26
- s.add_development_dependency "rspec", "~> 3.5.0"
30
+ s.add_development_dependency "rubocop", "~> 0.65.0"
31
+ s.add_development_dependency "rubocop-md", "~> 0.2"
32
+ s.add_development_dependency "standard", "~> 0.0.36"
33
+ s.add_development_dependency "rspec", ">= 3.5.0"
27
34
  end
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: store_attribute
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - palkan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-26 00:00:00.000000000 Z
11
+ date: 2019-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '5.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
26
  version: '5.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: pg
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - "~>"
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0.18'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - "~>"
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0.18'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rake
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - "~>"
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '10.1'
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
54
  version: '10.1'
55
55
  - !ruby/object:Gem::Dependency
@@ -81,17 +81,59 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: rspec
84
+ name: rubocop
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: 3.5.0
89
+ version: 0.65.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.65.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: rubocop-md
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.2'
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
108
  - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.2'
111
+ - !ruby/object:Gem::Dependency
112
+ name: standard
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.0.36
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.0.36
125
+ - !ruby/object:Gem::Dependency
126
+ name: rspec
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: 3.5.0
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
95
137
  - !ruby/object:Gem::Version
96
138
  version: 3.5.0
97
139
  description: ActiveRecord extension which adds typecasting to store accessors
@@ -114,7 +156,8 @@ files:
114
156
  - bin/console
115
157
  - bin/setup
116
158
  - gemfiles/rails5.gemfile
117
- - gemfiles/railsmaster.rb
159
+ - gemfiles/rails6.gemfile
160
+ - gemfiles/railsmaster.gemfile
118
161
  - lib/store_attribute.rb
119
162
  - lib/store_attribute/active_record.rb
120
163
  - lib/store_attribute/active_record/store.rb
@@ -138,15 +181,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
138
181
  requirements:
139
182
  - - ">="
140
183
  - !ruby/object:Gem::Version
141
- version: '0'
184
+ version: 2.4.0
142
185
  required_rubygems_version: !ruby/object:Gem::Requirement
143
186
  requirements:
144
187
  - - ">="
145
188
  - !ruby/object:Gem::Version
146
189
  version: '0'
147
190
  requirements: []
148
- rubyforge_project:
149
- rubygems_version: 2.6.13
191
+ rubygems_version: 3.0.2
150
192
  signing_key:
151
193
  specification_version: 4
152
194
  summary: ActiveRecord extension which adds typecasting to store accessors