mongoid-dsl 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/examples/helper/{con.rb → connection.rb} +2 -1
- data/examples/helper/models.rb +64 -0
- data/examples/include.rb +18 -0
- data/examples/recursive_find.rb +2 -67
- data/lib/mongoid-dsl/monkey.rb +13 -8
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 372d53d1aed4d20d50950a902a1afc589e63ad38
|
4
|
+
data.tar.gz: 3ff39915be54309d206c31f0f32ab706b4de2e22
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a86d8aab7e0013a166222f6d2b9fdb77757d4205eefefee51864a93063bec01758f1b7cec61cf6affec5703c098b1954f41a52d22dfc69bf33a3e76550d82f06
|
7
|
+
data.tar.gz: 445636d49a606e87561b1cd168b23fb23846e625027ea99aacbca08ca746e079f14f78bc0599d171df52643065fa5e07249c52c84262e1a92cf2b679df36a5d0
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.2
|
@@ -1 +1,2 @@
|
|
1
|
-
Mongoid.load!(File.join(File.dirname(__FILE__),"mongoid.yml"), :development)
|
1
|
+
Mongoid.load!(File.join(File.dirname(__FILE__),"mongoid.yml"), :development)
|
2
|
+
I18n.enforce_available_locales = false
|
@@ -0,0 +1,64 @@
|
|
1
|
+
|
2
|
+
class TestA
|
3
|
+
|
4
|
+
include Mongoid::Document
|
5
|
+
include Mongoid::Timestamps
|
6
|
+
include Mongoid::CRUD
|
7
|
+
|
8
|
+
store_in :collection => self.mongoid_name
|
9
|
+
|
10
|
+
embeds_many :TestB.mongoid_name
|
11
|
+
|
12
|
+
# field :test,
|
13
|
+
# :type => String,
|
14
|
+
# :presence => true,
|
15
|
+
# :desc => "description for this field",
|
16
|
+
# :accept_only => %W[ hello world hello\ world ]
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
class TestB
|
21
|
+
|
22
|
+
include Mongoid::Document
|
23
|
+
include Mongoid::Timestamps
|
24
|
+
include Mongoid::CRUD
|
25
|
+
|
26
|
+
embedded_in :TestA.mongoid_name
|
27
|
+
embeds_many :TestC.mongoid_name
|
28
|
+
|
29
|
+
# field :test,
|
30
|
+
# :type => String,
|
31
|
+
# :presence => true,
|
32
|
+
# :desc => "description for this field",
|
33
|
+
# :uniq => true
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
class TestC
|
38
|
+
|
39
|
+
include Mongoid::Document
|
40
|
+
include Mongoid::Timestamps
|
41
|
+
|
42
|
+
embedded_in :TestB.mongoid_name
|
43
|
+
embeds_many :TestD.mongoid_name
|
44
|
+
|
45
|
+
field :test,
|
46
|
+
:type => String,
|
47
|
+
:presence => true,
|
48
|
+
:desc => "description for this field"
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
class TestD
|
53
|
+
|
54
|
+
include Mongoid::Document
|
55
|
+
include Mongoid::Timestamps
|
56
|
+
|
57
|
+
embedded_in :TestC.mongoid_name
|
58
|
+
|
59
|
+
field :test,
|
60
|
+
:type => String,
|
61
|
+
:presence => true,
|
62
|
+
:desc => "description for this field"
|
63
|
+
|
64
|
+
end
|
data/examples/include.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require_relative "../lib/mongoid-dsl"
|
2
|
+
require_relative "helper/connection"
|
3
|
+
|
4
|
+
class TestD
|
5
|
+
|
6
|
+
include Mongoid::Document
|
7
|
+
include Mongoid::Timestamps
|
8
|
+
|
9
|
+
# for manual include but by default after require the module it will happen on the fly!
|
10
|
+
include Mongoid::DSL
|
11
|
+
|
12
|
+
store_in :collection => self.mongoid_name
|
13
|
+
|
14
|
+
field :test,
|
15
|
+
:type => String,
|
16
|
+
:desc => "description for this field"
|
17
|
+
|
18
|
+
end
|
data/examples/recursive_find.rb
CHANGED
@@ -1,71 +1,6 @@
|
|
1
1
|
require_relative "../lib/mongoid-dsl"
|
2
|
-
require_relative "helper/
|
3
|
-
|
4
|
-
:TestA.mongoid_name #> nil
|
5
|
-
|
6
|
-
class TestA
|
7
|
-
|
8
|
-
include Mongoid::Document
|
9
|
-
include Mongoid::Timestamps
|
10
|
-
|
11
|
-
store_in :collection => self.mongoid_name
|
12
|
-
|
13
|
-
embeds_many :TestB.mongoid_name
|
14
|
-
|
15
|
-
field :test,
|
16
|
-
:type => String,
|
17
|
-
:presence => true,
|
18
|
-
:desc => "description for this field",
|
19
|
-
:accept_only => %W[ hello world hello\ world ]
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
:TestA.mongoid_name #> "test_a"
|
24
|
-
|
25
|
-
class TestB
|
26
|
-
|
27
|
-
include Mongoid::Document
|
28
|
-
include Mongoid::Timestamps
|
29
|
-
|
30
|
-
embedded_in :TestA.mongoid_name
|
31
|
-
embeds_many :TestC.mongoid_name
|
32
|
-
|
33
|
-
field :test,
|
34
|
-
:type => String,
|
35
|
-
:presence => true,
|
36
|
-
:desc => "description for this field",
|
37
|
-
:uniq => true
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
class TestC
|
42
|
-
|
43
|
-
include Mongoid::Document
|
44
|
-
include Mongoid::Timestamps
|
45
|
-
|
46
|
-
embedded_in :TestB.mongoid_name
|
47
|
-
embeds_many :TestD.mongoid_name
|
48
|
-
|
49
|
-
field :test,
|
50
|
-
:type => String,
|
51
|
-
:presence => true,
|
52
|
-
:desc => "description for this field"
|
53
|
-
|
54
|
-
end
|
55
|
-
|
56
|
-
class TestD
|
57
|
-
|
58
|
-
include Mongoid::Document
|
59
|
-
include Mongoid::Timestamps
|
60
|
-
|
61
|
-
embedded_in :TestC.mongoid_name
|
62
|
-
|
63
|
-
field :test,
|
64
|
-
:type => String,
|
65
|
-
:presence => true,
|
66
|
-
:desc => "description for this field"
|
67
|
-
|
68
|
-
end
|
2
|
+
require_relative "helper/connection"
|
3
|
+
require_relative "helper/models"
|
69
4
|
|
70
5
|
test_a= TestA.create! test: "hello"
|
71
6
|
test_a.test_b.create(test: "world")
|
data/lib/mongoid-dsl/monkey.rb
CHANGED
@@ -74,11 +74,6 @@ module Mongoid
|
|
74
74
|
end
|
75
75
|
end
|
76
76
|
|
77
|
-
#> not yet finished
|
78
|
-
def available_fields
|
79
|
-
Mongoid::Document.available_fields(self)
|
80
|
-
end
|
81
|
-
|
82
77
|
def properties
|
83
78
|
|
84
79
|
hash_data = Hash.new
|
@@ -125,7 +120,7 @@ module Mongoid
|
|
125
120
|
end
|
126
121
|
end
|
127
122
|
|
128
|
-
def
|
123
|
+
def _get_class_path(*included)
|
129
124
|
|
130
125
|
# create defaults
|
131
126
|
begin
|
@@ -322,7 +317,7 @@ module Mongoid
|
|
322
317
|
# mother model find, and path generate
|
323
318
|
begin
|
324
319
|
|
325
|
-
full_path = self.
|
320
|
+
full_path = self._get_class_path(*models_container) || Array.new.push(self)
|
326
321
|
mother_model= full_path.shift
|
327
322
|
|
328
323
|
full_path.count.times do |index|
|
@@ -622,14 +617,24 @@ module Mongoid
|
|
622
617
|
|
623
618
|
end
|
624
619
|
|
620
|
+
# for manual include
|
621
|
+
begin
|
622
|
+
self.__send__ :include, Mongoid::DSL::Document::Include
|
623
|
+
def self.included klass
|
624
|
+
klass.__send__ :extend,Mongoid::DSL::Document::Extend
|
625
|
+
end
|
626
|
+
end
|
627
|
+
|
625
628
|
end
|
626
629
|
end
|
627
630
|
|
628
631
|
begin
|
632
|
+
|
629
633
|
Mongoid::Config.inject_singleton_method :register_model, add: :before do |klass|
|
630
634
|
klass.__send__ :extend, Mongoid::DSL::Document::Extend
|
631
635
|
klass.__send__ :include, Mongoid::DSL::Document::Include
|
632
636
|
end
|
637
|
+
|
633
638
|
rescue NoMethodError
|
634
639
|
end
|
635
640
|
|
@@ -642,4 +647,4 @@ end
|
|
642
647
|
class_name.__send__ :include, Mongoid::DSL::CoreExt::Include
|
643
648
|
end
|
644
649
|
|
645
|
-
String.__send__ :include, Mongoid::DSL::StringExt::Include
|
650
|
+
String.__send__ :include, Mongoid::DSL::StringExt::Include
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-dsl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Luzsi
|
@@ -94,8 +94,10 @@ files:
|
|
94
94
|
- README.md
|
95
95
|
- Rakefile
|
96
96
|
- VERSION
|
97
|
-
- examples/helper/
|
97
|
+
- examples/helper/connection.rb
|
98
|
+
- examples/helper/models.rb
|
98
99
|
- examples/helper/mongoid.yml
|
100
|
+
- examples/include.rb
|
99
101
|
- examples/recursive_find.rb
|
100
102
|
- lib/mongoid-dsl.rb
|
101
103
|
- lib/mongoid-dsl/fields-ext.rb
|