mongo_mapper_acts_as_list 0.3 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +4 -4
- data/lib/mongo_mapper/plugins/acts_as_list.rb +44 -8
- data/lib/mongo_mapper/plugins/version.rb +10 -1
- data/test/mongo_mapper_acts_as_list_test.rb +32 -5
- metadata +38 -61
data/README.rdoc
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
= mongo_mapper_acts_as_list
|
2
2
|
|
3
|
-
This is a port of classic Rails' {acts_as_list}[http://github.com/rails/acts_as_list] to Mongo Mapper. This MongoMapper plugin provides the capabilities for sorting and reordering a number of objects in a list. If you do not specify custom position column in the options, a key named position will be used by default.
|
3
|
+
This is a port of classic Rails' {acts_as_list}[http://github.com/rails/acts_as_list] to Mongo Mapper. This MongoMapper plugin provides the capabilities for sorting and reordering a number of objects in a list. If you do not specify custom position column in the options, a key named position will be added and used by default.
|
4
4
|
|
5
5
|
It has (almost) the same functionality and passes the original test-suite. Scope needs to be defined as symbol or array of symbols. It does not work for Embedded Documents.
|
6
6
|
|
7
7
|
== Installation
|
8
8
|
|
9
|
-
|
9
|
+
Add this to your Gemfile and run the +bundle+ command:
|
10
10
|
|
11
|
-
gem
|
11
|
+
gem 'mongo_mapper_acts_as_list'
|
12
12
|
|
13
13
|
== Example
|
14
14
|
|
@@ -20,7 +20,7 @@ mongo_mapper_acts_as_list is available as RubyGem:
|
|
20
20
|
|
21
21
|
class TodoItem
|
22
22
|
include MongoMapper::Document
|
23
|
-
|
23
|
+
include MongoMapper::Plugins::ActsAsList
|
24
24
|
|
25
25
|
key :todo_list_id, ObjectId
|
26
26
|
belongs_to :todo_list
|
@@ -2,24 +2,36 @@ module MongoMapper
|
|
2
2
|
module Plugins
|
3
3
|
module ActsAsList
|
4
4
|
|
5
|
+
|
6
|
+
|
5
7
|
extend ActiveSupport::Concern
|
6
8
|
|
7
9
|
|
8
10
|
|
9
|
-
#
|
11
|
+
# =====================================================================
|
12
|
+
|
13
|
+
|
14
|
+
|
10
15
|
module ClassMethods
|
16
|
+
|
11
17
|
def acts_as_list(options = {})
|
12
18
|
configuration = { :column => "position", :scope => {} }
|
13
19
|
configuration.update(options) if options.is_a?(Hash)
|
14
20
|
|
15
|
-
|
16
|
-
|
21
|
+
|
22
|
+
|
23
|
+
configuration[:scope] = "#{configuration[:scope]}_id".intern if
|
24
|
+
configuration[:scope].is_a?(Symbol) && configuration[:scope].to_s !~ /_id$/
|
25
|
+
|
26
|
+
|
27
|
+
|
17
28
|
if configuration[:scope].is_a?(Symbol)
|
18
29
|
scope_condition_method = %(
|
19
30
|
def scope_condition
|
20
31
|
{ "#{configuration[:scope].to_s}" => send(:#{configuration[:scope].to_s}) }.symbolize_keys!
|
21
32
|
end
|
22
33
|
)
|
34
|
+
|
23
35
|
elsif configuration[:scope].is_a?(Array)
|
24
36
|
scope_condition_method = %(
|
25
37
|
def scope_condition
|
@@ -31,9 +43,16 @@ module MongoMapper
|
|
31
43
|
end
|
32
44
|
)
|
33
45
|
else
|
34
|
-
|
46
|
+
|
47
|
+
scope_condition_method = %(
|
48
|
+
def scope_condition
|
49
|
+
#{configuration[:scope].to_json}
|
50
|
+
end
|
51
|
+
)
|
35
52
|
end
|
36
53
|
|
54
|
+
|
55
|
+
|
37
56
|
class_eval <<-EOV
|
38
57
|
def acts_as_list_class
|
39
58
|
::#{self.name}
|
@@ -54,8 +73,12 @@ module MongoMapper
|
|
54
73
|
|
55
74
|
|
56
75
|
|
57
|
-
#
|
76
|
+
# =====================================================================
|
77
|
+
|
78
|
+
|
79
|
+
|
58
80
|
module InstanceMethods
|
81
|
+
|
59
82
|
# Insert the item at the given position (defaults to the top position of 1).
|
60
83
|
def insert_at(position = 1)
|
61
84
|
insert_at_position(position)
|
@@ -150,8 +173,12 @@ module MongoMapper
|
|
150
173
|
!send(position_column).nil?
|
151
174
|
end
|
152
175
|
|
176
|
+
|
177
|
+
|
153
178
|
private
|
154
|
-
|
179
|
+
|
180
|
+
|
181
|
+
|
155
182
|
def add_to_list_top
|
156
183
|
increment_positions_on_all_items
|
157
184
|
end
|
@@ -160,7 +187,9 @@ module MongoMapper
|
|
160
187
|
self[position_column] = bottom_position_in_list.to_i+1
|
161
188
|
end
|
162
189
|
|
163
|
-
def scope_condition
|
190
|
+
def scope_condition
|
191
|
+
"1"
|
192
|
+
end
|
164
193
|
|
165
194
|
# Returns the bottom position number in the list.
|
166
195
|
# bottom_position_in_list # => 2
|
@@ -228,9 +257,16 @@ module MongoMapper
|
|
228
257
|
update_position( position )
|
229
258
|
end
|
230
259
|
|
231
|
-
|
260
|
+
|
261
|
+
|
232
262
|
end
|
233
263
|
|
264
|
+
|
265
|
+
|
266
|
+
# =====================================================================
|
267
|
+
|
268
|
+
|
269
|
+
|
234
270
|
end
|
235
271
|
end
|
236
272
|
end
|
@@ -2,18 +2,22 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
+
# ---------------------------------------------------------------------
|
5
6
|
# CLASS SETUP
|
6
7
|
|
8
|
+
|
9
|
+
|
7
10
|
class ListMixin
|
11
|
+
|
8
12
|
include MongoMapper::Document
|
9
|
-
|
10
|
-
plugin MongoMapper::Plugins::ActsAsList
|
13
|
+
include MongoMapper::Plugins::ActsAsList
|
11
14
|
|
12
15
|
key :pos, Integer
|
13
16
|
key :parent_id, Integer
|
14
17
|
key :original_id, Integer
|
15
18
|
|
16
19
|
acts_as_list :column => :pos, :scope => :parent_id
|
20
|
+
|
17
21
|
end
|
18
22
|
|
19
23
|
class ListMixinSub1 < ListMixin
|
@@ -23,19 +27,22 @@ class ListMixinSub2 < ListMixin
|
|
23
27
|
end
|
24
28
|
|
25
29
|
class ListMixinWithArrayScope
|
30
|
+
|
26
31
|
include MongoMapper::Document
|
27
|
-
|
28
|
-
plugin MongoMapper::Plugins::ActsAsList
|
32
|
+
include MongoMapper::Plugins::ActsAsList
|
29
33
|
|
30
34
|
key :pos, Integer
|
31
35
|
key :parent_id, Integer
|
32
36
|
|
33
37
|
acts_as_list :column => :pos, :scope => [:parent_id, :original_id]
|
38
|
+
|
34
39
|
end
|
35
40
|
|
36
41
|
|
37
42
|
|
38
|
-
#
|
43
|
+
# ---------------------------------------------------------------------
|
44
|
+
|
45
|
+
|
39
46
|
|
40
47
|
class ScopeTest < ActiveSupport::TestCase
|
41
48
|
|
@@ -53,6 +60,10 @@ end
|
|
53
60
|
|
54
61
|
|
55
62
|
|
63
|
+
# ---------------------------------------------------------------------
|
64
|
+
|
65
|
+
|
66
|
+
|
56
67
|
class ActiveSupport::TestCase
|
57
68
|
|
58
69
|
private
|
@@ -68,6 +79,10 @@ end
|
|
68
79
|
|
69
80
|
|
70
81
|
|
82
|
+
# ---------------------------------------------------------------------
|
83
|
+
|
84
|
+
|
85
|
+
|
71
86
|
class ListTest < ActiveSupport::TestCase
|
72
87
|
|
73
88
|
def setup
|
@@ -231,6 +246,12 @@ class ListTest < ActiveSupport::TestCase
|
|
231
246
|
|
232
247
|
end
|
233
248
|
|
249
|
+
|
250
|
+
|
251
|
+
# ---------------------------------------------------------------------
|
252
|
+
|
253
|
+
|
254
|
+
|
234
255
|
class ListSubTest < ActiveSupport::TestCase
|
235
256
|
|
236
257
|
def setup
|
@@ -333,3 +354,9 @@ class ListSubTest < ActiveSupport::TestCase
|
|
333
354
|
end
|
334
355
|
|
335
356
|
end
|
357
|
+
|
358
|
+
|
359
|
+
|
360
|
+
# ---------------------------------------------------------------------
|
361
|
+
|
362
|
+
|
metadata
CHANGED
@@ -1,99 +1,76 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongo_mapper_acts_as_list
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.1
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 3
|
9
|
-
version: "0.3"
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Tomas Celizna
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
dependencies:
|
20
|
-
- !ruby/object:Gem::Dependency
|
21
|
-
type: :runtime
|
12
|
+
date: 2011-10-23 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
22
15
|
name: mongo_mapper
|
23
|
-
requirement: &
|
16
|
+
requirement: &70119513438580 !ruby/object:Gem::Requirement
|
24
17
|
none: false
|
25
|
-
requirements:
|
26
|
-
- -
|
27
|
-
- !ruby/object:Gem::Version
|
28
|
-
|
29
|
-
|
30
|
-
- 0
|
31
|
-
version: "0"
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
32
23
|
prerelease: false
|
33
|
-
version_requirements: *
|
34
|
-
- !ruby/object:Gem::Dependency
|
35
|
-
type: :development
|
24
|
+
version_requirements: *70119513438580
|
25
|
+
- !ruby/object:Gem::Dependency
|
36
26
|
name: rake
|
37
|
-
requirement: &
|
27
|
+
requirement: &70119513438100 !ruby/object:Gem::Requirement
|
38
28
|
none: false
|
39
|
-
requirements:
|
40
|
-
- -
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
|
43
|
-
|
44
|
-
- 0
|
45
|
-
version: "0"
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
46
34
|
prerelease: false
|
47
|
-
version_requirements: *
|
35
|
+
version_requirements: *70119513438100
|
48
36
|
description:
|
49
|
-
email:
|
37
|
+
email:
|
50
38
|
- tomas.celizna@gmail.com
|
51
39
|
executables: []
|
52
|
-
|
53
40
|
extensions: []
|
54
|
-
|
55
41
|
extra_rdoc_files: []
|
56
|
-
|
57
|
-
files:
|
42
|
+
files:
|
58
43
|
- lib/mongo_mapper/plugins/acts_as_list.rb
|
59
44
|
- lib/mongo_mapper/plugins/version.rb
|
60
45
|
- lib/mongo_mapper_acts_as_list.rb
|
61
46
|
- test/mongo_mapper_acts_as_list_test.rb
|
62
47
|
- test/test_helper.rb
|
63
48
|
- README.rdoc
|
64
|
-
has_rdoc: true
|
65
49
|
homepage: http://github.com/tomasc/mongo_mapper_acts_as_list
|
66
50
|
licenses: []
|
67
|
-
|
68
51
|
post_install_message:
|
69
52
|
rdoc_options: []
|
70
|
-
|
71
|
-
require_paths:
|
53
|
+
require_paths:
|
72
54
|
- lib
|
73
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
74
56
|
none: false
|
75
|
-
requirements:
|
76
|
-
- -
|
77
|
-
- !ruby/object:Gem::Version
|
78
|
-
|
79
|
-
segments:
|
57
|
+
requirements:
|
58
|
+
- - ! '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
segments:
|
80
62
|
- 0
|
81
|
-
|
82
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
hash: 3420355153011742463
|
64
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
65
|
none: false
|
84
|
-
requirements:
|
85
|
-
- -
|
86
|
-
- !ruby/object:Gem::Version
|
87
|
-
|
88
|
-
segments:
|
89
|
-
- 0
|
90
|
-
version: "0"
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
91
70
|
requirements: []
|
92
|
-
|
93
71
|
rubyforge_project:
|
94
|
-
rubygems_version: 1.
|
72
|
+
rubygems_version: 1.8.7
|
95
73
|
signing_key:
|
96
74
|
specification_version: 3
|
97
75
|
summary: Port of classic Rails ActsAsList for MongoMapper
|
98
76
|
test_files: []
|
99
|
-
|