glebtv-mongoid_nested_set 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+
2
+ class RenamedFields
3
+ include Mongoid::Document
4
+ acts_as_nested_set :parent_field => 'mother_id', :left_field => 'red', :right_field => 'black'
5
+
6
+ field :name
7
+ end
@@ -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,4 @@
1
+ require "#{File.dirname(__FILE__)}/shape_node"
2
+
3
+ class SquareNode < ShapeNode
4
+ 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
@@ -0,0 +1,9 @@
1
+ require "#{File.dirname(__FILE__)}/test_document"
2
+
3
+ class UnscopedNode
4
+ include Mongoid::Document
5
+ include Mongoid::Acts::NestedSet::TestDocument
6
+ acts_as_nested_set
7
+
8
+ field :name
9
+ end