mongoid-tree-rational 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +2 -0
- data/.travis.yml +12 -0
- data/Gemfile +23 -0
- data/Guardfile +6 -0
- data/LICENSE +21 -0
- data/README.md +287 -0
- data/Rakefile +63 -0
- data/VERSION +1 -0
- data/lib/mongoid/locale/en.yml +11 -0
- data/lib/mongoid/locale/nb.yml +8 -0
- data/lib/mongoid/tree.rb +443 -0
- data/lib/mongoid/tree/ordering.rb +236 -0
- data/lib/mongoid/tree/rational_numbering.rb +805 -0
- data/lib/mongoid/tree/traversal.rb +122 -0
- data/mongoid-tree-rational.gemspec +103 -0
- data/spec/mongoid/tree/ordering_spec.rb +342 -0
- data/spec/mongoid/tree/rational_numbering_spec.rb +765 -0
- data/spec/mongoid/tree/traversal_spec.rb +177 -0
- data/spec/mongoid/tree_spec.rb +444 -0
- data/spec/spec_helper.rb +31 -0
- data/spec/support/macros/tree_macros.rb +53 -0
- data/spec/support/models/node.rb +47 -0
- metadata +320 -0
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler/setup'
|
3
|
+
|
4
|
+
require 'mongoid'
|
5
|
+
require 'mongoid/tree'
|
6
|
+
|
7
|
+
require 'rspec'
|
8
|
+
|
9
|
+
if ENV['TRAVIS']
|
10
|
+
require 'coveralls'
|
11
|
+
Coveralls.wear!
|
12
|
+
elsif ENV['COVERAGE'] && RUBY_VERSION > "1.8"
|
13
|
+
require 'simplecov'
|
14
|
+
SimpleCov.start do
|
15
|
+
add_filter 'spec'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
Mongoid.configure do |config|
|
20
|
+
config.connect_to('mongoid_tree_test')
|
21
|
+
end
|
22
|
+
|
23
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
24
|
+
|
25
|
+
RSpec.configure do |config|
|
26
|
+
config.expect_with :rspec do |c|
|
27
|
+
c.syntax = :expect
|
28
|
+
end
|
29
|
+
config.mock_with :rspec
|
30
|
+
config.after(:each) { Mongoid.purge! }
|
31
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'yaml'
|
2
|
+
|
3
|
+
module Mongoid::Tree::TreeMacros
|
4
|
+
|
5
|
+
def setup_tree(tree)
|
6
|
+
create_tree(YAML.load(tree))
|
7
|
+
end
|
8
|
+
|
9
|
+
def node(name)
|
10
|
+
@nodes[name].reload
|
11
|
+
end
|
12
|
+
|
13
|
+
def print_tree(node, inspect = false, depth = 0)
|
14
|
+
print ' ' * depth
|
15
|
+
print '- ' unless depth == 0
|
16
|
+
print node.name
|
17
|
+
print " (#{node.inspect})" if inspect
|
18
|
+
print ':' if node.children.any?
|
19
|
+
print "\n"
|
20
|
+
node.children.each { |c| print_tree(c, inspect, depth + 1) }
|
21
|
+
end
|
22
|
+
|
23
|
+
def print_rational_tree(node, inspect = false, depth = 0)
|
24
|
+
print ' ' * depth
|
25
|
+
print '- ' unless depth == 0
|
26
|
+
print "#{node.name} - pos: #{node.position} nv/dv: #{node.rational_number_nv}/#{node.rational_number_dv} snv/dnv: #{node.rational_number_snv}/#{node.rational_number_sdv}"
|
27
|
+
print " (#{node.inspect})" if inspect
|
28
|
+
print "\n"
|
29
|
+
node.children.each { |c| print_rational_tree(c, inspect, depth + 1) }
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
def create_tree(object)
|
34
|
+
case object
|
35
|
+
when String then return create_node(object)
|
36
|
+
when Array then object.each { |tree| create_tree(tree) }
|
37
|
+
when Hash then
|
38
|
+
name, children = object.first
|
39
|
+
node = create_node(name)
|
40
|
+
children.each { |c| node.children << create_tree(c) }
|
41
|
+
return node
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def create_node(name)
|
46
|
+
@nodes ||= HashWithIndifferentAccess.new
|
47
|
+
@nodes[name] = subject.create(:name => name)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
RSpec.configure do |config|
|
52
|
+
config.include Mongoid::Tree::TreeMacros
|
53
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
class Node
|
2
|
+
include Mongoid::Document
|
3
|
+
include Mongoid::Tree
|
4
|
+
include Mongoid::Tree::Traversal
|
5
|
+
|
6
|
+
field :name
|
7
|
+
|
8
|
+
attr_accessible :name
|
9
|
+
end
|
10
|
+
|
11
|
+
class SubclassedNode < Node
|
12
|
+
end
|
13
|
+
|
14
|
+
# Adding ordering on subclasses currently doesn't work as expected.
|
15
|
+
#
|
16
|
+
# class OrderedNode < Node
|
17
|
+
# include Mongoid::Tree::Ordering
|
18
|
+
# end
|
19
|
+
class OrderedNode
|
20
|
+
include Mongoid::Document
|
21
|
+
include Mongoid::Tree
|
22
|
+
include Mongoid::Tree::Traversal
|
23
|
+
include Mongoid::Tree::Ordering
|
24
|
+
|
25
|
+
field :name
|
26
|
+
|
27
|
+
attr_accessible :name
|
28
|
+
end
|
29
|
+
|
30
|
+
class NodeWithEmbeddedDocument < Node
|
31
|
+
embeds_one :embedded_document, :cascade_callbacks => true
|
32
|
+
end
|
33
|
+
|
34
|
+
class EmbeddedDocument
|
35
|
+
include Mongoid::Document
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
class RationalNumberedNode
|
40
|
+
include Mongoid::Document
|
41
|
+
include Mongoid::Tree
|
42
|
+
include Mongoid::Tree::RationalNumbering
|
43
|
+
|
44
|
+
field :name
|
45
|
+
|
46
|
+
attr_accessible :name
|
47
|
+
end
|
metadata
ADDED
@@ -0,0 +1,320 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mongoid-tree-rational
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Leif Ringstad
|
9
|
+
- Benedikt Deicke
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
date: 2013-10-09 00:00:00.000000000 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: mongoid
|
17
|
+
requirement: !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - <=
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '4.0'
|
23
|
+
- - ! '>='
|
24
|
+
- !ruby/object:Gem::Version
|
25
|
+
version: '3.0'
|
26
|
+
type: :runtime
|
27
|
+
prerelease: false
|
28
|
+
version_requirements: !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - <=
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.0'
|
34
|
+
- - ! '>='
|
35
|
+
- !ruby/object:Gem::Version
|
36
|
+
version: '3.0'
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: rational_number
|
39
|
+
requirement: !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
type: :runtime
|
46
|
+
prerelease: false
|
47
|
+
version_requirements: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
49
|
+
requirements:
|
50
|
+
- - ! '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: rake
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ! '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
type: :development
|
62
|
+
prerelease: false
|
63
|
+
version_requirements: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rspec
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
none: false
|
73
|
+
requirements:
|
74
|
+
- - ! '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
none: false
|
81
|
+
requirements:
|
82
|
+
- - ! '>='
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
- !ruby/object:Gem::Dependency
|
86
|
+
name: yard
|
87
|
+
requirement: !ruby/object:Gem::Requirement
|
88
|
+
none: false
|
89
|
+
requirements:
|
90
|
+
- - ! '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
type: :development
|
94
|
+
prerelease: false
|
95
|
+
version_requirements: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ! '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
- !ruby/object:Gem::Dependency
|
102
|
+
name: jeweler
|
103
|
+
requirement: !ruby/object:Gem::Requirement
|
104
|
+
none: false
|
105
|
+
requirements:
|
106
|
+
- - ! '>='
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
type: :development
|
110
|
+
prerelease: false
|
111
|
+
version_requirements: !ruby/object:Gem::Requirement
|
112
|
+
none: false
|
113
|
+
requirements:
|
114
|
+
- - ! '>='
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
- !ruby/object:Gem::Dependency
|
118
|
+
name: guard-rspec
|
119
|
+
requirement: !ruby/object:Gem::Requirement
|
120
|
+
none: false
|
121
|
+
requirements:
|
122
|
+
- - ! '>='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 2.6.0
|
125
|
+
type: :development
|
126
|
+
prerelease: false
|
127
|
+
version_requirements: !ruby/object:Gem::Requirement
|
128
|
+
none: false
|
129
|
+
requirements:
|
130
|
+
- - ! '>='
|
131
|
+
- !ruby/object:Gem::Version
|
132
|
+
version: 2.6.0
|
133
|
+
- !ruby/object:Gem::Dependency
|
134
|
+
name: rb-inotify
|
135
|
+
requirement: !ruby/object:Gem::Requirement
|
136
|
+
none: false
|
137
|
+
requirements:
|
138
|
+
- - ! '>='
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
type: :development
|
142
|
+
prerelease: false
|
143
|
+
version_requirements: !ruby/object:Gem::Requirement
|
144
|
+
none: false
|
145
|
+
requirements:
|
146
|
+
- - ! '>='
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
- !ruby/object:Gem::Dependency
|
150
|
+
name: rb-fsevent
|
151
|
+
requirement: !ruby/object:Gem::Requirement
|
152
|
+
none: false
|
153
|
+
requirements:
|
154
|
+
- - ! '>='
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: '0'
|
157
|
+
type: :development
|
158
|
+
prerelease: false
|
159
|
+
version_requirements: !ruby/object:Gem::Requirement
|
160
|
+
none: false
|
161
|
+
requirements:
|
162
|
+
- - ! '>='
|
163
|
+
- !ruby/object:Gem::Version
|
164
|
+
version: '0'
|
165
|
+
- !ruby/object:Gem::Dependency
|
166
|
+
name: wdm
|
167
|
+
requirement: !ruby/object:Gem::Requirement
|
168
|
+
none: false
|
169
|
+
requirements:
|
170
|
+
- - ! '>='
|
171
|
+
- !ruby/object:Gem::Version
|
172
|
+
version: '0'
|
173
|
+
type: :development
|
174
|
+
prerelease: false
|
175
|
+
version_requirements: !ruby/object:Gem::Requirement
|
176
|
+
none: false
|
177
|
+
requirements:
|
178
|
+
- - ! '>='
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
- !ruby/object:Gem::Dependency
|
182
|
+
name: hirb
|
183
|
+
requirement: !ruby/object:Gem::Requirement
|
184
|
+
none: false
|
185
|
+
requirements:
|
186
|
+
- - ! '>='
|
187
|
+
- !ruby/object:Gem::Version
|
188
|
+
version: '0'
|
189
|
+
type: :development
|
190
|
+
prerelease: false
|
191
|
+
version_requirements: !ruby/object:Gem::Requirement
|
192
|
+
none: false
|
193
|
+
requirements:
|
194
|
+
- - ! '>='
|
195
|
+
- !ruby/object:Gem::Version
|
196
|
+
version: '0'
|
197
|
+
- !ruby/object:Gem::Dependency
|
198
|
+
name: wirble
|
199
|
+
requirement: !ruby/object:Gem::Requirement
|
200
|
+
none: false
|
201
|
+
requirements:
|
202
|
+
- - ! '>='
|
203
|
+
- !ruby/object:Gem::Version
|
204
|
+
version: '0'
|
205
|
+
type: :development
|
206
|
+
prerelease: false
|
207
|
+
version_requirements: !ruby/object:Gem::Requirement
|
208
|
+
none: false
|
209
|
+
requirements:
|
210
|
+
- - ! '>='
|
211
|
+
- !ruby/object:Gem::Version
|
212
|
+
version: '0'
|
213
|
+
- !ruby/object:Gem::Dependency
|
214
|
+
name: awesome_print
|
215
|
+
requirement: !ruby/object:Gem::Requirement
|
216
|
+
none: false
|
217
|
+
requirements:
|
218
|
+
- - ! '>='
|
219
|
+
- !ruby/object:Gem::Version
|
220
|
+
version: '0'
|
221
|
+
type: :development
|
222
|
+
prerelease: false
|
223
|
+
version_requirements: !ruby/object:Gem::Requirement
|
224
|
+
none: false
|
225
|
+
requirements:
|
226
|
+
- - ! '>='
|
227
|
+
- !ruby/object:Gem::Version
|
228
|
+
version: '0'
|
229
|
+
- !ruby/object:Gem::Dependency
|
230
|
+
name: coveralls
|
231
|
+
requirement: !ruby/object:Gem::Requirement
|
232
|
+
none: false
|
233
|
+
requirements:
|
234
|
+
- - ! '>='
|
235
|
+
- !ruby/object:Gem::Version
|
236
|
+
version: '0'
|
237
|
+
type: :development
|
238
|
+
prerelease: false
|
239
|
+
version_requirements: !ruby/object:Gem::Requirement
|
240
|
+
none: false
|
241
|
+
requirements:
|
242
|
+
- - ! '>='
|
243
|
+
- !ruby/object:Gem::Version
|
244
|
+
version: '0'
|
245
|
+
- !ruby/object:Gem::Dependency
|
246
|
+
name: simplecov
|
247
|
+
requirement: !ruby/object:Gem::Requirement
|
248
|
+
none: false
|
249
|
+
requirements:
|
250
|
+
- - ! '>='
|
251
|
+
- !ruby/object:Gem::Version
|
252
|
+
version: '0'
|
253
|
+
type: :development
|
254
|
+
prerelease: false
|
255
|
+
version_requirements: !ruby/object:Gem::Requirement
|
256
|
+
none: false
|
257
|
+
requirements:
|
258
|
+
- - ! '>='
|
259
|
+
- !ruby/object:Gem::Version
|
260
|
+
version: '0'
|
261
|
+
description: A tree structure for Mongoid documents using the materialized path pattern
|
262
|
+
and rational number sorting.
|
263
|
+
email: leifcr@gmail.com
|
264
|
+
executables: []
|
265
|
+
extensions: []
|
266
|
+
extra_rdoc_files:
|
267
|
+
- LICENSE
|
268
|
+
- README.md
|
269
|
+
files:
|
270
|
+
- .rspec
|
271
|
+
- .travis.yml
|
272
|
+
- Gemfile
|
273
|
+
- Guardfile
|
274
|
+
- LICENSE
|
275
|
+
- README.md
|
276
|
+
- Rakefile
|
277
|
+
- VERSION
|
278
|
+
- lib/mongoid/locale/en.yml
|
279
|
+
- lib/mongoid/locale/nb.yml
|
280
|
+
- lib/mongoid/tree.rb
|
281
|
+
- lib/mongoid/tree/ordering.rb
|
282
|
+
- lib/mongoid/tree/rational_numbering.rb
|
283
|
+
- lib/mongoid/tree/traversal.rb
|
284
|
+
- mongoid-tree-rational.gemspec
|
285
|
+
- spec/mongoid/tree/ordering_spec.rb
|
286
|
+
- spec/mongoid/tree/rational_numbering_spec.rb
|
287
|
+
- spec/mongoid/tree/traversal_spec.rb
|
288
|
+
- spec/mongoid/tree_spec.rb
|
289
|
+
- spec/spec_helper.rb
|
290
|
+
- spec/support/macros/tree_macros.rb
|
291
|
+
- spec/support/models/node.rb
|
292
|
+
homepage: https://github.com/boxcms/mongoid-tree-rational
|
293
|
+
licenses:
|
294
|
+
- MIT
|
295
|
+
post_install_message:
|
296
|
+
rdoc_options: []
|
297
|
+
require_paths:
|
298
|
+
- lib
|
299
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
300
|
+
none: false
|
301
|
+
requirements:
|
302
|
+
- - ! '>='
|
303
|
+
- !ruby/object:Gem::Version
|
304
|
+
version: '0'
|
305
|
+
segments:
|
306
|
+
- 0
|
307
|
+
hash: -552489557788164545
|
308
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
309
|
+
none: false
|
310
|
+
requirements:
|
311
|
+
- - ! '>='
|
312
|
+
- !ruby/object:Gem::Version
|
313
|
+
version: '0'
|
314
|
+
requirements: []
|
315
|
+
rubyforge_project:
|
316
|
+
rubygems_version: 1.8.25
|
317
|
+
signing_key:
|
318
|
+
specification_version: 3
|
319
|
+
summary: A tree structure for Mongoid documents with rational numbers
|
320
|
+
test_files: []
|