mongoid-sorted-relations 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/README.md +0 -4
  2. data/lib/mongoid/sorted_relations.rb +1 -9
  3. metadata +11 -11
data/README.md CHANGED
@@ -37,13 +37,9 @@ class Book
37
37
 
38
38
  has_many :chapters
39
39
  has_and_belongs_to_many :authors
40
-
41
- init_sorted_relations
42
40
  end
43
41
  ```
44
42
 
45
- It's important to place the ```init_sorted_relations``` after the declaration of your relations.
46
-
47
43
 
48
44
  ### Getting the relations in the right order
49
45
 
@@ -3,18 +3,9 @@ module Mongoid
3
3
  extend ActiveSupport::Concern
4
4
 
5
5
  def self.included(base)
6
- base.extend(ClassMethods)
7
6
  base.after_initialize :freeze_relation_ids
8
7
  end
9
8
 
10
- module ClassMethods
11
- def init_sorted_relations
12
- self.relations.each do |k,v|
13
- send(:define_method, "sorted_#{v.name}") { sorted_relation v } if [:references_many, :references_and_referenced_in_many].include? v.macro
14
- end
15
- end
16
- end
17
-
18
9
  def freeze_relation_ids
19
10
  @cache_sorted_documents = {}
20
11
  @cache_sorted_ids = {}
@@ -22,6 +13,7 @@ module Mongoid
22
13
  self.relations.each do |k,v|
23
14
  if [:references_many, :references_and_referenced_in_many].include? v.macro
24
15
  @cache_sorted_ids[v.key] = [self.send(v.key)].flatten.map{ |rid| rid.to_s }
16
+ self.class.send(:define_method, "sorted_#{v.name}") { sorted_relation v }
25
17
  end
26
18
  end
27
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongoid-sorted-relations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-05-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mongoid
16
- requirement: &2160751500 !ruby/object:Gem::Requirement
16
+ requirement: &2152416520 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '2.0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *2160751500
24
+ version_requirements: *2152416520
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: bson_ext
27
- requirement: &2160750920 !ruby/object:Gem::Requirement
27
+ requirement: &2152413860 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '1.6'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *2160750920
35
+ version_requirements: *2152413860
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rake
38
- requirement: &2160750080 !ruby/object:Gem::Requirement
38
+ requirement: &2152409420 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 0.8.7
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *2160750080
46
+ version_requirements: *2152409420
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rspec
49
- requirement: &2160539920 !ruby/object:Gem::Requirement
49
+ requirement: &2152407260 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '2.0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *2160539920
57
+ version_requirements: *2152407260
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: rspec-aspic
60
- requirement: &2160538360 !ruby/object:Gem::Requirement
60
+ requirement: &2152404900 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,7 +65,7 @@ dependencies:
65
65
  version: 0.0.2
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *2160538360
68
+ version_requirements: *2152404900
69
69
  description: Preserve the order of the mongoid documents in a referenced one-to-many
70
70
  or many-to-many relationship.
71
71
  email: