frozen_record 0.7.0 → 0.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/frozen_record/base.rb +9 -10
- data/lib/frozen_record/scope.rb +2 -2
- data/lib/frozen_record/version.rb +1 -1
- data/spec/scope_spec.rb +10 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 275b29fe63b81841f976203d89605b9a9a5c6289
|
4
|
+
data.tar.gz: 4243044175796dec9f623da8e9e1a589eef85994
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f4de4b60e0cee0988b3aaae4fab620958e034d2d22057cf7d4c896b3ec879295c0d3340576e9a388cd6b5e77d3bf581ed08eb3542cc6d51a5a0ad5cd79a254c7
|
7
|
+
data.tar.gz: 531c13fa6479eabbc5662910ff92173851cb06949a51e781523379ac6089cfb2b1c0cce8b0e1b1b861c45ada84ac8ab88b31472f222b375832edc41fd700d14a
|
data/lib/frozen_record/base.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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
|
-
|
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
|
data/lib/frozen_record/scope.rb
CHANGED
@@ -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
|
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.
|
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-
|
11
|
+
date: 2016-05-09 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|