frozen_record 0.26.1 → 0.26.2

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: 4e4a597e4419873da69776c887c5ef35c812f785493cd9597d3d3ced891578ab
4
- data.tar.gz: d46b86085ceeee261b39a281aab1c62a2551e872ad1f4696e8a7325b7cfa9a7a
3
+ metadata.gz: e162699e1ec4c32223be26afd36c1222bedeea90b8d0f26e05407641c9f01ccd
4
+ data.tar.gz: f4f6dcb51344bf99558e278a746e4ae5527355ed8771c7be26186af2cab630a1
5
5
  SHA512:
6
- metadata.gz: 8e68a5dfb1d888de4f6dc72bb42ffdc1c08af87229b7bd0dcf107d1da9b48ef5b948adea5652b132cb497a1a8c15b513aa7ba8beea7c863b06f19de14ae02865
7
- data.tar.gz: f787b5072efd3997fb41942c1d9b6014ee872d6faec12a4c5a77ef489a7039ed980987bbf4102ed7d9c5cd2b296e49c1bd6a25f578559969d200d875d6cdf877
6
+ metadata.gz: 594beed9888fc9379882815828f1d85a0941b143b03d177662fd02a8460867135003eeeb1391ad473f393c78f299c9e0c3ed45c9dcee88dee7bc7940ce3662c4
7
+ data.tar.gz: bcc049e4643b24bca1c98f8947a924c97f829a2a66798fbe798cbeba744d9934c0b81cbb2bb5c29f686d8d6af723f99299312d56e7e484524021c57613d02f4d
data/CHANGELOG.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # Unreleased
2
2
 
3
+ - Fix `Model.find_by` fastpath raising an error when called before records are loaded.
4
+
3
5
  # v0.26.1
4
6
 
5
7
  - Optimized single attribute lookup.
@@ -137,6 +137,7 @@ module FrozenRecord
137
137
  criterias.each do |attribute, value|
138
138
  attribute = attribute.to_s
139
139
  if index = index_definitions[attribute]
140
+ load_records
140
141
  return index.lookup(value).first
141
142
  end
142
143
  end
@@ -181,10 +182,15 @@ module FrozenRecord
181
182
  load_records
182
183
  end
183
184
 
185
+ def unload!
186
+ @records = nil
187
+ index_definitions.values.each(&:reset)
188
+ undefine_attribute_methods
189
+ end
190
+
184
191
  def load_records(force: false)
185
192
  if force || (auto_reloading && file_changed?)
186
- @records = nil
187
- undefine_attribute_methods
193
+ unload!
188
194
  end
189
195
 
190
196
  @records ||= begin
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module FrozenRecord
4
- VERSION = '0.26.1'
4
+ VERSION = '0.26.2'
5
5
  end
data/spec/scope_spec.rb CHANGED
@@ -101,7 +101,6 @@ describe 'querying' do
101
101
  country = Country.find_by_id(42)
102
102
  expect(country).to be_nil
103
103
  end
104
-
105
104
  end
106
105
 
107
106
  describe '.find_by' do
@@ -116,6 +115,11 @@ describe 'querying' do
116
115
  expect(country).to be_nil
117
116
  end
118
117
 
118
+ it 'load records' do
119
+ Country.unload!
120
+ country = Country.find_by(name: 'France')
121
+ expect(country.name).to be == 'France'
122
+ end
119
123
  end
120
124
 
121
125
  describe '.find_by!' do
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.26.1
4
+ version: 0.26.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean Boussier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-08-11 00:00:00.000000000 Z
11
+ date: 2022-08-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -124,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
124
124
  - !ruby/object:Gem::Version
125
125
  version: '0'
126
126
  requirements: []
127
- rubygems_version: 3.2.20
127
+ rubygems_version: 3.3.7
128
128
  signing_key:
129
129
  specification_version: 4
130
130
  summary: ActiveRecord like interface to read only access and query static YAML files