mongo_mapper_acts_as_list 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -13,64 +13,66 @@ module MongoMapper
13
13
 
14
14
 
15
15
  module ClassMethods
16
-
17
16
  def acts_as_list(options = {})
18
- configuration = { :column => "position", :scope => {} }
19
- configuration.update(options) if options.is_a?(Hash)
20
17
 
21
18
 
22
19
 
20
+ def self.included(base)
21
+ include Comparable
22
+ end
23
+
24
+
25
+
26
+ configuration = { :column => "position", :scope => {} }
27
+ configuration.update(options) if options.is_a?(Hash)
23
28
  configuration[:scope] = "#{configuration[:scope]}_id".intern if
24
29
  configuration[:scope].is_a?(Symbol) && configuration[:scope].to_s !~ /_id$/
25
30
 
26
31
 
27
32
 
28
33
  if configuration[:scope].is_a?(Symbol)
29
- scope_condition_method = %(
30
- def scope_condition
31
- { "#{configuration[:scope].to_s}" => send(:#{configuration[:scope].to_s}) }.symbolize_keys!
32
- end
33
- )
34
-
34
+ define_method "scope_condition" do
35
+ { configuration[:scope] => send(configuration[:scope].to_s) }.symbolize_keys!
36
+ end
35
37
  elsif configuration[:scope].is_a?(Array)
36
- scope_condition_method = %(
37
- def scope_condition
38
- attrs = %w(#{configuration[:scope].join(" ")}).inject({}) do |memo, column|
39
- memo[column.intern] = send(column.intern)
40
- memo
41
- end
42
- attrs.symbolize_keys!
43
- end
44
- )
38
+ define_method "scope_condition" do
39
+ configuration[:scope].inject({}) { |memo, column|
40
+ memo[column.intern] = send(column.intern)
41
+ memo
42
+ }.symbolize_keys!
43
+ end
45
44
  else
46
-
47
- scope_condition_method = %(
48
- def scope_condition
49
- #{configuration[:scope].to_json}
50
- end
51
- )
45
+ define_method "scope_condition" do
46
+ configuration[:scope].to_json
47
+ end
52
48
  end
53
-
54
-
55
-
56
- class_eval <<-EOV
49
+
50
+
51
+
52
+ define_method "position_column" do
53
+ "#{configuration[:column]}"
54
+ end
55
+
56
+
57
+
58
+ key configuration[:column], Integer
59
+
60
+
61
+
62
+ before_destroy :decrement_positions_on_lower_items
63
+ before_create :add_to_list_bottom
64
+
65
+
66
+
67
+ class_eval <<-EOV
57
68
  def acts_as_list_class
58
69
  ::#{self.name}
59
70
  end
60
-
61
- def position_column
62
- '#{configuration[:column]}'
63
- end
64
-
65
- #{scope_condition_method}
66
-
67
- key '#{configuration[:column]}', Integer
68
-
69
- before_destroy :decrement_positions_on_lower_items
70
- before_create :add_to_list_bottom
71
71
  EOV
72
+
73
+
74
+
72
75
  end
73
-
74
76
  end
75
77
 
76
78
 
@@ -81,6 +83,10 @@ module MongoMapper
81
83
 
82
84
  module InstanceMethods
83
85
 
86
+ def <=>(other)
87
+ self[position_column] <=> other[position_column]
88
+ end
89
+
84
90
  # Insert the item at the given position (defaults to the top position of 1).
85
91
  def insert_at(position = 1)
86
92
  insert_at_position(position)
@@ -8,7 +8,7 @@ module MongoMapper
8
8
 
9
9
 
10
10
 
11
- Version = '0.3.2'
11
+ Version = '0.3.3'
12
12
 
13
13
 
14
14
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongo_mapper_acts_as_list
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-10-23 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mongo_mapper
16
- requirement: &70330524729220 !ruby/object:Gem::Requirement
16
+ requirement: &70196084473160 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70330524729220
24
+ version_requirements: *70196084473160
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &70330524728780 !ruby/object:Gem::Requirement
27
+ requirement: &70196084470020 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70330524728780
35
+ version_requirements: *70196084470020
36
36
  description: This is a port of classic Rails' acts_as_list to Mongo Mapper. This Mongo
37
37
  Mapper plugin provides the capabilities for sorting and reordering a number of objects
38
38
  in a list. If you do not specify custom position column in the options, a key named
@@ -63,7 +63,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
63
63
  version: '0'
64
64
  segments:
65
65
  - 0
66
- hash: -342600062179569977
66
+ hash: 1708410481327726767
67
67
  required_rubygems_version: !ruby/object:Gem::Requirement
68
68
  none: false
69
69
  requirements: