clone 1.0.0.alpha → 1.0.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/Gemfile +1 -0
- data/LICENSE.txt +22 -0
- data/README.md +22 -1
- data/VERSION +1 -1
- data/bin/clone +7 -0
- data/clone.gemspec +4 -0
- data/docs/readme +16 -0
- data/docs/readme.txt +5 -0
- data/lib/clone.rb +13 -2
- data/lib/clone/config/config.rb +19 -0
- data/lib/clone/config/config.yml +22 -0
- data/lib/clone/config/default_config.yml +20 -0
- data/lib/clone/config/require.rb +3 -0
- data/lib/clone/config/version.rb +10 -0
- data/lib/clone/config/yml.rb +22 -0
- data/lib/clone/config/z_defaults.rb +28 -0
- data/lib/clone/generator/engine.rb +581 -0
- data/lib/clone/generator/terminal.rb +104 -0
- data/lib/clone/helpers/helper_methods.rb +251 -0
- data/lib/clone/helpers/local_methods.rb +150 -0
- data/lib/clone/helpers/require.rb +37 -0
- data/module/Marshal.4.8 +0 -0
- data/module/Marshal.4.8.Z +0 -0
- data/module/gems/commander-4.1.3/.gitignore +6 -0
- data/module/gems/commander-4.1.3/.travis.yml +11 -0
- data/module/gems/commander-4.1.3/DEVELOPMENT +15 -0
- data/module/gems/commander-4.1.3/Gemfile +3 -0
- data/module/gems/commander-4.1.3/History.rdoc +345 -0
- data/module/gems/commander-4.1.3/Manifest +38 -0
- data/module/gems/commander-4.1.3/README.rdoc +375 -0
- data/module/gems/commander-4.1.3/Rakefile +10 -0
- data/module/gems/commander-4.1.3/bin/commander +55 -0
- data/module/gems/commander-4.1.3/commander.gemspec +26 -0
- data/module/gems/commander-4.1.3/lib/commander.rb +32 -0
- data/module/gems/commander-4.1.3/lib/commander/blank.rb +8 -0
- data/module/gems/commander-4.1.3/lib/commander/command.rb +213 -0
- data/module/gems/commander-4.1.3/lib/commander/core_ext.rb +3 -0
- data/module/gems/commander-4.1.3/lib/commander/core_ext/array.rb +26 -0
- data/module/gems/commander-4.1.3/lib/commander/core_ext/object.rb +11 -0
- data/module/gems/commander-4.1.3/lib/commander/delegates.rb +13 -0
- data/module/gems/commander-4.1.3/lib/commander/help_formatters.rb +8 -0
- data/module/gems/commander-4.1.3/lib/commander/help_formatters/base.rb +18 -0
- data/module/gems/commander-4.1.3/lib/commander/help_formatters/terminal.rb +20 -0
- data/module/gems/commander-4.1.3/lib/commander/help_formatters/terminal/command_help.erb +35 -0
- data/module/gems/commander-4.1.3/lib/commander/help_formatters/terminal/help.erb +36 -0
- data/module/gems/commander-4.1.3/lib/commander/help_formatters/terminal_compact.rb +12 -0
- data/module/gems/commander-4.1.3/lib/commander/help_formatters/terminal_compact/command_help.erb +27 -0
- data/module/gems/commander-4.1.3/lib/commander/help_formatters/terminal_compact/help.erb +29 -0
- data/module/gems/commander-4.1.3/lib/commander/import.rb +10 -0
- data/module/gems/commander-4.1.3/lib/commander/platform.rb +8 -0
- data/module/gems/commander-4.1.3/lib/commander/runner.rb +411 -0
- data/module/gems/commander-4.1.3/lib/commander/user_interaction.rb +521 -0
- data/module/gems/commander-4.1.3/lib/commander/version.rb +3 -0
- data/module/gems/commander-4.1.3/spec/command_spec.rb +157 -0
- data/module/gems/commander-4.1.3/spec/core_ext/array_spec.rb +20 -0
- data/module/gems/commander-4.1.3/spec/core_ext/object_spec.rb +21 -0
- data/module/gems/commander-4.1.3/spec/help_formatters/terminal_spec.rb +67 -0
- data/module/gems/commander-4.1.3/spec/runner_spec.rb +526 -0
- data/module/gems/commander-4.1.3/spec/spec_helper.rb +59 -0
- data/module/gems/commander-4.1.3/spec/ui_spec.rb +30 -0
- data/module/gems/hello.rb +1 -0
- data/module/gems/highline-1.6.19/.gitignore +2 -0
- data/module/gems/highline-1.6.19/AUTHORS +3 -0
- data/module/gems/highline-1.6.19/CHANGELOG +346 -0
- data/module/gems/highline-1.6.19/COPYING +340 -0
- data/module/gems/highline-1.6.19/INSTALL +55 -0
- data/module/gems/highline-1.6.19/LICENSE +7 -0
- data/module/gems/highline-1.6.19/README.rdoc +63 -0
- data/module/gems/highline-1.6.19/Rakefile +50 -0
- data/module/gems/highline-1.6.19/TODO +6 -0
- data/module/gems/highline-1.6.19/examples/ansi_colors.rb +38 -0
- data/module/gems/highline-1.6.19/examples/asking_for_arrays.rb +18 -0
- data/module/gems/highline-1.6.19/examples/basic_usage.rb +75 -0
- data/module/gems/highline-1.6.19/examples/color_scheme.rb +32 -0
- data/module/gems/highline-1.6.19/examples/get_character.rb +12 -0
- data/module/gems/highline-1.6.19/examples/limit.rb +12 -0
- data/module/gems/highline-1.6.19/examples/menus.rb +65 -0
- data/module/gems/highline-1.6.19/examples/overwrite.rb +19 -0
- data/module/gems/highline-1.6.19/examples/page_and_wrap.rb +322 -0
- data/module/gems/highline-1.6.19/examples/password.rb +7 -0
- data/module/gems/highline-1.6.19/examples/repeat_entry.rb +21 -0
- data/module/gems/highline-1.6.19/examples/trapping_eof.rb +22 -0
- data/module/gems/highline-1.6.19/examples/using_readline.rb +17 -0
- data/module/gems/highline-1.6.19/highline.gemspec +37 -0
- data/module/gems/highline-1.6.19/lib/highline.rb +1012 -0
- data/module/gems/highline-1.6.19/lib/highline/color_scheme.rb +134 -0
- data/module/gems/highline-1.6.19/lib/highline/compatibility.rb +16 -0
- data/module/gems/highline-1.6.19/lib/highline/import.rb +41 -0
- data/module/gems/highline-1.6.19/lib/highline/menu.rb +398 -0
- data/module/gems/highline-1.6.19/lib/highline/question.rb +475 -0
- data/module/gems/highline-1.6.19/lib/highline/simulate.rb +48 -0
- data/module/gems/highline-1.6.19/lib/highline/string_extensions.rb +131 -0
- data/module/gems/highline-1.6.19/lib/highline/style.rb +181 -0
- data/module/gems/highline-1.6.19/lib/highline/system_extensions.rb +222 -0
- data/module/gems/highline-1.6.19/setup.rb +1360 -0
- data/module/gems/highline-1.6.19/site/.cvsignore +1 -0
- data/module/gems/highline-1.6.19/site/highline.css +65 -0
- data/module/gems/highline-1.6.19/site/images/logo.png +0 -0
- data/module/gems/highline-1.6.19/site/index.html +58 -0
- data/module/gems/highline-1.6.19/test/string_methods.rb +32 -0
- data/module/gems/highline-1.6.19/test/tc_color_scheme.rb +96 -0
- data/module/gems/highline-1.6.19/test/tc_highline.rb +1128 -0
- data/module/gems/highline-1.6.19/test/tc_import.rb +52 -0
- data/module/gems/highline-1.6.19/test/tc_menu.rb +439 -0
- data/module/gems/highline-1.6.19/test/tc_string_extension.rb +20 -0
- data/module/gems/highline-1.6.19/test/tc_string_highline.rb +38 -0
- data/module/gems/highline-1.6.19/test/tc_style.rb +567 -0
- data/module/gems/highline-1.6.19/test/ts_all.rb +16 -0
- data/module/latest_specs.4.8 +0 -0
- data/module/latest_specs.4.8.gz +0 -0
- data/module/prerelease_specs.4.8 +0 -0
- data/module/prerelease_specs.4.8.gz +0 -0
- data/module/specs.4.8 +0 -0
- data/module/specs.4.8.gz +0 -0
- data/samples/blather/restlike/Gemfile +4 -0
- data/samples/blather/restlike/cmd.yml +1 -0
- data/samples/blather/restlike/lib/blather.rb +9 -0
- data/samples/blather/restlike/lib/blather/dsl/api.rb +78 -0
- data/samples/blather/restlike/lib/blather/dsl/call.rb +13 -0
- data/samples/blather/restlike/lib/blather/dsl/client.rb +58 -0
- data/samples/blather/restlike/lib/blather/dsl/config.rb +11 -0
- data/samples/blather/restlike/lib/blather/dsl/extraDSL.rb +163 -0
- data/samples/blather/restlike/lib/blather/meta/require.rb +8 -0
- data/samples/blather/restlike/lib/blather/meta/xmpp.yml +5 -0
- data/samples/blather/restlike/lib/blather/vendors/xmpp_default.rb +27 -0
- data/samples/blather/restlike/readme +2 -0
- data/samples/grape/init/Gemfile +2 -0
- data/samples/grape/init/cmd.yml +3 -0
- data/samples/grape/init/config.ru +2 -0
- data/samples/grape/init/docs/grape/documentation.txt +939 -0
- data/samples/grape/init/docs/grape/generate_rest_routes.rb +37 -0
- data/samples/grape/init/docs/grape/ls_routes.rb +31 -0
- data/samples/grape/init/lib/grape.rb +4 -0
- data/samples/grape/init/lib/grape/meta/subclasses.rb +20 -0
- data/samples/grape/init/lib/grape/xpath/app.rb +30 -0
- data/samples/grape/init/lib/grape/xpath/ruotes.rb +6 -0
- data/samples/grape/init/readme +1 -0
- data/samples/grape/readme +29 -0
- data/samples/grape/vendor/lib/grape/vendors/v1/rest.rb +57 -0
- data/samples/mongoid/cmd.yml +1 -0
- data/samples/mongoid/init/Gemfile +3 -0
- data/samples/mongoid/init/cmd.yml +2 -0
- data/samples/mongoid/init/docs/mongoid/ModelsRelations.rb +11 -0
- data/samples/mongoid/init/docs/mongoid/documents.xls +0 -0
- data/samples/mongoid/init/docs/mongoid/generate_modelsToDocs.rb +25 -0
- data/samples/mongoid/init/docs/mongoid/modelsToDocs.rb +25 -0
- data/samples/mongoid/init/docs/mongoid/relations.txt +1354 -0
- data/samples/mongoid/init/lib/mongoid.rb +44 -0
- data/samples/mongoid/init/lib/mongoid/dsl/extraDSL_CRUD.rb +446 -0
- data/samples/mongoid/init/lib/mongoid/dsl/extraDSL_MP.rb +517 -0
- data/samples/mongoid/init/lib/mongoid/dsl/init.rb +37 -0
- data/samples/mongoid/init/lib/mongoid/dsl/params.rb +67 -0
- data/samples/mongoid/init/lib/mongoid/meta/banned.rb +147 -0
- data/samples/mongoid/init/lib/mongoid/meta/control.yml +13 -0
- data/samples/mongoid/init/lib/mongoid/meta/mongoid.yml +6 -0
- data/samples/mongoid/init/lib/mongoid/meta/mpatch.rb +14 -0
- data/samples/mongoid/model/lib/mongoid/models/model.rb +28 -0
- data/samples/mongoid/readme +33 -0
- data/samples/rack/init/Gemfile +10 -0
- data/samples/rack/init/cmd.yml +2 -0
- data/samples/rack/init/config.ru +1 -0
- data/samples/rack/init/docs/rack/rake introducing.txt +60 -0
- data/samples/rack/init/docs/rack/webservers/Thin +43 -0
- data/samples/rack/init/docs/rack/webservers/ebb +72 -0
- data/samples/rack/init/docs/rack/webservers/fcgi +103 -0
- data/samples/rack/init/docs/rack/webservers/mongrel +74 -0
- data/samples/rack/init/docs/rack/webservers/passenger +37 -0
- data/samples/rack/init/docs/rack/webservers/scgi +188 -0
- data/samples/rack/init/lib/rack.rb +1 -0
- data/samples/rack/init/lib/rack/meta/webserver/thin.rb +45 -0
- data/samples/rack/init/lib/rack/meta/webserver/thin.yml +6 -0
- data/samples/rack/init/server.rb +0 -0
- data/samples/rack/readme +13 -0
- data/samples/rest_client/init/Gemfile +5 -0
- data/samples/rest_client/init/boot.rb +2 -0
- data/samples/rest_client/init/cmd.yml +1 -0
- data/samples/rest_client/init/config/rest_client/defaults.rb +16 -0
- data/samples/rest_client/init/docs/rest_client/simple overlook +251 -0
- data/samples/rest_client/init/test/rest_client/rest_dsl.rb +5 -0
- data/samples/rest_client/readme +7 -0
- data/samples/scripts/lines_counter/lines_number.rb +32 -0
- data/samples/scripts/lines_counter/readme +5 -0
- data/samples/scripts/readme +1 -0
- metadata +197 -7
- data/lib/clone/cms.rb +0 -56
- data/lib/clone/ext.rb +0 -77
- data/sample/test.rb +0 -30
@@ -0,0 +1,517 @@
|
|
1
|
+
class Class
|
2
|
+
|
3
|
+
def documents
|
4
|
+
begin
|
5
|
+
|
6
|
+
exceptions= %w[
|
7
|
+
Mongoid::Relations::Embedded::In
|
8
|
+
Mongoid::Relations::Referenced::In
|
9
|
+
]
|
10
|
+
|
11
|
+
return_array = Array.new
|
12
|
+
self.relations.each do |model_name,module_propertys|
|
13
|
+
if !exceptions.include?(module_propertys[:relation].to_s)
|
14
|
+
return_array.push model_name
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
return return_array
|
19
|
+
rescue Exception
|
20
|
+
return Array.new
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def relation_connection_type(to_model)
|
25
|
+
begin
|
26
|
+
|
27
|
+
return_none= "Mongoid::Relations::None"
|
28
|
+
return_self= "Mongoid::Relations::Self"
|
29
|
+
|
30
|
+
if to_model.nil?
|
31
|
+
return return_none
|
32
|
+
end
|
33
|
+
|
34
|
+
if self.to_s == to_model.to_s
|
35
|
+
return return_self
|
36
|
+
end
|
37
|
+
|
38
|
+
relation_type_data= self.reflect_on_association(to_model.convert_model_name)
|
39
|
+
|
40
|
+
if relation_type_data.nil?
|
41
|
+
return return_none
|
42
|
+
else
|
43
|
+
return relation_type_data[:relation].to_s
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
def reverse_relation_connection_type(to_model)
|
49
|
+
begin
|
50
|
+
|
51
|
+
return_none= "Mongoid::Relations::None"
|
52
|
+
return_self= "Mongoid::Relations::Self"
|
53
|
+
|
54
|
+
if to_model.nil?
|
55
|
+
return return_none
|
56
|
+
end
|
57
|
+
|
58
|
+
if self.to_s == to_model.to_s
|
59
|
+
return return_self
|
60
|
+
end
|
61
|
+
|
62
|
+
relation_type_data= to_model.reflect_on_association(self.convert_model_name)
|
63
|
+
|
64
|
+
if relation_type_data.nil?
|
65
|
+
return return_none
|
66
|
+
else
|
67
|
+
return relation_type_data[:relation].to_s
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def properties
|
74
|
+
|
75
|
+
hash_data = Hash.new
|
76
|
+
self.fields.each do |key,value|
|
77
|
+
hash_data[value.name]=value.options[:type]
|
78
|
+
end
|
79
|
+
return hash_data
|
80
|
+
|
81
|
+
end
|
82
|
+
def parents
|
83
|
+
begin
|
84
|
+
|
85
|
+
exceptions= %w[
|
86
|
+
Mongoid::Relations::Embedded::In
|
87
|
+
]
|
88
|
+
|
89
|
+
return_array = Array.new
|
90
|
+
self.relations.each do |model_name,module_propertys|
|
91
|
+
if exceptions.include?(module_propertys[:relation].to_s)
|
92
|
+
return_array.push model_name
|
93
|
+
end
|
94
|
+
end
|
95
|
+
if return_array.empty?
|
96
|
+
return nil
|
97
|
+
end
|
98
|
+
return return_array
|
99
|
+
|
100
|
+
end
|
101
|
+
end
|
102
|
+
def references
|
103
|
+
begin
|
104
|
+
|
105
|
+
exceptions= %w[
|
106
|
+
Mongoid::Relations::Referenced::In
|
107
|
+
Mongoid::Relations::Referenced::ManyToMany
|
108
|
+
]
|
109
|
+
|
110
|
+
return_array = Array.new
|
111
|
+
self.relations.each do |model_name,module_propertys|
|
112
|
+
if exceptions.include?(module_propertys[:relation].to_s)
|
113
|
+
return_array.push model_name
|
114
|
+
end
|
115
|
+
end
|
116
|
+
if return_array.empty?
|
117
|
+
return nil
|
118
|
+
end
|
119
|
+
return return_array
|
120
|
+
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def getPaths(*included)
|
125
|
+
|
126
|
+
### create defaults
|
127
|
+
begin
|
128
|
+
return_array= Array.new()
|
129
|
+
check_list= Array.new#.push(self.to_s)
|
130
|
+
relations_hash = Hash.new()
|
131
|
+
#chains= Hash.new
|
132
|
+
chains= Array.new
|
133
|
+
end
|
134
|
+
|
135
|
+
### get parents for every participants
|
136
|
+
begin
|
137
|
+
models_to_check = Array.new.push self
|
138
|
+
loop do
|
139
|
+
tmp_array = Array.new
|
140
|
+
break if models_to_check.empty?
|
141
|
+
models_to_check.each do |one_models_element|
|
142
|
+
begin
|
143
|
+
one_models_element.parents.each do |one_parent_in_underscore|
|
144
|
+
parent_model= one_parent_in_underscore.convert_model_name
|
145
|
+
tmp_array.push parent_model if !relations_hash.keys.include?(parent_model)
|
146
|
+
relations_hash[one_models_element] ||= Array.new
|
147
|
+
relations_hash[one_models_element].push parent_model
|
148
|
+
end
|
149
|
+
rescue NoMethodError
|
150
|
+
#next
|
151
|
+
end
|
152
|
+
end
|
153
|
+
models_to_check= tmp_array
|
154
|
+
end
|
155
|
+
models_to_check.clear
|
156
|
+
end
|
157
|
+
|
158
|
+
### make connections from relation pairs
|
159
|
+
begin
|
160
|
+
|
161
|
+
### generate pre path chains
|
162
|
+
### minden egyes szulo,s szulo szulo elemen egyesevel menj vegig (csak elso elemet vizsgalva) es ahol tobb mint egy elem talalhato azt torold
|
163
|
+
### igy legkozelebb az mar nem lesz lehetseges utvonal, ahol pedig mindenhol csak 1 elem volt ott ellenorzid
|
164
|
+
### hogy mar megtalalt sorrol van e szo, s ha igen torold a relations_hash[self] ből ezt a szulot (2. elem a path ban)
|
165
|
+
### the goal is to get every 1 element from sub arrays
|
166
|
+
|
167
|
+
begin
|
168
|
+
available_paths= Array.new
|
169
|
+
return nil if relations_hash[self].nil?
|
170
|
+
loop do
|
171
|
+
|
172
|
+
### defaults
|
173
|
+
begin
|
174
|
+
next_element_to_find = self
|
175
|
+
delete_element = Hash.new
|
176
|
+
one_chain = Array.new
|
177
|
+
end
|
178
|
+
|
179
|
+
### chain element builder
|
180
|
+
begin
|
181
|
+
loop do
|
182
|
+
if !relations_hash[next_element_to_find].nil? && relations_hash[next_element_to_find] != Array.new
|
183
|
+
|
184
|
+
one_chain.push(relations_hash[next_element_to_find][0])
|
185
|
+
if relations_hash[next_element_to_find].count > 1
|
186
|
+
delete_element = Hash.new
|
187
|
+
delete_element[next_element_to_find]= relations_hash[next_element_to_find][0]
|
188
|
+
end
|
189
|
+
|
190
|
+
next_element_to_find= relations_hash[next_element_to_find][0]
|
191
|
+
else
|
192
|
+
break
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
### remove already checked tree
|
198
|
+
begin
|
199
|
+
if delete_element != Hash.new
|
200
|
+
relations_hash[delete_element.keys[0]].delete_at(
|
201
|
+
relations_hash[delete_element.keys[0]].index(
|
202
|
+
delete_element[delete_element.keys[0]]))
|
203
|
+
delete_element= Hash.new
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
### add new element to chains
|
208
|
+
begin
|
209
|
+
unless chains.include? one_chain
|
210
|
+
chains.push one_chain
|
211
|
+
else
|
212
|
+
break
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
end
|
218
|
+
|
219
|
+
end
|
220
|
+
|
221
|
+
### after format and check params for contains
|
222
|
+
begin
|
223
|
+
|
224
|
+
### pre chains trim
|
225
|
+
begin
|
226
|
+
|
227
|
+
tmp_array= Array.new
|
228
|
+
chains.each do |one_element|
|
229
|
+
if !one_element.contains?(included)
|
230
|
+
tmp_array.push one_element
|
231
|
+
end
|
232
|
+
end
|
233
|
+
tmp_array.each do |one_element_to_delete|
|
234
|
+
chains.delete_at(chains.index(one_element_to_delete))
|
235
|
+
end
|
236
|
+
|
237
|
+
end
|
238
|
+
|
239
|
+
### choose the shortest path
|
240
|
+
begin
|
241
|
+
chain_list_max_count= nil
|
242
|
+
chains.each do |one_chain_list|
|
243
|
+
counter= one_chain_list.count
|
244
|
+
chain_list_max_count ||= (counter+1)
|
245
|
+
if counter < chain_list_max_count
|
246
|
+
return_array= one_chain_list
|
247
|
+
counter= chain_list_max_count
|
248
|
+
end
|
249
|
+
end
|
250
|
+
end
|
251
|
+
|
252
|
+
### reverse array
|
253
|
+
begin
|
254
|
+
return_array.reverse!
|
255
|
+
end
|
256
|
+
|
257
|
+
### add new element as self for first
|
258
|
+
begin
|
259
|
+
return_array.push self
|
260
|
+
end
|
261
|
+
|
262
|
+
|
263
|
+
end
|
264
|
+
|
265
|
+
return return_array
|
266
|
+
end
|
267
|
+
|
268
|
+
def __query_wrapper(*args)
|
269
|
+
|
270
|
+
### defaults
|
271
|
+
begin
|
272
|
+
return_data= nil
|
273
|
+
### params field
|
274
|
+
field_hash= Hash.new
|
275
|
+
### models
|
276
|
+
models_container= Array.new
|
277
|
+
### mother model
|
278
|
+
mother_model= nil
|
279
|
+
### method_to_use
|
280
|
+
method_to_use= Hash.new
|
281
|
+
|
282
|
+
args.each do |one_argument|
|
283
|
+
case one_argument.class.to_s.downcase
|
284
|
+
when "string"
|
285
|
+
begin
|
286
|
+
field_hash['_id']= Moped::BSON::ObjectId.from_string(one_argument)
|
287
|
+
rescue
|
288
|
+
begin
|
289
|
+
models_container.push one_argument.constantize
|
290
|
+
rescue NameError
|
291
|
+
#method_to_use= one_argument
|
292
|
+
end
|
293
|
+
end
|
294
|
+
when "hash"
|
295
|
+
begin
|
296
|
+
one_argument.each do |key,value|
|
297
|
+
if key.to_s == '_id'
|
298
|
+
field_hash['_id']= Moped::BSON::ObjectId.from_string(value.to_s)
|
299
|
+
else
|
300
|
+
field_hash[key]=value
|
301
|
+
end
|
302
|
+
end
|
303
|
+
end
|
304
|
+
when "class"
|
305
|
+
begin
|
306
|
+
models_container.push one_argument
|
307
|
+
end
|
308
|
+
when "array"
|
309
|
+
begin
|
310
|
+
method_to_use= one_argument
|
311
|
+
end
|
312
|
+
|
313
|
+
end
|
314
|
+
end
|
315
|
+
|
316
|
+
end
|
317
|
+
|
318
|
+
### mother model find, and path generate
|
319
|
+
begin
|
320
|
+
|
321
|
+
full_path = self.getPaths(*models_container) || Array.new.push(self)
|
322
|
+
mother_model= full_path.shift
|
323
|
+
|
324
|
+
full_path.count.times do |index|
|
325
|
+
full_path[index]= full_path[index].convert_model_name
|
326
|
+
end
|
327
|
+
|
328
|
+
end
|
329
|
+
|
330
|
+
### path trim
|
331
|
+
begin
|
332
|
+
|
333
|
+
deep_level = (full_path.count) || 0
|
334
|
+
chains= full_path
|
335
|
+
|
336
|
+
if full_path != Array.new && !full_path.nil?
|
337
|
+
full_path= full_path.join('.')+'.'
|
338
|
+
end
|
339
|
+
|
340
|
+
if full_path == Array.new
|
341
|
+
full_path= String.new
|
342
|
+
end
|
343
|
+
|
344
|
+
end
|
345
|
+
|
346
|
+
### start query
|
347
|
+
begin
|
348
|
+
|
349
|
+
### build app query args
|
350
|
+
begin
|
351
|
+
query_fields= Hash.new()
|
352
|
+
field_hash.each do |key,value|
|
353
|
+
query_fields["#{full_path}#{key}"]= value
|
354
|
+
end
|
355
|
+
end
|
356
|
+
|
357
|
+
### do query ask from db
|
358
|
+
begin
|
359
|
+
if method_to_use[1][:arguments?]
|
360
|
+
query_data = mother_model.__send__(
|
361
|
+
method_to_use[0].to_s,
|
362
|
+
query_fields)
|
363
|
+
else
|
364
|
+
query_data = mother_model.__send__(
|
365
|
+
method_to_use[0].to_s)
|
366
|
+
end
|
367
|
+
|
368
|
+
|
369
|
+
end
|
370
|
+
|
371
|
+
### return data
|
372
|
+
begin
|
373
|
+
if deep_level == 0
|
374
|
+
return_data=query_data
|
375
|
+
|
376
|
+
else
|
377
|
+
|
378
|
+
### go down for embeds docs
|
379
|
+
begin
|
380
|
+
|
381
|
+
last_round = (chains.count-1)
|
382
|
+
map_object = query_data
|
383
|
+
return_array = Array.new
|
384
|
+
chains.count.times do |deepness|
|
385
|
+
begin
|
386
|
+
children = Array.new
|
387
|
+
if map_object.class == Array || map_object.class == Mongoid::Criteria
|
388
|
+
|
389
|
+
map_object.each do |one_element_of_the_map_array|
|
390
|
+
subclass_data = one_element_of_the_map_array.__send__(chains[deepness])
|
391
|
+
if subclass_data.class == Array || subclass_data.class == Mongoid::Criteria
|
392
|
+
subclass_data.each do |one_element_of_tmp_children|
|
393
|
+
if deepness < last_round
|
394
|
+
children.push one_element_of_tmp_children
|
395
|
+
else
|
396
|
+
return_array.push one_element_of_tmp_children
|
397
|
+
end
|
398
|
+
end
|
399
|
+
else
|
400
|
+
if deepness < last_round
|
401
|
+
children.push subclass_data
|
402
|
+
else
|
403
|
+
return_array.push subclass_data
|
404
|
+
end
|
405
|
+
end
|
406
|
+
end
|
407
|
+
else
|
408
|
+
subclass_data = map_object.__send__(chains[deepness])
|
409
|
+
if subclass_data.class == Array || subclass_data.class == Mongoid::Criteria
|
410
|
+
subclass_data.each do |one_element_of_tmp_children|
|
411
|
+
if deepness < last_round
|
412
|
+
children.push one_element_of_tmp_children
|
413
|
+
else
|
414
|
+
return_array.push one_element_of_tmp_children
|
415
|
+
end
|
416
|
+
end
|
417
|
+
else
|
418
|
+
if deepness < last_round
|
419
|
+
children.push subclass_data
|
420
|
+
else
|
421
|
+
return_array.push subclass_data
|
422
|
+
end
|
423
|
+
end
|
424
|
+
end
|
425
|
+
map_object=children.uniq
|
426
|
+
rescue NoMethodError => ex
|
427
|
+
puts ex
|
428
|
+
end
|
429
|
+
end
|
430
|
+
|
431
|
+
return_data= return_array
|
432
|
+
|
433
|
+
end
|
434
|
+
|
435
|
+
end
|
436
|
+
end
|
437
|
+
|
438
|
+
end
|
439
|
+
|
440
|
+
return return_data
|
441
|
+
end
|
442
|
+
|
443
|
+
def _where(*args)
|
444
|
+
self.__query_wrapper(['where',{:arguments? => true}],*args)
|
445
|
+
end
|
446
|
+
def _all(*args)
|
447
|
+
self.__query_wrapper(['all',{:arguments? => false}],*args)
|
448
|
+
end
|
449
|
+
|
450
|
+
def _find(*args)
|
451
|
+
|
452
|
+
### pre validation
|
453
|
+
begin
|
454
|
+
if args[0].class != Moped::BSON::ObjectId && args[0].class != String
|
455
|
+
raise ArgumentError, "id parameter must be id or ObjectId"
|
456
|
+
end
|
457
|
+
end
|
458
|
+
|
459
|
+
### Do the Gangnam style
|
460
|
+
begin
|
461
|
+
return_array = self._where('_id' => args[0])
|
462
|
+
end
|
463
|
+
|
464
|
+
#### After validation
|
465
|
+
#begin
|
466
|
+
# if return_array.count > 1
|
467
|
+
# raise ArgumentError,"multiple finds, give more parameters"
|
468
|
+
# end
|
469
|
+
#end
|
470
|
+
|
471
|
+
### reformation
|
472
|
+
begin
|
473
|
+
return_array=return_array[0]
|
474
|
+
end
|
475
|
+
|
476
|
+
return return_array
|
477
|
+
end
|
478
|
+
def _find_by(*args)
|
479
|
+
|
480
|
+
### Do the Gangnam style
|
481
|
+
begin
|
482
|
+
return_array = self._where(*args).first
|
483
|
+
end
|
484
|
+
|
485
|
+
return return_array
|
486
|
+
end
|
487
|
+
|
488
|
+
alias :this_to_me :relation_connection_type
|
489
|
+
alias :me_to_this :reverse_relation_connection_type
|
490
|
+
|
491
|
+
end
|
492
|
+
class Object
|
493
|
+
def convert_model_name
|
494
|
+
|
495
|
+
unless self.class == Class || self.class == String || self.class == NilClass
|
496
|
+
raise ArgumentError, "invalid input, must be Class or String: => #{self.class} (#{self})"
|
497
|
+
end
|
498
|
+
|
499
|
+
case self.class.to_s.downcase
|
500
|
+
|
501
|
+
when "class"
|
502
|
+
begin
|
503
|
+
return self.to_s.underscore.split('/').last
|
504
|
+
end
|
505
|
+
when "string"
|
506
|
+
begin
|
507
|
+
Mongoid::Document.classes.each do |one_model_name|
|
508
|
+
if one_model_name.to_s.underscore.split('/').last == self.to_s
|
509
|
+
return one_model_name.to_s.constantize
|
510
|
+
end
|
511
|
+
end
|
512
|
+
end
|
513
|
+
|
514
|
+
end
|
515
|
+
|
516
|
+
end
|
517
|
+
end
|