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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5477acbd4ee7ae0a0fcdfe48f71d323d00468780
4
- data.tar.gz: 8d5eb8ed257ea8c244754c1e181b8cac7c3da91b
3
+ metadata.gz: 785548769c7ba7f3bbb52f2e17b9a3199b5dbcc7
4
+ data.tar.gz: a35161fae1e80efc72d01ea0eb0e4c45e0cacd84
5
5
  SHA512:
6
- metadata.gz: 766bd1bc51a4a3550cb1f0c393ebff069acea8f2315d969aa7ecd706792f1bc0e37a2796d01576aef597b540bf456889b60ae9bf45eff2081c06189f951116d7
7
- data.tar.gz: ac701b3390eead9b097f7fa0a89aa2c8ef9bb1a2602dd4f2b97b20084b2d8c789e6645919bfe3df667be3444be76e963a263657c73eee50df480664abbabbe32
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.png)](http://travis-ci.org/byroot/frozen_record)
4
- [![Code Climate](https://codeclimate.com/github/byroot/frozen_record.png)](https://codeclimate.com/github/byroot/frozen_record)
5
- [![Coverage Status](https://coveralls.io/repos/byroot/frozen_record/badge.png)](https://coveralls.io/r/byroot/frozen_record)
6
- [![Gem Version](https://badge.fury.io/rb/frozen_record.png)](http://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
 
@@ -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 |a, b|
165
- compare(a, b)
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(a, b)
177
+ def compare(record_a, record_b)
178
178
  @order_values.each do |attr, order|
179
- a_value, b_value = a[attr], b[attr]
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
@@ -1,3 +1,3 @@
1
1
  module FrozenRecord
2
- VERSION = '0.8.0'
2
+ VERSION = '0.9.0'
3
3
  end
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 'records records by given attribute and specified order' do
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 be == 108.04200000000002
360
+ expect(sum).to be_within(0.00000000000002).of(108.042)
353
361
  end
354
362
 
355
363
  end
@@ -4,4 +4,7 @@ class Country < FrozenRecord::Base
4
4
  where(king: nil)
5
5
  end
6
6
 
7
+ def reverse_name
8
+ name.reverse
9
+ end
7
10
  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.8.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: 2017-01-09 00:00:00.000000000 Z
11
+ date: 2018-03-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel