frozen_record 0.7.0 → 0.7.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fdb7686678220892ee4d076e0dd12678eb3b5bb6
4
- data.tar.gz: 1cb91679f2c40a42ff635b3ae92a28169641b4f8
3
+ metadata.gz: 275b29fe63b81841f976203d89605b9a9a5c6289
4
+ data.tar.gz: 4243044175796dec9f623da8e9e1a589eef85994
5
5
  SHA512:
6
- metadata.gz: a01bb54dc54ca88f5acb7b85c4739002e6e7918345f55f7bd45cd4f97350e1d721c9497f981b909ec57ae217353a881f4c01c36e8f66921353dfc099fa60d760
7
- data.tar.gz: de01bdbbb0c09f3d8720711a540c7a7686ba2c7f55d64ddd39296f9e3ba8501da3f84b81259f22b26f30f2fe840e75c80e2610788abe39f98d1634a129cdeafa
6
+ metadata.gz: f4de4b60e0cee0988b3aaae4fab620958e034d2d22057cf7d4c896b3ec879295c0d3340576e9a388cd6b5e77d3bf581ed08eb3542cc6d51a5a0ad5cd79a254c7
7
+ data.tar.gz: 531c13fa6479eabbc5662910ff92173851cb06949a51e781523379ac6089cfb2b1c0cce8b0e1b1b861c45ada84ac8ab88b31472f222b375832edc41fd700d14a
@@ -62,18 +62,23 @@ module FrozenRecord
62
62
 
63
63
  def respond_to_missing?(name, *)
64
64
  if name.to_s =~ FIND_BY_PATTERN
65
- return true if $1.split('_and_').all? { |attr| public_method_defined?(attr) }
65
+ load_records # ensure attribute methods are defined
66
+ return true if $1.split('_and_').all? { |attr| instance_method_already_implemented?(attr) }
66
67
  end
67
68
  end
68
69
 
69
70
  def load_records
70
- @records = nil if auto_reloading && file_changed?
71
+ if auto_reloading && file_changed?
72
+ @records = nil
73
+ undefine_attribute_methods
74
+ end
75
+
71
76
  @records ||= begin
72
77
  yml_erb_data = File.read(file_path)
73
78
  yml_data = ERB.new(yml_erb_data).result
74
79
 
75
80
  records = YAML.load(yml_data) || []
76
- define_attributes!(list_attributes(records))
81
+ define_attribute_methods(list_attributes(records))
77
82
  records.map(&method(:new)).freeze
78
83
  end
79
84
  end
@@ -109,13 +114,7 @@ module FrozenRecord
109
114
  attributes.add(key.to_s)
110
115
  end
111
116
  end
112
- attributes
113
- end
114
-
115
- def define_attributes!(attributes)
116
- attributes.each do |attr|
117
- define_attribute_method(attr)
118
- end
117
+ attributes.to_a
119
118
  end
120
119
 
121
120
  end
@@ -118,8 +118,8 @@ module FrozenRecord
118
118
  spawn.offset!(amount)
119
119
  end
120
120
 
121
- def respond_to_missing(method_name, *)
122
- array_delegable?(method_name) || super
121
+ def respond_to_missing?(method_name, *)
122
+ array_delegable?(method_name) || @klass.respond_to?(method_name) || super
123
123
  end
124
124
 
125
125
  protected
@@ -1,3 +1,3 @@
1
1
  module FrozenRecord
2
- VERSION = '0.7.0'
2
+ VERSION = '0.7.1'
3
3
  end
data/spec/scope_spec.rb CHANGED
@@ -145,12 +145,22 @@ describe 'querying' do
145
145
  expect(country).to be_nil
146
146
  end
147
147
 
148
+ it 'can be used on a scope' do
149
+ country = Country.republics.find_by_name_and_density('France', 116)
150
+ expect(country.name).to be == 'France'
151
+
152
+ country = Country.republics.find_by_name('Canada')
153
+ expect(country).to be_nil
154
+ end
155
+
148
156
  it 'hook into respond_to?' do
149
157
  expect(Country).to respond_to :find_by_name_and_density
158
+ expect(Country.republics).to respond_to :find_by_name_and_density
150
159
  end
151
160
 
152
161
  it 'do not respond to unknown attributes' do
153
162
  expect(Country).to_not respond_to :find_by_name_and_unknown_attribute
163
+ expect(Country.republics).to_not respond_to :find_by_name_and_unknown_attribute
154
164
  end
155
165
 
156
166
  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.7.0
4
+ version: 0.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jean Boussier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-06 00:00:00.000000000 Z
11
+ date: 2016-05-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel