frozen_record 0.1.1 → 0.1.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
  SHA1:
3
- metadata.gz: 8ea4f7773d19e5117d8b6f23c0d084f69d9b9536
4
- data.tar.gz: 55b940e5665ae50fbde6f2a39ea5cd3ef5a441f1
3
+ metadata.gz: 3d4e63aa52d9052aae870362fdf7fdb9694b9b7a
4
+ data.tar.gz: e9c04cee1e8f9d9d9fa092210fd8136ca511020f
5
5
  SHA512:
6
- metadata.gz: f0bd1f71685d2bac36df3311bf9b8d97697d755eb910a7c7903a64add5543f51b98d975f99813c4c9aa8d2df7c8968f040e28f5478af061469fb964282e06d08
7
- data.tar.gz: bc8c7766b4100563913f824bd6cb2e95e75439eb8a20cec2ad204195e48b1c8916dc17fcc61f7e9a81a35e0c5b5eef6095477893cf0cd573dc950f1c9a42526f
6
+ metadata.gz: 267fb24b52944b467872711210dd37813fe47076a0115524194c004c2dfcb8b1f6119bd883aa6d3a0d298864f8dda4b51e4eaa0bf07ed28e857e16c4ea5c0616
7
+ data.tar.gz: 2d843d62ac21f9541bdff32b988b2830bbf496c754027555947d0c9c6ad515a4d4a52158f283737d90c0f9b51d4bb8e77e875292d3f4aeb865c5b350a53834bb
@@ -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] == value } &&
143
- @where_not_values.all? { |attr, value| record[attr] != value }
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
@@ -1,3 +1,3 @@
1
1
  module FrozenRecord
2
- VERSION = '0.1.1'
2
+ VERSION = '0.1.2'
3
3
  end
@@ -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 be_false
67
+ expect(blank.id?).to be false
68
68
  end
69
69
 
70
70
  it 'considers `""` as missing' do
71
- expect(blank.name?).to be_false
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 be_false
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 be_false
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 be_true
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 be_true
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 be_true
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 be_true
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 be_empty
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.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-04-10 00:00:00.000000000 Z
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.1
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