activerecord_sortable 0.0.4 → 0.1.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: 5640a5dd9f693339206e48b5ab9b3a5da3f147ff
4
- data.tar.gz: 308004a4966b8cf43fd8918461b36dda03ad75ef
3
+ metadata.gz: 1bf73c95b55406d62e73c59a4e3d61b1fe9f7116
4
+ data.tar.gz: 55acfcb751c18e34f8dd09d016444a105cbcd9ff
5
5
  SHA512:
6
- metadata.gz: 29d9883a543f1e643b1fa44f2631afd345f4d38a648180432b1fd6ac914c6c93c67b262e090935a063acfe6a451523b95d07e146161e9a3b7ed3fb9bf8ddf1a4
7
- data.tar.gz: 50e11bb35d513717b964f06a4496f06f2b4b8c12ce17f28920f50a59df4654b66083433f6d065b652f5e6b1f5316266af5d49a51ff4f4e2e98a38d01c90e8e25
6
+ metadata.gz: ef04696ffa2b16931bae9b146f4bf20c74f0f20fdefb1b4d27dd6ac26ef2c60a3e979f0bfc53286a0615dd6396fa89d7f0aea9c5c1c18cbfb410d9a1e02cdad7
7
+ data.tar.gz: b0e3147d74a143f2d3bf10c5828b440b7a2aae5ad663131d373f456f665f66bd2d0e1931462b7896350544f0253ec5d036c40fccf302fc9e6b2c981ed72413b9
@@ -1,6 +1,7 @@
1
1
  require 'activerecord_sortable/association'
2
2
  require 'activerecord_sortable/association_reflection'
3
- require 'activerecord_sortable/association_relation'
3
+ require 'activerecord_sortable/through_reflection'
4
+ require 'activerecord_sortable/collection_proxy'
4
5
  require 'activerecord_sortable/has_many_association'
5
6
 
6
7
  module ActiveRecordSortable
@@ -0,0 +1,19 @@
1
+ # encoding: utf-8
2
+ module ActiveRecord
3
+ module Associations
4
+ class CollectionProxy
5
+
6
+ alias_method :original_load_target, :load_target
7
+
8
+ def load_target
9
+ if proxy_association.reflection.sortable? and order_values.empty?
10
+ sortable_table_name = (proxy_association.try(:through_reflection) || proxy_association.reflection).table_name
11
+ order("#{sortable_table_name}.#{proxy_association.reflection.sortable_field} ASC").to_a
12
+ else
13
+ original_load_target
14
+ end
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+ module ActiveRecord
3
+ module Reflection
4
+ class ThroughReflection
5
+
6
+ def sortable_field
7
+ @delegate_reflection.options.fetch(:sortable_field, :position).to_sym
8
+ end
9
+
10
+ def sortable?
11
+ @delegate_reflection.options.fetch(:sortable, false)
12
+ end
13
+
14
+ end
15
+ end
16
+ end
@@ -1,4 +1,4 @@
1
1
  # encoding: utf-8
2
2
  module ActiveRecordSortable
3
- VERSION = '0.0.4'
3
+ VERSION = '0.1.0'
4
4
  end
@@ -3,15 +3,15 @@ require 'spec_helper'
3
3
  describe 'Association reflection' do
4
4
 
5
5
  let(:post_reflection) do
6
- User.reflections[:posts]
6
+ User.reflections['posts']
7
7
  end
8
8
 
9
9
  let(:user_post_reflection) do
10
- User.reflections[:user_posts]
10
+ User.reflections['user_posts']
11
11
  end
12
12
 
13
13
  let(:sorted_post_reflection) do
14
- User.reflections[:sorted_posts]
14
+ User.reflections['sorted_posts']
15
15
  end
16
16
 
17
17
  describe '.sortable?' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord_sortable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vladislav Melanitskiy
@@ -16,14 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
- version: 4.1.0
19
+ version: '4.2'
20
+ - - '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 4.2.0
20
23
  type: :runtime
21
24
  prerelease: false
22
25
  version_requirements: !ruby/object:Gem::Requirement
23
26
  requirements:
24
27
  - - ~>
25
28
  - !ruby/object:Gem::Version
26
- version: 4.1.0
29
+ version: '4.2'
30
+ - - '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 4.2.0
27
33
  description: It adds possibility for sorting relation
28
34
  email:
29
35
  - co@rademade.com
@@ -34,8 +40,9 @@ files:
34
40
  - lib/activerecord_sortable.rb
35
41
  - lib/activerecord_sortable/association.rb
36
42
  - lib/activerecord_sortable/association_reflection.rb
37
- - lib/activerecord_sortable/association_relation.rb
43
+ - lib/activerecord_sortable/collection_proxy.rb
38
44
  - lib/activerecord_sortable/has_many_association.rb
45
+ - lib/activerecord_sortable/through_reflection.rb
39
46
  - lib/activerecord_sortable/version.rb
40
47
  - spec/dummy/README.rdoc
41
48
  - spec/dummy/Rakefile
@@ -1,17 +0,0 @@
1
- # encoding: utf-8
2
- module ActiveRecord
3
- class AssociationRelation
4
-
5
- alias_method :original_to_a, :to_a
6
-
7
- def to_a
8
- if proxy_association.reflection.sortable? and order_values.empty?
9
- sortable_table_name = (proxy_association.try(:through_reflection) || proxy_association.reflection).table_name
10
- order("#{sortable_table_name}.#{proxy_association.reflection.sortable_field} ASC").to_a
11
- else
12
- original_to_a
13
- end
14
- end
15
-
16
- end
17
- end