mongoid-dsl 1.3.1 → 1.4.0
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/README.md +11 -0
- data/VERSION +1 -1
- data/lib/mongoid-dsl/doc.rb +74 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aee34566f05a375f7d79f2ac900dc145aa89d4b7
|
4
|
+
data.tar.gz: a9f7489aab61abd4bb01a4ee9f6d3eb966dcaa76
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a31d30c584b0e79418c02039088ef945713419257bd119fad1f50e1968996c98cb462cd7534e88eb67276aa642de22a030ceddb3401c22f6d171e53aee3d4830
|
7
|
+
data.tar.gz: 90f1a667bf7db4daa1c4a833ec56d99fa9172d6a706b514389e1eecb796a850a048ebb678500a840888f2e82b9526e5bdc87e19adacea7c6b4cee514ef3e50cc
|
data/README.md
CHANGED
@@ -111,6 +111,17 @@ The return object will be array if the target model is not a main one but an emb
|
|
111
111
|
Mongoid.purge!
|
112
112
|
|
113
113
|
|
114
|
+
```
|
115
|
+
|
116
|
+
As a plus, you can dump your mongoid models into a Hash Object,
|
117
|
+
that can be used to serialized as yaml and lend out as documentation if you lazy as me
|
118
|
+
|
119
|
+
```ruby
|
120
|
+
|
121
|
+
File.write "/tmp/#{$0}.model_dump.yml",
|
122
|
+
Mongoid.model_relations_dump.to_yaml
|
123
|
+
|
124
|
+
|
114
125
|
```
|
115
126
|
|
116
127
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.4.0
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module Mongoid
|
2
|
+
module DSL
|
3
|
+
|
4
|
+
module DumpHelper
|
5
|
+
def mongoid_relations_dump_parse(obj)
|
6
|
+
case obj
|
7
|
+
|
8
|
+
when Class
|
9
|
+
return {
|
10
|
+
obj.to_s => {
|
11
|
+
|
12
|
+
'relations' => {
|
13
|
+
'one' => obj.relations.map{ |name,attributes|
|
14
|
+
if attributes[:relation].to_s.downcase =~ /embedded::one$/
|
15
|
+
mongoid_relations_dump_parse name.convert_model_name
|
16
|
+
end
|
17
|
+
}.compact,
|
18
|
+
|
19
|
+
'many' => obj.relations.map{ |name,attributes|
|
20
|
+
if attributes[:relation].to_s.downcase =~ /embedded::many$/
|
21
|
+
mongoid_relations_dump_parse name.convert_model_name
|
22
|
+
elsif attributes[:relation].to_s.downcase =~ /referenced::many$/
|
23
|
+
name.convert_model_name.to_s
|
24
|
+
end
|
25
|
+
}.compact,
|
26
|
+
|
27
|
+
'manytomany' => obj.relations.map{ |name,attributes|
|
28
|
+
if attributes[:relation].to_s.downcase =~ /manytomany$/
|
29
|
+
name.convert_model_name.to_s
|
30
|
+
end
|
31
|
+
}.compact
|
32
|
+
}.select{ |k,v| !v.empty? },
|
33
|
+
'attributes' => obj.properties.reduce({}){|m,o| m.merge!(o[0] => o[1].to_s) ;m}
|
34
|
+
|
35
|
+
}.select{ |k,v| !v.empty? }
|
36
|
+
}
|
37
|
+
|
38
|
+
|
39
|
+
when Hash
|
40
|
+
return obj
|
41
|
+
|
42
|
+
when Array
|
43
|
+
obj.reduce({}) do |m,e|
|
44
|
+
case e
|
45
|
+
|
46
|
+
when Class
|
47
|
+
m.merge!(mongoid_relations_dump_parse(e))
|
48
|
+
|
49
|
+
when Hash
|
50
|
+
m.merge!(e)
|
51
|
+
|
52
|
+
else
|
53
|
+
m.merge!(e => nil)
|
54
|
+
|
55
|
+
end;m
|
56
|
+
end
|
57
|
+
|
58
|
+
else
|
59
|
+
return obj
|
60
|
+
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def model_relations_dump
|
65
|
+
mongoid_relations_dump_parse Mongoid.models.select{|klass| klass.parents.empty? }
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
extend DSL::DumpHelper
|
73
|
+
|
74
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongoid-dsl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Adam Luzsi
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-10-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -100,6 +100,7 @@ files:
|
|
100
100
|
- examples/include.rb
|
101
101
|
- examples/recursive_find.rb
|
102
102
|
- lib/mongoid-dsl.rb
|
103
|
+
- lib/mongoid-dsl/doc.rb
|
103
104
|
- lib/mongoid-dsl/fields-ext.rb
|
104
105
|
- lib/mongoid-dsl/monkey.rb
|
105
106
|
- mongoid-dsl.gemspec
|