glebtv-mongoid_nested_set 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.document +5 -0
- data/.gitignore +44 -0
- data/.rspec +1 -0
- data/Gemfile +10 -0
- data/LICENSE.txt +20 -0
- data/README.markdown +147 -0
- data/Rakefile +1 -0
- data/glebtv-mongoid_nested_set.gemspec +29 -0
- data/lib/glebtv-mongoid_nested_set.rb +1 -0
- data/lib/mongoid_nested_set/base.rb +90 -0
- data/lib/mongoid_nested_set/document.rb +238 -0
- data/lib/mongoid_nested_set/fields.rb +60 -0
- data/lib/mongoid_nested_set/outline_number.rb +122 -0
- data/lib/mongoid_nested_set/rebuild.rb +40 -0
- data/lib/mongoid_nested_set/relations.rb +100 -0
- data/lib/mongoid_nested_set/remove_order_by.rb +15 -0
- data/lib/mongoid_nested_set/update.rb +230 -0
- data/lib/mongoid_nested_set/validation.rb +59 -0
- data/lib/mongoid_nested_set/version.rb +3 -0
- data/lib/mongoid_nested_set.rb +40 -0
- data/spec/matchers/nestedset_pos.rb +46 -0
- data/spec/models/circle_node.rb +4 -0
- data/spec/models/node.rb +10 -0
- data/spec/models/node_without_nested_set.rb +6 -0
- data/spec/models/numbering_node.rb +10 -0
- data/spec/models/renamed_fields.rb +7 -0
- data/spec/models/shape_node.rb +18 -0
- data/spec/models/square_node.rb +4 -0
- data/spec/models/test_document.rb +36 -0
- data/spec/models/unscoped_node.rb +9 -0
- data/spec/mongoid_nested_set_spec.rb +786 -0
- data/spec/spec_helper.rb +43 -0
- metadata +147 -0
@@ -0,0 +1,18 @@
|
|
1
|
+
require "#{File.dirname(__FILE__)}/test_document"
|
2
|
+
|
3
|
+
class ShapeNode
|
4
|
+
include Mongoid::Document
|
5
|
+
include Mongoid::Acts::NestedSet::TestDocument
|
6
|
+
acts_as_nested_set
|
7
|
+
|
8
|
+
field :name
|
9
|
+
|
10
|
+
def test_set_attributes(attrs)
|
11
|
+
@attributes.update(attrs)
|
12
|
+
self
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.test_set_dependent_option(val)
|
16
|
+
self.acts_as_nested_set_options[:dependent] = val
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Mongoid::Acts::NestedSet
|
2
|
+
|
3
|
+
module TestDocument
|
4
|
+
|
5
|
+
def self.included(base)
|
6
|
+
base.extend(ClassMethods)
|
7
|
+
base.send(:include, InstanceMethods)
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
|
13
|
+
def test_set_dependent_option(val)
|
14
|
+
self.acts_as_nested_set_options[:dependent] = val
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
module InstanceMethods
|
21
|
+
|
22
|
+
def test_set_attributes(attrs)
|
23
|
+
attrs.each do |key, val|
|
24
|
+
key = key.to_s
|
25
|
+
if Mongoid.allow_dynamic_fields ||
|
26
|
+
fields.keys.any? { |k| k.to_s == key } ||
|
27
|
+
associations.any? { |a| a[0].to_s == key || a[1].foreign_key.to_s == key }
|
28
|
+
@attributes[key] = fields[key].mongoize(val)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
self
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|