activerecord-typedstore 1.1.2 → 1.1.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: 32186c23b2155944fe8760d18cbfd9fa1091ba10
4
- data.tar.gz: 811f0a0dfd47754e463afe3c6d540443456e8397
2
+ SHA256:
3
+ metadata.gz: ab5f09b64721a41a7eae679a4ae848813504913d1d87815c035352da6b3134eb
4
+ data.tar.gz: bc9d48e95b48f9ad9d5b7e02f1edd9a1ce1004e8c93bfb6d18fc4d944d63c161
5
5
  SHA512:
6
- metadata.gz: abbf5d186254ff6052dcd07d11e8f4743eaa406086845511bd0ef2a5451e2b3e56ae3f5ba3e190bd6582d409985ce08fd33db61a52eee8d0cf415c7c0cad0c37
7
- data.tar.gz: ce93bc861633c8b1e1aecd0c23e398caa0688fd23577cb8da5398459927711905a9c72a07337ab34c42952e3e8e81fec0d827775e8eeddedbc6c3ff700bcff04
6
+ metadata.gz: bbd034206f96e1063bdb078417b685148346edeeb36968068bd54a2a8e95321ec56d5aa69b50851238607a862a01cba1a1770ac541e283eba12735c11dd84f5a
7
+ data.tar.gz: f04cdc9a39338b8b0fcc164da82f4b472acbf7e59543e6f8ebf5b51300e5bf55f4cb01d602a7dfc083833fef38069ed468049a49be3b6ff45b84dac7e0f86952
data/.travis.yml CHANGED
@@ -1,12 +1,12 @@
1
1
  language: ruby
2
2
 
3
3
  rvm:
4
- - 2.1
5
- - 2.2.3
6
- - 2.3.0
4
+ - 2.3.5
5
+ - 2.4.2
7
6
  gemfile:
8
7
  - gemfiles/Gemfile.ar-4.2
9
8
  - gemfiles/Gemfile.ar-5.0
9
+ - gemfiles/Gemfile.ar-5.1
10
10
 
11
11
  env:
12
12
  - TIMEZONE_AWARE=1 POSTGRES=1 MYSQL=1
@@ -21,8 +21,3 @@ cache: bundler
21
21
  before_script:
22
22
  - mysql -e 'create database typed_store_test;'
23
23
  - psql -c 'create database typed_store_test;' -U postgres
24
-
25
- matrix:
26
- exclude:
27
- - rvm: 2.1
28
- gemfile: gemfiles/Gemfile.ar-5.0
data/Rakefile CHANGED
@@ -21,7 +21,7 @@ end
21
21
 
22
22
  namespace :spec do
23
23
  task :all do
24
- %w(3.2 4.0 edge).each do |ar_version|
24
+ %w(4.2 5.0 5.1).each do |ar_version|
25
25
  [1, 0].each do |timezone_aware|
26
26
  command = %W{
27
27
  BUNDLE_GEMFILE=gemfiles/Gemfile.ar-#{ar_version}
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ['lib']
20
20
 
21
- spec.add_dependency 'activerecord', '>= 4.2', '< 5.2'
21
+ spec.add_dependency 'activerecord', '>= 4.2', '< 5.3'
22
22
 
23
23
  spec.add_development_dependency 'bundler', '~> 1.3'
24
24
  spec.add_development_dependency 'rake', '~> 10'
@@ -1,11 +1,11 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- gem 'activerecord', '~> 3.2.15'
3
+ gem 'activerecord', ['>= 5.2.0.beta1', '< 5.3']
4
4
  gem 'bundler', '~> 1.3'
5
5
  gem 'rake'
6
6
  gem 'rspec'
7
7
  gem 'sqlite3'
8
8
  gem 'pg', '~> 0.11'
9
- gem 'mysql2', '~> 0.3.10'
9
+ gem 'mysql2', ['>= 0.3.13', '< 0.5']
10
10
  gem 'database_cleaner'
11
11
  gem 'coveralls', require: false
@@ -8,19 +8,17 @@ module ActiveRecord::TypedStore
8
8
 
9
9
  included do
10
10
  class_attribute :typed_stores
11
+ self.typed_stores = {}
11
12
  end
12
13
 
13
14
  module ClassMethods
14
15
  def store_accessors
15
- return [] unless typed_stores
16
- typed_stores.values.map(&:accessors).flatten
16
+ typed_stores.each_value.flat_map(&:accessors)
17
17
  end
18
18
 
19
19
  def typed_store(store_attribute, options={}, &block)
20
20
  dsl = DSL.new(store_attribute, options, &block)
21
- self.typed_stores ||= {}
22
- self.typed_stores = typed_stores.deep_dup
23
- self.typed_stores[store_attribute] = dsl
21
+ self.typed_stores = self.typed_stores.merge(store_attribute => dsl)
24
22
 
25
23
  typed_klass = TypedHash.create(dsl.fields.values)
26
24
  const_set("#{store_attribute}_hash".camelize, typed_klass)
@@ -29,11 +27,26 @@ module ActiveRecord::TypedStore
29
27
  Type.new(typed_klass, dsl.coder, subtype)
30
28
  end
31
29
  store_accessor(store_attribute, dsl.accessors)
30
+
31
+ dsl.accessors.each do |accessor_name|
32
+ define_method("#{accessor_name}_changed?") do
33
+ send("#{store_attribute}_changed?") &&
34
+ send(store_attribute)[accessor_name] != send("#{store_attribute}_was")[accessor_name]
35
+ end
36
+
37
+ define_method("#{accessor_name}_was") do
38
+ send("#{store_attribute}_was")[accessor_name]
39
+ end
40
+
41
+ define_method("restore_#{accessor_name}!") do
42
+ send("#{accessor_name}=", send("#{accessor_name}_was"))
43
+ end
44
+ end
32
45
  end
33
46
 
34
47
  def define_attribute_methods
35
48
  super
36
- define_typed_store_attribute_methods if typed_stores
49
+ define_typed_store_attribute_methods
37
50
  end
38
51
 
39
52
  def undefine_attribute_methods # :nodoc:
@@ -57,6 +70,16 @@ module ActiveRecord::TypedStore
57
70
  end
58
71
  end
59
72
 
73
+ def changes
74
+ changes = super
75
+ self.class.store_accessors.each do |attr|
76
+ if send("#{attr}_changed?")
77
+ changes[attr] = [send("#{attr}_was"), send(attr)]
78
+ end
79
+ end
80
+ changes
81
+ end
82
+
60
83
  def clear_attribute_change(attr_name)
61
84
  return if self.class.store_accessors.include?(normalize_attribute(attr_name))
62
85
  super
@@ -69,16 +92,6 @@ module ActiveRecord::TypedStore
69
92
  super
70
93
  end
71
94
 
72
- def write_store_attribute(store_attribute, key, value)
73
- if typed_stores && typed_stores[store_attribute]
74
- prev_value = read_store_attribute(store_attribute, key)
75
- new_value = typed_stores[store_attribute].fields[key].cast(value)
76
- attribute_will_change!(key.to_s) if new_value != prev_value
77
- end
78
-
79
- super
80
- end
81
-
82
95
  def query_attribute(attr_name)
83
96
  if self.class.store_accessors.include?(attr_name.to_sym)
84
97
  value = public_send(attr_name)
@@ -1,5 +1,5 @@
1
1
  module ActiveRecord
2
2
  module TypedStore
3
- VERSION = '1.1.2'
3
+ VERSION = '1.1.3'
4
4
  end
5
5
  end
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: 1.1.2
4
+ version: 1.1.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: 2017-11-27 00:00:00.000000000 Z
11
+ date: 2018-02-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '4.2'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '5.2'
22
+ version: '5.3'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '4.2'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '5.2'
32
+ version: '5.3'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: bundler
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -157,12 +157,10 @@ files:
157
157
  - README.md
158
158
  - Rakefile
159
159
  - activerecord-typedstore.gemspec
160
- - gemfiles/Gemfile.ar-3.2
161
- - gemfiles/Gemfile.ar-4.0
162
- - gemfiles/Gemfile.ar-4.1
163
160
  - gemfiles/Gemfile.ar-4.2
164
161
  - gemfiles/Gemfile.ar-5.0
165
162
  - gemfiles/Gemfile.ar-5.1
163
+ - gemfiles/Gemfile.ar-5.2
166
164
  - lib/active_record/typed_store.rb
167
165
  - lib/active_record/typed_store/dsl.rb
168
166
  - lib/active_record/typed_store/extension.rb
@@ -196,7 +194,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
196
194
  version: '0'
197
195
  requirements: []
198
196
  rubyforge_project:
199
- rubygems_version: 2.5.1
197
+ rubygems_version: 2.7.3
200
198
  signing_key:
201
199
  specification_version: 4
202
200
  summary: Add type casting and full method attributes support to АctiveRecord store
@@ -1,11 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'activerecord', '~> 4.0.0'
4
- gem 'bundler', '~> 1.3'
5
- gem 'rake'
6
- gem 'rspec'
7
- gem 'sqlite3'
8
- gem 'pg', '~> 0.11'
9
- gem 'mysql2', '~> 0.3.10'
10
- gem 'database_cleaner'
11
- gem 'coveralls', require: false
@@ -1,11 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- gem 'activerecord', '~> 4.1.0'
4
- gem 'bundler', '~> 1.3'
5
- gem 'rake'
6
- gem 'rspec'
7
- gem 'sqlite3'
8
- gem 'pg', '~> 0.11'
9
- gem 'mysql2', '~> 0.3.13'
10
- gem 'database_cleaner'
11
- gem 'coveralls', require: false