frozen_record 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -4
- data/lib/frozen_record/scope.rb +4 -4
- data/lib/frozen_record/version.rb +1 -1
- data/spec/scope_spec.rb +10 -2
- data/spec/support/country.rb +3 -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: 785548769c7ba7f3bbb52f2e17b9a3199b5dbcc7
|
4
|
+
data.tar.gz: a35161fae1e80efc72d01ea0eb0e4c45e0cacd84
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c026e89f7d50bdf288da41935a7615d9e45906ab041da84f1fb564ab79bc53ebde815d2c63adeaad16dc7bfcba36b2c1a10bf99e9f91e6e181af53b9be3aee51
|
7
|
+
data.tar.gz: 5081081b183668d2eb253576ffa04116a348d9e90901dee06e9ef0bec66d0b78224f906877551cd4dd255b5451b79d92722e440eee0ad045d82d393198ba06e3
|
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
# FrozenRecord
|
2
2
|
|
3
|
-
[![Build Status](https://secure.travis-ci.org/byroot/frozen_record.
|
4
|
-
[![Code Climate](https://codeclimate.com/github/byroot/frozen_record.
|
5
|
-
[![Coverage Status](https://coveralls.io/repos/byroot/frozen_record/badge.
|
6
|
-
[![Gem Version](https://badge.fury.io/rb/frozen_record.
|
3
|
+
[![Build Status](https://secure.travis-ci.org/byroot/frozen_record.svg)](http://travis-ci.org/byroot/frozen_record)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/byroot/frozen_record.svg)](https://codeclimate.com/github/byroot/frozen_record)
|
5
|
+
[![Coverage Status](https://coveralls.io/repos/byroot/frozen_record/badge.svg)](https://coveralls.io/r/byroot/frozen_record)
|
6
|
+
[![Gem Version](https://badge.fury.io/rb/frozen_record.svg)](http://badge.fury.io/rb/frozen_record)
|
7
7
|
|
8
8
|
ActiveRecord-like interface for **read only** access to YAML static data.
|
9
9
|
|
data/lib/frozen_record/scope.rb
CHANGED
@@ -161,8 +161,8 @@ module FrozenRecord
|
|
161
161
|
def sort_records(records)
|
162
162
|
return records if @order_values.empty?
|
163
163
|
|
164
|
-
records.sort do |
|
165
|
-
compare(
|
164
|
+
records.sort do |record_a, record_b|
|
165
|
+
compare(record_a, record_b)
|
166
166
|
end
|
167
167
|
end
|
168
168
|
|
@@ -174,9 +174,9 @@ module FrozenRecord
|
|
174
174
|
records[first...last] || []
|
175
175
|
end
|
176
176
|
|
177
|
-
def compare(
|
177
|
+
def compare(record_a, record_b)
|
178
178
|
@order_values.each do |attr, order|
|
179
|
-
a_value, b_value =
|
179
|
+
a_value, b_value = record_a.send(attr), record_b.send(attr)
|
180
180
|
cmp = a_value <=> b_value
|
181
181
|
next if cmp == 0
|
182
182
|
return order == :asc ? cmp : -cmp
|
data/spec/scope_spec.rb
CHANGED
@@ -243,13 +243,21 @@ describe 'querying' do
|
|
243
243
|
|
244
244
|
context 'when passed a hash' do
|
245
245
|
|
246
|
-
it '
|
246
|
+
it 'reorder records by given attribute and specified order' do
|
247
247
|
countries = Country.order(name: :desc).pluck(:name)
|
248
248
|
expect(countries).to be == %w(France Canada Austria)
|
249
249
|
end
|
250
250
|
|
251
251
|
end
|
252
252
|
|
253
|
+
context 'when passed arguments that are not attributes' do
|
254
|
+
|
255
|
+
it 'reorder records by calling the given method name' do
|
256
|
+
countries = Country.order(:reverse_name).pluck(:reverse_name)
|
257
|
+
expect(countries).to be == %w(adanaC airtsuA ecnarF)
|
258
|
+
end
|
259
|
+
|
260
|
+
end
|
253
261
|
end
|
254
262
|
|
255
263
|
describe '.limit' do
|
@@ -349,7 +357,7 @@ describe 'querying' do
|
|
349
357
|
|
350
358
|
it 'returns the sum of the column argument' do
|
351
359
|
sum = Country.sum(:population)
|
352
|
-
expect(sum).to
|
360
|
+
expect(sum).to be_within(0.00000000000002).of(108.042)
|
353
361
|
end
|
354
362
|
|
355
363
|
end
|
data/spec/support/country.rb
CHANGED
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.
|
4
|
+
version: 0.9.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jean Boussier
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-03-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|