frozen_record 0.1.1 → 0.1.2
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 +4 -4
- data/lib/frozen_record/scope.rb +8 -3
- data/lib/frozen_record/version.rb +1 -1
- data/spec/frozen_record_spec.rb +8 -8
- data/spec/scope_spec.rb +11 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d4e63aa52d9052aae870362fdf7fdb9694b9b7a
|
4
|
+
data.tar.gz: e9c04cee1e8f9d9d9fa092210fd8136ca511020f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 267fb24b52944b467872711210dd37813fe47076a0115524194c004c2dfcb8b1f6119bd883aa6d3a0d298864f8dda4b51e4eaa0bf07ed28e857e16c4ea5c0616
|
7
|
+
data.tar.gz: 2d843d62ac21f9541bdff32b988b2830bbf496c754027555947d0c9c6ad515a4d4a52158f283737d90c0f9b51d4bb8e77e875292d3f4aeb865c5b350a53834bb
|
data/lib/frozen_record/scope.rb
CHANGED
@@ -139,8 +139,8 @@ module FrozenRecord
|
|
139
139
|
return records if @where_values.empty? && @where_not_values.empty?
|
140
140
|
|
141
141
|
records.select do |record|
|
142
|
-
@where_values.all? { |attr, value| record[attr]
|
143
|
-
@where_not_values.all? { |attr, value| record[attr]
|
142
|
+
@where_values.all? { |attr, value| compare_value(record[attr], value) } &&
|
143
|
+
@where_not_values.all? { |attr, value| !compare_value(record[attr], value) }
|
144
144
|
end
|
145
145
|
end
|
146
146
|
|
@@ -172,7 +172,7 @@ module FrozenRecord
|
|
172
172
|
|
173
173
|
def method_missing(method_name, *args, &block)
|
174
174
|
if array_delegable?(method_name)
|
175
|
-
to_a.public_send(method_name, *args, &block)
|
175
|
+
to_a.public_send(method_name, *args, &block)
|
176
176
|
elsif @klass.respond_to?(method_name)
|
177
177
|
delegate_to_class(method_name, *args, &block)
|
178
178
|
else
|
@@ -215,5 +215,10 @@ module FrozenRecord
|
|
215
215
|
self
|
216
216
|
end
|
217
217
|
|
218
|
+
private
|
219
|
+
def compare_value(actual, requested)
|
220
|
+
return actual == requested unless requested.is_a?(Array) || requested.is_a?(Range)
|
221
|
+
requested.include?(actual)
|
222
|
+
end
|
218
223
|
end
|
219
224
|
end
|
data/spec/frozen_record_spec.rb
CHANGED
@@ -64,35 +64,35 @@ describe FrozenRecord::Base do
|
|
64
64
|
let(:present) { Country.new(id: 42, name: 'Groland', nato: true, king: Object.new) }
|
65
65
|
|
66
66
|
it 'considers `0` as missing' do
|
67
|
-
expect(blank.id?).to
|
67
|
+
expect(blank.id?).to be false
|
68
68
|
end
|
69
69
|
|
70
70
|
it 'considers `""` as missing' do
|
71
|
-
expect(blank.name?).to
|
71
|
+
expect(blank.name?).to be false
|
72
72
|
end
|
73
73
|
|
74
74
|
it 'considers `false` as missing' do
|
75
|
-
expect(blank.nato?).to
|
75
|
+
expect(blank.nato?).to be false
|
76
76
|
end
|
77
77
|
|
78
78
|
it 'considers `nil` as missing' do
|
79
|
-
expect(blank.king?).to
|
79
|
+
expect(blank.king?).to be false
|
80
80
|
end
|
81
81
|
|
82
82
|
it 'considers other numbers than `0` as present' do
|
83
|
-
expect(present.id?).to
|
83
|
+
expect(present.id?).to be true
|
84
84
|
end
|
85
85
|
|
86
86
|
it 'considers other strings than `""` as present' do
|
87
|
-
expect(present.name?).to
|
87
|
+
expect(present.name?).to be true
|
88
88
|
end
|
89
89
|
|
90
90
|
it 'considers `true` as present' do
|
91
|
-
expect(present.nato?).to
|
91
|
+
expect(present.nato?).to be true
|
92
92
|
end
|
93
93
|
|
94
94
|
it 'considers not `nil` objects as present' do
|
95
|
-
expect(present.king?).to
|
95
|
+
expect(present.king?).to be true
|
96
96
|
end
|
97
97
|
|
98
98
|
end
|
data/spec/scope_spec.rb
CHANGED
@@ -151,7 +151,17 @@ describe 'querying' do
|
|
151
151
|
|
152
152
|
it 'is chainable' do
|
153
153
|
countries = Country.where(name: 'France').where(id: 1)
|
154
|
-
expect(countries).to
|
154
|
+
expect(countries.length).to be == 0
|
155
|
+
end
|
156
|
+
|
157
|
+
it 'can be used with arrays' do
|
158
|
+
countries = Country.where(id: [1,2])
|
159
|
+
expect(countries.length).to be == 2
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'can be used with ranges' do
|
163
|
+
countries = Country.where(id: (1..2))
|
164
|
+
expect(countries.length).to be == 2
|
155
165
|
end
|
156
166
|
|
157
167
|
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.1.
|
4
|
+
version: 0.1.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: 2014-
|
11
|
+
date: 2014-07-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -126,7 +126,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
126
126
|
version: '0'
|
127
127
|
requirements: []
|
128
128
|
rubyforge_project:
|
129
|
-
rubygems_version: 2.2.
|
129
|
+
rubygems_version: 2.2.2
|
130
130
|
signing_key:
|
131
131
|
specification_version: 4
|
132
132
|
summary: ActiveRecord like interface to read only access and query static YAML files
|