frozen_record 0.19.5 → 0.20.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
2
  SHA256:
3
- metadata.gz: 9a5344be7378de1fb30f456b1a44b455dce2cec5d5db848058e8f3a137eb0ae7
4
- data.tar.gz: a8ed04973c5c1edd7600d180c8fc827bdb9312ec0a7e602d408373eb86ff2749
3
+ metadata.gz: 8f755e0e4bce41d9687a8b29eedad265593319156b8d086e81c355d6cdbf15dd
4
+ data.tar.gz: bb63057b31078536220168e6430ee0099cad053bdfd35a1a2567c054fe26e780
5
5
  SHA512:
6
- metadata.gz: 8ec04aa72dfbee08525e8f4d6bea2413e7c84142f0f3bb8f6b8dc57538be10dcedfb07a7fd12f0c2992f292fb91ea492c8b6a21ab431470de551647b218b5dc2
7
- data.tar.gz: 03ac7a0e64dd6caa6f519611096130c4bb33ac77467792b4c48d9a368f31abb91a22ed4a0d370e94e76b1a63b91aaec06b3bee1d38fcc9761edc47ac4beabe16
6
+ metadata.gz: 22929e50f2c0eec95d863222171cf81ab52531396118259ff4107240d5ce7d9828f70198b133a126bedb0f11cea7858814ab1fdabbcf31e9840aaad23cb9c614
7
+ data.tar.gz: 43c61d4238b44945bcd94bea89864ba0c4a06d0b53669e9a27d00ae2ba27673817ef5104c710e341c0ed286d544195f3a7615bac306c6cc8424c5afd0453a921
@@ -20,6 +20,8 @@ Gem::Specification.new do |spec|
20
20
  spec.required_ruby_version = '>= 2.5'
21
21
 
22
22
  spec.add_runtime_dependency 'activemodel'
23
+ spec.add_runtime_dependency 'dedup'
24
+
23
25
  spec.add_development_dependency 'bundler'
24
26
  spec.add_development_dependency 'rake'
25
27
  spec.add_development_dependency 'rspec'
@@ -5,12 +5,13 @@ require 'set'
5
5
  require 'active_support/all'
6
6
  require 'active_model'
7
7
 
8
+ require 'dedup'
9
+
8
10
  require 'frozen_record/version'
9
11
  require 'frozen_record/scope'
10
12
  require 'frozen_record/index'
11
13
  require 'frozen_record/base'
12
14
  require 'frozen_record/compact'
13
- require 'frozen_record/deduplication'
14
15
 
15
16
  module FrozenRecord
16
17
  RecordNotFound = Class.new(StandardError)
@@ -52,7 +52,7 @@ module FrozenRecord
52
52
  alias_method :set_default_attributes, :default_attributes=
53
53
  private :set_default_attributes
54
54
  def default_attributes=(default_attributes)
55
- set_default_attributes(Deduplication.deep_deduplicate!(default_attributes.stringify_keys))
55
+ set_default_attributes(Dedup.deep_intern!(default_attributes.stringify_keys))
56
56
  end
57
57
 
58
58
  alias_method :set_primary_key, :primary_key=
@@ -147,7 +147,7 @@ module FrozenRecord
147
147
  @records ||= begin
148
148
  records = backend.load(file_path)
149
149
  records.each { |r| assign_defaults!(r) }
150
- records = Deduplication.deep_deduplicate!(records)
150
+ records = Dedup.deep_intern!(records)
151
151
  @attributes = list_attributes(records).freeze
152
152
  define_attribute_methods(@attributes.to_a)
153
153
  records = records.map { |r| load(r) }.freeze
@@ -14,7 +14,7 @@ module FrozenRecord
14
14
  @records ||= begin
15
15
  records = backend.load(file_path)
16
16
  records.each { |r| assign_defaults!(r) }
17
- records = Deduplication.deep_deduplicate!(records)
17
+ records = Dedup.deep_intern!(records)
18
18
  @attributes = list_attributes(records).freeze
19
19
  build_attributes_cache
20
20
  define_attribute_methods(@attributes.to_a)
@@ -67,7 +67,7 @@ module FrozenRecord
67
67
 
68
68
  def attributes=(attributes)
69
69
  self.class.attributes.each do |attr|
70
- instance_variable_set(self.class._attributes_cache[attr], Deduplication.deep_deduplicate!(attributes[attr]))
70
+ instance_variable_set(self.class._attributes_cache[attr], Dedup.deep_intern!(attributes[attr]))
71
71
  end
72
72
  end
73
73
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  module FrozenRecord
4
4
  class Scope
5
- BLACKLISTED_ARRAY_METHODS = [
5
+ DISALLOWED_ARRAY_METHODS = [
6
6
  :compact!, :flatten!, :reject!, :reverse!, :rotate!, :map!,
7
7
  :shuffle!, :slice!, :sort!, :sort_by!, :delete_if,
8
8
  :keep_if, :pop, :shift, :delete_at, :compact
@@ -233,7 +233,7 @@ module FrozenRecord
233
233
  end
234
234
 
235
235
  def array_delegable?(method)
236
- Array.method_defined?(method) && BLACKLISTED_ARRAY_METHODS.exclude?(method)
236
+ Array.method_defined?(method) && DISALLOWED_ARRAY_METHODS.exclude?(method)
237
237
  end
238
238
 
239
239
  def where!(criterias)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FrozenRecord
4
- VERSION = '0.19.5'
4
+ VERSION = '0.20.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: frozen_record
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.19.5
4
+ version: 0.20.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean Boussier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-08-19 00:00:00.000000000 Z
11
+ date: 2020-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: dedup
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -118,13 +132,11 @@ files:
118
132
  - lib/frozen_record/backends/yaml.rb
119
133
  - lib/frozen_record/base.rb
120
134
  - lib/frozen_record/compact.rb
121
- - lib/frozen_record/deduplication.rb
122
135
  - lib/frozen_record/index.rb
123
136
  - lib/frozen_record/railtie.rb
124
137
  - lib/frozen_record/scope.rb
125
138
  - lib/frozen_record/test_helper.rb
126
139
  - lib/frozen_record/version.rb
127
- - spec/deduplication_spec.rb
128
140
  - spec/fixtures/animals.json
129
141
  - spec/fixtures/cars.yml
130
142
  - spec/fixtures/countries.yml.erb
@@ -156,12 +168,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
156
168
  - !ruby/object:Gem::Version
157
169
  version: '0'
158
170
  requirements: []
159
- rubygems_version: 3.1.2
171
+ rubygems_version: 3.0.2
160
172
  signing_key:
161
173
  specification_version: 4
162
174
  summary: ActiveRecord like interface to read only access and query static YAML files
163
175
  test_files:
164
- - spec/deduplication_spec.rb
165
176
  - spec/fixtures/animals.json
166
177
  - spec/fixtures/cars.yml
167
178
  - spec/fixtures/countries.yml.erb
@@ -1,57 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'active_support/core_ext/object/duplicable'
4
-
5
- module FrozenRecord
6
- module Deduplication
7
- extend self
8
-
9
- # We deduplicate data in place because it is assumed it directly
10
- # comes from the parser, and won't be held by anyone.
11
- #
12
- # Frozen Hashes and Arrays are ignored because they are likely
13
- # the result of the use of YAML anchor. Meaning we already deduplicated
14
- # them.
15
- if RUBY_VERSION >= '2.7'
16
- def deep_deduplicate!(data)
17
- case data
18
- when Hash
19
- return data if data.frozen?
20
- data.transform_keys! { |k| deep_deduplicate!(k) }
21
- data.transform_values! { |v| deep_deduplicate!(v) }
22
- data.freeze
23
- when Array
24
- return data if data.frozen?
25
- data.map! { |d| deep_deduplicate!(d) }.freeze
26
- when String
27
- -data.freeze
28
- else
29
- data.duplicable? ? data.freeze : data
30
- end
31
- end
32
- else
33
- def deep_deduplicate!(data)
34
- case data
35
- when Hash
36
- return data if data.frozen?
37
- data.transform_keys! { |k| deep_deduplicate!(k) }
38
- data.transform_values! { |v| deep_deduplicate!(v) }
39
- data.freeze
40
- when Array
41
- return data if data.frozen?
42
- data.map! { |d| deep_deduplicate!(d) }.freeze
43
- when String
44
- # String#-@ doesn't deduplicate the string if it's tainted.
45
- # So in such case we need to untaint it first.
46
- if data.tainted?
47
- -(+data).untaint.freeze
48
- else
49
- -data.freeze
50
- end
51
- else
52
- data.duplicable? ? data.freeze : data
53
- end
54
- end
55
- end
56
- end
57
- end
@@ -1,31 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe 'deduplication' do
4
-
5
- it 'deduplicate string values' do
6
- pending("Strings can't be deduplicated before Ruby 2.5") if RUBY_VERSION < '2.5'
7
-
8
- records = [
9
- { 'name' => 'George'.dup },
10
- ]
11
-
12
- expect(records[0]['name']).to_not equal 'George'.freeze
13
- FrozenRecord::Deduplication.deep_deduplicate!(records)
14
- expect(records[0]['name']).to equal 'George'.freeze
15
- end
16
-
17
- it 'handles duplicated references' do
18
- # This simulates the YAML anchor behavior
19
- tags = { 'foo' => 'bar' }
20
- records = [
21
- { 'name' => 'George', 'tags' => tags },
22
- { 'name' => 'Peter', 'tags' => tags },
23
- ]
24
-
25
- expect(records[0]['tags']).to_not be_frozen
26
- FrozenRecord::Deduplication.deep_deduplicate!(records)
27
- expect(records[0]['tags']).to be_frozen
28
- expect(records[0]['tags']).to equal records[1]['tags']
29
- end
30
-
31
- end