ranked-model 0.4.3 → 0.4.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Appraisals +5 -5
- data/Readme.mkd +9 -0
- data/gemfiles/rails_4_1.gemfile +1 -1
- data/gemfiles/rails_4_2.gemfile +1 -1
- data/gemfiles/rails_5_0.gemfile +1 -1
- data/gemfiles/rails_5_1.gemfile +1 -1
- data/gemfiles/rails_5_2.gemfile +1 -1
- data/lib/ranked-model.rb +9 -1
- data/lib/ranked-model/ranker.rb +4 -0
- data/lib/ranked-model/version.rb +1 -1
- data/spec/duck-model/column_default_ducks_spec.rb +15 -0
- data/spec/duck-model/duck_spec.rb +31 -0
- data/spec/support/database.yml +1 -1
- metadata +2 -3
- data/gemfiles/rails_3_2.gemfile +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e92bbed2da4ae8cd7a3705fed451fb73a27b6eee
|
4
|
+
data.tar.gz: da248775ef6a763b5a6342587fd5343c06db9adb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 638948178a3dd3c45bdc811e43ea8b5ca2cd8401ae7a74124c97e2cf09d5a68381bcce5e810db1d42b311281a07633cfb69946c0994e8f1a1675fb564501e70b
|
7
|
+
data.tar.gz: 3d37e0b29d0aac037f6ca3edf7258ffac9b17aefa55f46f472d0789999eddf37e5258ea30969a94d7f1543a95e63bf964d40b0d4c517354f6e64b057f1054cc0
|
data/Appraisals
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
appraise "rails-4-1" do
|
2
2
|
group :sqlite do
|
3
|
-
gem "sqlite3", platform: :ruby
|
3
|
+
gem "sqlite3", "~> 1.3.13", platform: :ruby
|
4
4
|
gem "activerecord-jdbcsqlite3-adapter", "~> 1.3.24", platform: :jruby
|
5
5
|
end
|
6
6
|
group :mysql do
|
@@ -17,7 +17,7 @@ end
|
|
17
17
|
|
18
18
|
appraise "rails-4-2" do
|
19
19
|
group :sqlite do
|
20
|
-
gem "sqlite3", platform: :ruby
|
20
|
+
gem "sqlite3", "~> 1.3.13", platform: :ruby
|
21
21
|
gem "activerecord-jdbcsqlite3-adapter", "~> 1.3.24", platform: :jruby
|
22
22
|
end
|
23
23
|
group :mysql do
|
@@ -34,7 +34,7 @@ end
|
|
34
34
|
|
35
35
|
appraise "rails-5-0" do
|
36
36
|
group :sqlite do
|
37
|
-
gem "sqlite3", platform: :ruby
|
37
|
+
gem "sqlite3", "~> 1.3.13", platform: :ruby
|
38
38
|
gem "activerecord-jdbcsqlite3-adapter", "~> 50.1", platform: :jruby
|
39
39
|
end
|
40
40
|
group :mysql do
|
@@ -51,7 +51,7 @@ end
|
|
51
51
|
|
52
52
|
appraise "rails-5-1" do
|
53
53
|
group :sqlite do
|
54
|
-
gem "sqlite3", platform: :ruby
|
54
|
+
gem "sqlite3", "~> 1.3.13", platform: :ruby
|
55
55
|
gem "activerecord-jdbcsqlite3-adapter", "~> 51.1", platform: :jruby
|
56
56
|
end
|
57
57
|
group :mysql do
|
@@ -68,7 +68,7 @@ end
|
|
68
68
|
|
69
69
|
appraise "rails-5-2" do
|
70
70
|
group :sqlite do
|
71
|
-
gem "sqlite3", platform: :ruby
|
71
|
+
gem "sqlite3", "~> 1.3.13", platform: :ruby
|
72
72
|
end
|
73
73
|
group :mysql do
|
74
74
|
gem "mysql2", "~> 0.4.10", platform: :ruby
|
data/Readme.mkd
CHANGED
@@ -72,6 +72,15 @@ $.ajax({
|
|
72
72
|
});
|
73
73
|
```
|
74
74
|
|
75
|
+
If you need to find the rank of an item with respect to other ranked items, you can use the `{column_name}_rank` method on the model instance. `{column_name}` is your resource ranking column.
|
76
|
+
|
77
|
+
Following on from our examples above, the `row_order_rank` method will return the position of the duck object in the list with respect to the order defined by the row_order column.
|
78
|
+
|
79
|
+
``` ruby
|
80
|
+
Duck.rank(:row_order).first.row_order_rank # => 0
|
81
|
+
Duck.rank(:row_order).third.row_order_rank # => 2
|
82
|
+
```
|
83
|
+
|
75
84
|
Complex Use
|
76
85
|
-----------
|
77
86
|
|
data/gemfiles/rails_4_1.gemfile
CHANGED
data/gemfiles/rails_4_2.gemfile
CHANGED
data/gemfiles/rails_5_0.gemfile
CHANGED
data/gemfiles/rails_5_1.gemfile
CHANGED
data/gemfiles/rails_5_2.gemfile
CHANGED
data/lib/ranked-model.rb
CHANGED
@@ -48,7 +48,7 @@ module RankedModel
|
|
48
48
|
self.rankers ||= []
|
49
49
|
ranker = RankedModel::Ranker.new(*args)
|
50
50
|
|
51
|
-
if
|
51
|
+
if column_default(ranker)
|
52
52
|
raise NonNilColumnDefault, %Q{Your ranked model column "#{ranker.name}" must not have a default value in the database.}
|
53
53
|
end
|
54
54
|
|
@@ -61,9 +61,17 @@ module RankedModel
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
+
define_method "#{ranker.name}_rank" do
|
65
|
+
ranker.with(self).relative_rank
|
66
|
+
end
|
67
|
+
|
64
68
|
public "#{ranker.name}_position", "#{ranker.name}_position="
|
65
69
|
end
|
66
70
|
|
71
|
+
def column_default ranker
|
72
|
+
column_defaults[ranker.name.to_s] if ActiveRecord::Base.connected?
|
73
|
+
end
|
74
|
+
|
67
75
|
end
|
68
76
|
|
69
77
|
end
|
data/lib/ranked-model/ranker.rb
CHANGED
data/lib/ranked-model/version.rb
CHANGED
@@ -11,4 +11,19 @@ describe 'ColumnDefaultDuck' do
|
|
11
11
|
}.to raise_error(RankedModel::NonNilColumnDefault, 'Your ranked model column "size" must not have a default value in the database.')
|
12
12
|
end
|
13
13
|
|
14
|
+
it "should not raise an error if we don't have a database connection when checking for default value" do
|
15
|
+
begin
|
16
|
+
ActiveRecord::Base.remove_connection
|
17
|
+
|
18
|
+
expect {
|
19
|
+
class ColumnDefaultDuck < ActiveRecord::Base
|
20
|
+
include RankedModel
|
21
|
+
ranks :size, :with_same => :pond
|
22
|
+
end
|
23
|
+
}.not_to raise_error
|
24
|
+
ensure
|
25
|
+
ActiveRecord::Base.establish_connection(DB_CONFIG.to_sym)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
14
29
|
end
|
@@ -10,12 +10,16 @@ describe Duck do
|
|
10
10
|
|
11
11
|
it { expect(subject).to respond_to(:row_position) }
|
12
12
|
it { expect(subject).to respond_to(:row_position=) }
|
13
|
+
it { expect(subject).to respond_to(:row_rank) }
|
13
14
|
it { expect(subject).to respond_to(:size_position) }
|
14
15
|
it { expect(subject).to respond_to(:size_position=) }
|
16
|
+
it { expect(subject).to respond_to(:size_rank) }
|
15
17
|
it { expect(subject).to respond_to(:age_position) }
|
16
18
|
it { expect(subject).to respond_to(:age_position=) }
|
19
|
+
it { expect(subject).to respond_to(:age_rank) }
|
17
20
|
it { expect(subject).to respond_to(:landing_order_position) }
|
18
21
|
it { expect(subject).to respond_to(:landing_order_position=) }
|
22
|
+
it { expect(subject).to respond_to(:landing_order_rank) }
|
19
23
|
|
20
24
|
end
|
21
25
|
|
@@ -748,6 +752,33 @@ describe Duck do
|
|
748
752
|
|
749
753
|
end
|
750
754
|
|
755
|
+
describe "fetching rank for an instance" do
|
756
|
+
before {
|
757
|
+
[:quacky, :feathers, :wingy, :webby, :waddly, :beaky].each_with_index do |name, i|
|
758
|
+
Duck.where(id: @ducks[name].id).update_all(row: RankedModel::MAX_RANK_VALUE - i)
|
759
|
+
@ducks[name].reload
|
760
|
+
end
|
761
|
+
}
|
762
|
+
|
763
|
+
context {
|
764
|
+
subject { Duck.find_by(id: @ducks[:beaky]).row_rank }
|
765
|
+
|
766
|
+
it { should == 0 }
|
767
|
+
}
|
768
|
+
|
769
|
+
context {
|
770
|
+
subject { Duck.find_by(id: @ducks[:wingy]).row_rank }
|
771
|
+
|
772
|
+
it { should == 3 }
|
773
|
+
}
|
774
|
+
|
775
|
+
context {
|
776
|
+
subject { Duck.find_by(id: @ducks[:quacky]).row_rank }
|
777
|
+
|
778
|
+
it { should == 5 }
|
779
|
+
}
|
780
|
+
end
|
781
|
+
|
751
782
|
end
|
752
783
|
|
753
784
|
describe Duck do
|
data/spec/support/database.yml
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ranked-model
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matthew Beale
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-03-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -138,7 +138,6 @@ files:
|
|
138
138
|
- LICENSE
|
139
139
|
- Rakefile
|
140
140
|
- Readme.mkd
|
141
|
-
- gemfiles/rails_3_2.gemfile
|
142
141
|
- gemfiles/rails_4_1.gemfile
|
143
142
|
- gemfiles/rails_4_2.gemfile
|
144
143
|
- gemfiles/rails_5_0.gemfile
|
data/gemfiles/rails_3_2.gemfile
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
# This file was generated by Appraisal
|
2
|
-
|
3
|
-
source "https://rubygems.org"
|
4
|
-
|
5
|
-
gem "activerecord", "~> 3.2.22.5"
|
6
|
-
|
7
|
-
group :sqlite do
|
8
|
-
gem "sqlite3", platform: :ruby
|
9
|
-
gem "activerecord-jdbcsqlite3-adapter", "~> 1.3.24", platform: :jruby
|
10
|
-
end
|
11
|
-
|
12
|
-
group :mysql do
|
13
|
-
gem "mysql2", "~> 0.3.21", platform: :ruby
|
14
|
-
gem "activerecord-jdbcmysql-adapter", "~> 1.3.24", platform: :jruby
|
15
|
-
end
|
16
|
-
|
17
|
-
group :postgresql do
|
18
|
-
gem "pg", "~> 0.18.0", platform: :ruby
|
19
|
-
gem "activerecord-jdbcpostgresql-adapter", "~> 1.3.24", platform: :jruby
|
20
|
-
end
|
21
|
-
|
22
|
-
gemspec path: "../"
|