clone 1.0.0.beta → 1.0.0.beta2
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/.gitignore +1 -2
- data/VERSION +1 -1
- data/samples/grape/init/Gemfile +2 -2
- data/samples/grape/init/{docs → doc}/grape/documentation.txt +0 -0
- data/samples/grape/init/lib/grape.rb +12 -2
- data/samples/grape/init/lib/grape/mount/rest_api.rb +22 -0
- data/samples/grape/vendor/lib/grape/vendors/{v1/rest.rb → v1.rb} +4 -2
- data/samples/helper/init/Gemfile +5 -0
- data/samples/helper/init/lib/boot.rb +23 -0
- data/samples/mongoid/init/Gemfile +1 -3
- data/samples/mongoid/init/lib/mongoid.rb +9 -40
- data/samples/mongoid/init/lib/mongoid/meta/{mongoid.yml → config.yml} +0 -0
- data/samples/rack/init/Gemfile +1 -4
- data/samples/rack/init/lib/rack.rb +1 -1
- metadata +8 -44
- data/samples/blather/restlike/Gemfile +0 -4
- data/samples/blather/restlike/cmd.yml +0 -1
- data/samples/blather/restlike/lib/blather.rb +0 -9
- data/samples/blather/restlike/lib/blather/dsl/api.rb +0 -78
- data/samples/blather/restlike/lib/blather/dsl/call.rb +0 -13
- data/samples/blather/restlike/lib/blather/dsl/client.rb +0 -58
- data/samples/blather/restlike/lib/blather/dsl/config.rb +0 -11
- data/samples/blather/restlike/lib/blather/dsl/extraDSL.rb +0 -163
- data/samples/blather/restlike/lib/blather/meta/require.rb +0 -8
- data/samples/blather/restlike/lib/blather/meta/xmpp.yml +0 -5
- data/samples/blather/restlike/lib/blather/vendors/xmpp_default.rb +0 -27
- data/samples/blather/restlike/readme +0 -2
- data/samples/grape/init/docs/grape/generate_rest_routes.rb +0 -37
- data/samples/grape/init/docs/grape/ls_routes.rb +0 -31
- data/samples/grape/init/lib/grape/meta/subclasses.rb +0 -20
- data/samples/grape/init/lib/grape/xpath/app.rb +0 -30
- data/samples/grape/init/lib/grape/xpath/ruotes.rb +0 -6
- data/samples/mongoid/cmd.yml +0 -1
- data/samples/mongoid/init/docs/mongoid/ModelsRelations.rb +0 -11
- data/samples/mongoid/init/docs/mongoid/generate_modelsToDocs.rb +0 -25
- data/samples/mongoid/init/docs/mongoid/modelsToDocs.rb +0 -25
- data/samples/mongoid/init/lib/mongoid/dsl/extraDSL_CRUD.rb +0 -446
- data/samples/mongoid/init/lib/mongoid/dsl/extraDSL_MP.rb +0 -517
- data/samples/mongoid/init/lib/mongoid/dsl/init.rb +0 -37
- data/samples/mongoid/init/lib/mongoid/dsl/params.rb +0 -67
- data/samples/mongoid/init/lib/mongoid/meta/banned.rb +0 -147
- data/samples/mongoid/init/lib/mongoid/meta/control.yml +0 -13
- data/samples/mongoid/init/lib/mongoid/meta/mpatch.rb +0 -14
- data/samples/rack/init/lib/rack/meta/webserver/thin.rb +0 -45
- data/samples/rack/init/lib/rack/meta/webserver/thin.yml +0 -6
- data/samples/rack/init/server.rb +0 -0
- data/samples/rest_client/init/Gemfile +0 -5
- data/samples/rest_client/init/boot.rb +0 -2
- data/samples/rest_client/init/cmd.yml +0 -1
- data/samples/rest_client/init/config/rest_client/defaults.rb +0 -16
- data/samples/rest_client/init/docs/rest_client/simple overlook +0 -251
- data/samples/rest_client/init/test/rest_client/rest_dsl.rb +0 -5
- data/samples/rest_client/readme +0 -7
@@ -1,11 +0,0 @@
|
|
1
|
-
module XMPP
|
2
|
-
class CONFIG
|
3
|
-
JID = BLATHER_CONFIG['XMPP']['JID']
|
4
|
-
PWD = BLATHER_CONFIG['XMPP']['PWD']
|
5
|
-
HOST = BLATHER_CONFIG['XMPP']['HOST'] || '0.0.0.0'
|
6
|
-
PORT = BLATHER_CONFIG['XMPP']['PORT'] || '5222'
|
7
|
-
TIMEOUT= BLATHER_CONFIG['XMPP']['TIMEOUT'] || 30
|
8
|
-
SLEEP_TIME= BLATHER_CONFIG['XMPP']['SLEEP_TIME'] || 0.2
|
9
|
-
MSG= BLATHER_CONFIG['XMPP']['MSG'] || {'version'=>'v0','path'=>'/default','method'=>'GET'}
|
10
|
-
end
|
11
|
-
end
|
@@ -1,163 +0,0 @@
|
|
1
|
-
module XMPP
|
2
|
-
### extraDSL
|
3
|
-
begin
|
4
|
-
class << self
|
5
|
-
def send(to,what)
|
6
|
-
### hold thread
|
7
|
-
if XMPP::Client.ready.nil? && XMPP::Client.engine.nil?
|
8
|
-
timeout= 30
|
9
|
-
while XMPP::Client.ready.nil?
|
10
|
-
sleep 1
|
11
|
-
timeout-= 1
|
12
|
-
if timeout <= 0
|
13
|
-
break
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
XMPP::Client.engine.say to, what
|
18
|
-
return true
|
19
|
-
end
|
20
|
-
def ask(to,what)
|
21
|
-
### wait for engine
|
22
|
-
begin
|
23
|
-
if XMPP::Client.ready.nil? && XMPP::Client.engine.nil?
|
24
|
-
timeout= 30
|
25
|
-
while XMPP::Client.ready.nil?
|
26
|
-
sleep 1
|
27
|
-
timeout-= 1
|
28
|
-
if timeout <= 0
|
29
|
-
break
|
30
|
-
end
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
### generate sample form
|
35
|
-
begin
|
36
|
-
### check msg structure
|
37
|
-
begin
|
38
|
-
if what['body'].nil?
|
39
|
-
tmp_hash= Hash.new
|
40
|
-
begin
|
41
|
-
XMPP::CONFIG::MSG.each do |key,value|
|
42
|
-
if !what[key].nil?
|
43
|
-
tmp_hash[key]= what[key]
|
44
|
-
what.delete key
|
45
|
-
else
|
46
|
-
tmp_hash[key]= value
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
tmp_hash['body']= what
|
51
|
-
tmp_hash['token']= self.token
|
52
|
-
what= tmp_hash
|
53
|
-
else
|
54
|
-
begin
|
55
|
-
XMPP::CONFIG::MSG.each do |key,value|
|
56
|
-
if what[key].nil?
|
57
|
-
what[key]= value
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
what['token']= self.token
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
### mark token
|
66
|
-
begin
|
67
|
-
XMPP::Client.answers[what['token']]=nil
|
68
|
-
end
|
69
|
-
### send msg
|
70
|
-
begin
|
71
|
-
XMPP::Client.engine.say to, what.to_json
|
72
|
-
rescue Exception
|
73
|
-
XMPP::Client.engine.say to, what
|
74
|
-
end
|
75
|
-
### after msg
|
76
|
-
begin
|
77
|
-
### hold process
|
78
|
-
begin
|
79
|
-
sleep_time= XMPP::CONFIG::SLEEP_TIME
|
80
|
-
timeout = XMPP::CONFIG::TIMEOUT.to_f / sleep_time
|
81
|
-
while XMPP::Client.answers[what['token']].nil?
|
82
|
-
sleep sleep_time
|
83
|
-
timeout -= 1
|
84
|
-
if timeout <= 0
|
85
|
-
#logger
|
86
|
-
puts "time is out for the answer"
|
87
|
-
break
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
### finis process with answer
|
92
|
-
begin
|
93
|
-
answer_msg = XMPP::Client.answers[what['token']]
|
94
|
-
XMPP::Client.answers.delete what['token']
|
95
|
-
end
|
96
|
-
### return answer
|
97
|
-
begin
|
98
|
-
return answer_msg
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
def receive(msg)
|
103
|
-
if XMPP.json? msg
|
104
|
-
message= JSON.parse(msg)
|
105
|
-
XMPP::CONFIG::MSG.each do |key,value|
|
106
|
-
if message[key].nil?
|
107
|
-
message[key]= value
|
108
|
-
end
|
109
|
-
end
|
110
|
-
if XMPP::Client.answers.keys.include?(message['token'])
|
111
|
-
XMPP::Client.answers[message['token']]= message['body']
|
112
|
-
else
|
113
|
-
call_method= XMPP.generate_method_name(message)
|
114
|
-
message['body']= XMPP::Call.__send__(call_method,message['body'])
|
115
|
-
return message.to_json
|
116
|
-
end
|
117
|
-
end
|
118
|
-
end
|
119
|
-
def token
|
120
|
-
begin
|
121
|
-
token_string= Time.now.to_s
|
122
|
-
[' ',':','-','+'].each do |one_sym|
|
123
|
-
token_string.gsub!(one_sym,'')
|
124
|
-
end
|
125
|
-
token_string+= Random.srand(Time.now.to_i).to_s
|
126
|
-
token_string+= XMPP::CONFIG::JID.to_s.gsub('@','').gsub('.','').upcase
|
127
|
-
end
|
128
|
-
return token_string
|
129
|
-
end
|
130
|
-
def json? json
|
131
|
-
begin
|
132
|
-
JSON.parse(json)
|
133
|
-
return true
|
134
|
-
rescue Exception => e
|
135
|
-
return false
|
136
|
-
end
|
137
|
-
end
|
138
|
-
def routes
|
139
|
-
XMPP::Call.singleton_methods - [:create_singleton_method,:method_missing]
|
140
|
-
end
|
141
|
-
def generate_method_name(hash)
|
142
|
-
|
143
|
-
call_method= String.new
|
144
|
-
call_method+= hash['method'].to_s.downcase
|
145
|
-
call_method+= '_'
|
146
|
-
call_method+= hash['version']
|
147
|
-
call_method+= '_'
|
148
|
-
if hash['path'].include? '/'
|
149
|
-
call_method+= hash['path'].to_s.gsub('/','_')
|
150
|
-
elsif hash['path'].include? '\\'
|
151
|
-
call_method+= hash['path'].to_s.gsub('\\','_')
|
152
|
-
elsif hash['path'].include? '.'
|
153
|
-
call_method+= hash['path'].to_s.gsub('.','_')
|
154
|
-
else
|
155
|
-
call_method+= hash['path']
|
156
|
-
end
|
157
|
-
|
158
|
-
return call_method
|
159
|
-
|
160
|
-
end
|
161
|
-
end
|
162
|
-
end
|
163
|
-
end
|
@@ -1,8 +0,0 @@
|
|
1
|
-
yml_file = (Dir.entries(File.join(File.dirname(__FILE__))).reject{|x| x[-4,4] != ".yml"})[0].to_s
|
2
|
-
BLATHER_CONFIG = YAML.load_file(File.expand_path(File.join(File.dirname(__FILE__),yml_file)))
|
3
|
-
|
4
|
-
module XMPP
|
5
|
-
### require
|
6
|
-
require 'blather/client/dsl'
|
7
|
-
require 'json'
|
8
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
module Vendors
|
2
|
-
class Default < XMPP::API
|
3
|
-
|
4
|
-
#version :prototype #> default is v0
|
5
|
-
|
6
|
-
resource :default do
|
7
|
-
|
8
|
-
get do |params|
|
9
|
-
|
10
|
-
end
|
11
|
-
|
12
|
-
post do |params|
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
put do |params|
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
delete do |params|
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
|
25
|
-
end
|
26
|
-
end
|
27
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require_relative File.join("..","..","boot.rb")
|
2
|
-
write_out_array = Array.new
|
3
|
-
write_out_array.push "REST::API ROUTES:\n"
|
4
|
-
write_out_array.push "\nTable Of Contents\n================="
|
5
|
-
|
6
|
-
array_of_hash = Array.new
|
7
|
-
REST::API.routes.map do |route|
|
8
|
-
array_of_hash.push({:method => route.route_method.to_s, :path => route.route_path.to_s})
|
9
|
-
end
|
10
|
-
contents_array= Array.new
|
11
|
-
array_of_hash.each do |hash|
|
12
|
-
separator_str= String.new
|
13
|
-
if hash[:method].to_s == "POST" || hash[:method].to_s == "DELETE"
|
14
|
-
separator_str= "\t\t "
|
15
|
-
else
|
16
|
-
separator_str= "\t\t\t "
|
17
|
-
end
|
18
|
-
contents_array.push "#{hash[:method]}#{separator_str}#{hash[:path]}"
|
19
|
-
end
|
20
|
-
write_out_array.push contents_array.join("\n")
|
21
|
-
write_out_array.push "\nExplanations\n============"
|
22
|
-
REST::API.routes.map do |route|
|
23
|
-
new_docs_element= Array.new
|
24
|
-
new_docs_element.push "Method: #{route.route_method}"
|
25
|
-
new_docs_element.push "Path: #{route.route_path}"
|
26
|
-
new_docs_element.push "description: #{route.route_description}"
|
27
|
-
if route.route_params.count == 0
|
28
|
-
new_docs_element.push "No specified or special params"
|
29
|
-
else
|
30
|
-
route.route_params.each do |key,value|
|
31
|
-
new_docs_element.push " -#{key}: #{value}"
|
32
|
-
end
|
33
|
-
end
|
34
|
-
new_docs_element.push "\n"
|
35
|
-
write_out_array.push new_docs_element.join("\n")
|
36
|
-
end
|
37
|
-
File.new("routes_docs.txt","w").write write_out_array.join("\n")
|
@@ -1,31 +0,0 @@
|
|
1
|
-
require_relative File.join("..","..","boot.rb")
|
2
|
-
write_out_array = Array.new
|
3
|
-
write_out_array.push "REST::API ROUTES:\n"
|
4
|
-
write_out_array.push "\nTable Of Contents\n================="
|
5
|
-
|
6
|
-
array_of_hash = Array.new
|
7
|
-
REST::API.routes.map do |route|
|
8
|
-
array_of_hash.push({:method => route.route_method.to_s, :path => route.route_path.to_s})
|
9
|
-
end
|
10
|
-
contents_array= Array.new
|
11
|
-
array_of_hash.sort_by!{|hash| hash[:method]}.each do |hash|
|
12
|
-
contents_array.push "#{hash[:method]} | #{hash[:path]}"
|
13
|
-
end
|
14
|
-
write_out_array.push contents_array.join("\n")
|
15
|
-
write_out_array.push "\nExplanations\n============"
|
16
|
-
REST::API.routes.map do |route|
|
17
|
-
new_docs_element= Array.new
|
18
|
-
new_docs_element.push "Method: #{route.route_method}"
|
19
|
-
new_docs_element.push "Path: #{route.route_path}"
|
20
|
-
new_docs_element.push "description: #{route.route_description}"
|
21
|
-
if route.route_params.count == 0
|
22
|
-
new_docs_element.push "No specified or special params"
|
23
|
-
else
|
24
|
-
route.route_params.each do |key,value|
|
25
|
-
new_docs_element.push " -#{key}: #{value}"
|
26
|
-
end
|
27
|
-
end
|
28
|
-
new_docs_element.push "\n"
|
29
|
-
write_out_array.push new_docs_element.join("\n")
|
30
|
-
end
|
31
|
-
puts write_out_array.join("\n")
|
@@ -1,20 +0,0 @@
|
|
1
|
-
module Grape
|
2
|
-
# The API class is the primary entry point for
|
3
|
-
# creating Grape APIs.Users should subclass this
|
4
|
-
# class in order to build an API.
|
5
|
-
class API
|
6
|
-
|
7
|
-
def self.inherited(subclass)
|
8
|
-
@classes ||= Array.new
|
9
|
-
@classes.push subclass.name.constantize
|
10
|
-
|
11
|
-
subclass.reset!
|
12
|
-
subclass.logger = logger.clone
|
13
|
-
end
|
14
|
-
|
15
|
-
def self.classes
|
16
|
-
@classes
|
17
|
-
end
|
18
|
-
|
19
|
-
end
|
20
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
#encoding: UTF-8
|
2
|
-
module REST
|
3
|
-
class API < Grape::API
|
4
|
-
|
5
|
-
### defaults
|
6
|
-
begin
|
7
|
-
### exclude array
|
8
|
-
exclude_list = [
|
9
|
-
self
|
10
|
-
]
|
11
|
-
end
|
12
|
-
|
13
|
-
### mount components
|
14
|
-
begin
|
15
|
-
Grape::API.classes.each do |component|
|
16
|
-
if !exclude_list.include? component
|
17
|
-
begin
|
18
|
-
if component.class == Class
|
19
|
-
mount component
|
20
|
-
else
|
21
|
-
mount component.constantize
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
|
29
|
-
end
|
30
|
-
end
|
data/samples/mongoid/cmd.yml
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
helper: init
|
@@ -1,11 +0,0 @@
|
|
1
|
-
require_relative File.join("..","..","boot.rb")
|
2
|
-
|
3
|
-
|
4
|
-
begin
|
5
|
-
relations_array = Array.new
|
6
|
-
Mongoid::Document.classes.each do |class_name|
|
7
|
-
relations_array.push class_name.constantize.getPaths[0]
|
8
|
-
end
|
9
|
-
relations_array= relations_array.sort_by{ |hsh| hsh.values }
|
10
|
-
end
|
11
|
-
puts relations_array
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require_relative File.join("..","..","boot.rb")
|
2
|
-
|
3
|
-
write_out_array= Array.new
|
4
|
-
begin
|
5
|
-
puts "\n"
|
6
|
-
separator= "="*0#*99
|
7
|
-
Mongoid::Document.classes.each do |class_name|
|
8
|
-
puts separator
|
9
|
-
write_out_array.push separator
|
10
|
-
puts "the model name:#{class_name}"
|
11
|
-
write_out_array.push "the model name:#{class_name}"
|
12
|
-
begin
|
13
|
-
puts "the embeds model:"+(class_name.constantize.getPaths).inspect
|
14
|
-
write_out_array.push "the embeds model:"+(class_name.constantize.getPaths).inspect
|
15
|
-
rescue NoMethodError
|
16
|
-
end
|
17
|
-
class_name.constantize.properties.each do |key,value|
|
18
|
-
printf "%-78s %s\n", "The field name: #{key}", "field type: #{value}"
|
19
|
-
write_out_array.push("The field name: #{key},\t field type: #{value}")
|
20
|
-
end
|
21
|
-
puts separator
|
22
|
-
write_out_array.push separator
|
23
|
-
end
|
24
|
-
end
|
25
|
-
File.new("models_docs.txt","w").write write_out_array.join("\n")
|
@@ -1,25 +0,0 @@
|
|
1
|
-
require_relative File.join("..","..","boot.rb")
|
2
|
-
|
3
|
-
write_out_array= Array.new
|
4
|
-
begin
|
5
|
-
puts "\n"
|
6
|
-
separator= "="*0#*99
|
7
|
-
Mongoid::Document.classes.each do |class_name|
|
8
|
-
puts separator
|
9
|
-
write_out_array.push separator
|
10
|
-
puts "the model name:#{class_name}"
|
11
|
-
write_out_array.push "the model name:#{class_name}"
|
12
|
-
begin
|
13
|
-
puts "the embeds model:"+(class_name.constantize.getPaths).inspect
|
14
|
-
write_out_array.push "the embeds model:"+(class_name.constantize.getPaths).inspect
|
15
|
-
rescue NoMethodError
|
16
|
-
end
|
17
|
-
class_name.constantize.properties.each do |key,value|
|
18
|
-
printf "%-78s %s\n", "The field name: #{key}", "field type: #{value}"
|
19
|
-
write_out_array.push("The field name: #{key},\t field type: #{value}")
|
20
|
-
end
|
21
|
-
puts separator
|
22
|
-
write_out_array.push separator
|
23
|
-
end
|
24
|
-
end
|
25
|
-
File.new("models_docs.txt","w").write write_out_array.join("\n")
|
@@ -1,446 +0,0 @@
|
|
1
|
-
module Mongoid
|
2
|
-
module ExtraDSL
|
3
|
-
### Mongoid::ExtraDSL.CRUD_name(
|
4
|
-
# *models, #target , parent
|
5
|
-
# *param_hashTags,
|
6
|
-
# [optionable]relation_type_string
|
7
|
-
#)
|
8
|
-
class << self
|
9
|
-
|
10
|
-
def input(*args)
|
11
|
-
|
12
|
-
### defaults
|
13
|
-
begin
|
14
|
-
|
15
|
-
relation_type_model = nil
|
16
|
-
|
17
|
-
parent_model = nil
|
18
|
-
target_model = nil
|
19
|
-
|
20
|
-
models_array = Array.new
|
21
|
-
params = Hash.new
|
22
|
-
pager = Hash.new
|
23
|
-
properties = Hash.new
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
### fill up defaults by argumens
|
28
|
-
begin
|
29
|
-
args.each do |argument|
|
30
|
-
case argument.class.to_s.downcase
|
31
|
-
|
32
|
-
when "class"
|
33
|
-
models_array.push argument
|
34
|
-
|
35
|
-
when "hash","hashie::mash"
|
36
|
-
argument.each do |key,value|
|
37
|
-
case key.to_s.downcase
|
38
|
-
|
39
|
-
when "db_page_limit","db_page_number"
|
40
|
-
pager[key.to_s.downcase]= value
|
41
|
-
|
42
|
-
else
|
43
|
-
params[key]=value
|
44
|
-
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
when "string"
|
49
|
-
begin
|
50
|
-
if argument.to_s.downcase.include?("mongoid::relations")
|
51
|
-
#argument=argument.split('::')
|
52
|
-
#2.times do
|
53
|
-
# argument.shift()
|
54
|
-
#end
|
55
|
-
#argument=argument.join('::')
|
56
|
-
relation_type_model= argument
|
57
|
-
else
|
58
|
-
begin
|
59
|
-
if argument.constantize != Object
|
60
|
-
models_array.push argument.constantize
|
61
|
-
end
|
62
|
-
rescue NameError
|
63
|
-
relation_type_model= argument
|
64
|
-
end
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
end
|
69
|
-
end
|
70
|
-
if models_array.count <= 1
|
71
|
-
target_model= models_array[0]
|
72
|
-
models_array.shift()
|
73
|
-
else
|
74
|
-
|
75
|
-
target_model= models_array[0]
|
76
|
-
models_array.shift()
|
77
|
-
|
78
|
-
parent_model= models_array[0]
|
79
|
-
models_array.shift()
|
80
|
-
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
### params sub key remove
|
85
|
-
begin
|
86
|
-
if !params['params'].nil?
|
87
|
-
|
88
|
-
tmp_hash=Hash.new
|
89
|
-
tmp_hash= params['params']
|
90
|
-
params.delete 'params'
|
91
|
-
tmp_hash.each do |key,value|
|
92
|
-
params[key]= value
|
93
|
-
end
|
94
|
-
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
### BSON::ObjectId convert in params
|
99
|
-
begin
|
100
|
-
tmp_hash= Hash.new
|
101
|
-
params.each do |key,value|
|
102
|
-
if key.to_s == '_id'
|
103
|
-
tmp_hash[key]= Moped::BSON::ObjectId.from_string(value.to_s)
|
104
|
-
end
|
105
|
-
if key.to_s == 'id'
|
106
|
-
tmp_hash['_id']= Moped::BSON::ObjectId.from_string(value.to_s)
|
107
|
-
params.delete 'id'
|
108
|
-
end
|
109
|
-
end
|
110
|
-
if tmp_hash != Hash.new
|
111
|
-
tmp_hash.each do |key,value|
|
112
|
-
params[key]= value
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
|
117
|
-
### parent_id key search
|
118
|
-
begin
|
119
|
-
parent_id_key= "#{parent_model.convert_model_name.to_s.downcase}_id"
|
120
|
-
parent_id_key= "parent_id" if parent_id_key=='_id'
|
121
|
-
|
122
|
-
tmp_hash= Hash.new
|
123
|
-
params.each do |key,value|
|
124
|
-
case key.to_s.downcase
|
125
|
-
when "parent_id","parentid",parent_id_key
|
126
|
-
properties['parent_id']=value
|
127
|
-
else
|
128
|
-
tmp_hash[key]=value
|
129
|
-
end
|
130
|
-
end
|
131
|
-
params= tmp_hash
|
132
|
-
end
|
133
|
-
|
134
|
-
### params trim by banned elements
|
135
|
-
begin
|
136
|
-
Mongoid::Banned.list.each do |category,category_elements|
|
137
|
-
case category
|
138
|
-
|
139
|
-
when :ProtocolElements
|
140
|
-
category_elements.each do |one_banned_global_key|
|
141
|
-
params.delete one_banned_global_key
|
142
|
-
end
|
143
|
-
|
144
|
-
else
|
145
|
-
#nothing
|
146
|
-
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
### generate model connection type
|
152
|
-
begin
|
153
|
-
begin
|
154
|
-
relation_type_model ||= target_model.reverse_relation_connection_type(parent_model)
|
155
|
-
rescue Exception
|
156
|
-
relation_type_model ||= parent_model.relation_connection_type(target_model)
|
157
|
-
end
|
158
|
-
end
|
159
|
-
|
160
|
-
### return processed data as hash table
|
161
|
-
begin
|
162
|
-
return_hash= {
|
163
|
-
:parent_model => parent_model,
|
164
|
-
:target_model => target_model,
|
165
|
-
:models => models_array,
|
166
|
-
:model_type => relation_type_model,
|
167
|
-
:params => params,
|
168
|
-
:pager => pager,
|
169
|
-
:properties => properties
|
170
|
-
}
|
171
|
-
return return_hash
|
172
|
-
end
|
173
|
-
|
174
|
-
end
|
175
|
-
|
176
|
-
def read(*args)
|
177
|
-
|
178
|
-
### defaults
|
179
|
-
begin
|
180
|
-
input_hash = self.input(*args)
|
181
|
-
parent_model = input_hash[:parent_model]
|
182
|
-
target_model = input_hash[:target_model]
|
183
|
-
model_type = input_hash[:model_type]
|
184
|
-
params = input_hash[:params]
|
185
|
-
pager = input_hash[:pager]
|
186
|
-
properties = input_hash[:properties]
|
187
|
-
return_object = nil
|
188
|
-
end
|
189
|
-
|
190
|
-
#puts args.inspect,""
|
191
|
-
#puts input_hash.inspect,""
|
192
|
-
|
193
|
-
### processing
|
194
|
-
begin
|
195
|
-
case true
|
196
|
-
|
197
|
-
when model_type.downcase.include?("none"),
|
198
|
-
model_type.downcase.include?("self")
|
199
|
-
begin
|
200
|
-
if params.find_hashize == Hash.new
|
201
|
-
return_object= target_model._all
|
202
|
-
elsif !params.find_hashize['_id'].nil?
|
203
|
-
return_object= target_model._find(params.find_hashize['_id'])
|
204
|
-
else
|
205
|
-
return_object= target_model._where(params.find_hashize)
|
206
|
-
end
|
207
|
-
end
|
208
|
-
|
209
|
-
when model_type.downcase.include?("embedded"),
|
210
|
-
model_type.downcase.include?("referenced")
|
211
|
-
begin
|
212
|
-
if !properties['parent_id'].nil?
|
213
|
-
### find embeds collection by parent_id
|
214
|
-
return_object= parent_model._find_by(
|
215
|
-
properties['parent_id']).__send__(target_model.convert_model_name)
|
216
|
-
else
|
217
|
-
### find by params
|
218
|
-
if !params['_id'].nil?
|
219
|
-
return_object= target_model._find_by(params.find_hashize)
|
220
|
-
elsif params.find_hashize == Hash.new
|
221
|
-
return_object= target_model._all(parent_model)
|
222
|
-
else
|
223
|
-
return_object= target_model._where(params.find_hashize)
|
224
|
-
end
|
225
|
-
end
|
226
|
-
end
|
227
|
-
|
228
|
-
end
|
229
|
-
end
|
230
|
-
|
231
|
-
### after limiting
|
232
|
-
begin
|
233
|
-
if pager != Hash.new && return_object.class == Mongoid::Criteria && !pager['db_page_limit'].nil?
|
234
|
-
if pager['db_page_number'].nil?
|
235
|
-
return_object= return_object.limit(pager['db_page_limit'])
|
236
|
-
else
|
237
|
-
return_object= return_object.limit(pager['db_page_limit'].to_i).offset(
|
238
|
-
(pager['db_page_number'].to_i * pager['db_page_limit'].to_i))
|
239
|
-
end
|
240
|
-
end
|
241
|
-
end
|
242
|
-
|
243
|
-
### grape readable formating
|
244
|
-
begin
|
245
|
-
|
246
|
-
#if return_object.class == Mongoid::Criteria
|
247
|
-
# return_object= Array[*return_object]
|
248
|
-
#end
|
249
|
-
|
250
|
-
|
251
|
-
return return_object
|
252
|
-
end
|
253
|
-
|
254
|
-
end
|
255
|
-
|
256
|
-
def create(*args)
|
257
|
-
|
258
|
-
### defaults
|
259
|
-
begin
|
260
|
-
input_hash = self.input(*args)
|
261
|
-
parent_model = input_hash[:parent_model]
|
262
|
-
target_model = input_hash[:target_model]
|
263
|
-
model_type = input_hash[:model_type]
|
264
|
-
params = input_hash[:params]
|
265
|
-
properties = input_hash[:properties]
|
266
|
-
return_key = 'id'
|
267
|
-
return_object = nil
|
268
|
-
end
|
269
|
-
|
270
|
-
### params trim by banned elements
|
271
|
-
begin
|
272
|
-
Mongoid::Banned.list.each do |category,category_elements|
|
273
|
-
case category
|
274
|
-
|
275
|
-
when :Elements
|
276
|
-
category_elements.each do |one_banned_global_key|
|
277
|
-
params.delete one_banned_global_key
|
278
|
-
end
|
279
|
-
|
280
|
-
when :ModelElements
|
281
|
-
category_elements.each do |one_info_hash|
|
282
|
-
if one_info_hash.keys[0].to_s == target_model.to_s
|
283
|
-
params.delete one_info_hash.values[0]
|
284
|
-
end
|
285
|
-
end
|
286
|
-
|
287
|
-
end
|
288
|
-
end
|
289
|
-
end
|
290
|
-
|
291
|
-
### processing
|
292
|
-
begin
|
293
|
-
case true
|
294
|
-
|
295
|
-
when model_type.downcase.include?("none"),
|
296
|
-
model_type.downcase.include?("self")
|
297
|
-
begin
|
298
|
-
|
299
|
-
|
300
|
-
new_data= target_model.new(params.new_hashize)
|
301
|
-
|
302
|
-
begin
|
303
|
-
new_data.save
|
304
|
-
rescue Exception
|
305
|
-
return_object= false
|
306
|
-
end
|
307
|
-
|
308
|
-
if return_object.nil?
|
309
|
-
return_object= new_data['_id']
|
310
|
-
end
|
311
|
-
|
312
|
-
end
|
313
|
-
|
314
|
-
when model_type.downcase.include?("embedded::many"),
|
315
|
-
model_type.downcase.include?("referenced::many")
|
316
|
-
begin
|
317
|
-
parent= parent_model._find(properties['parent_id'])
|
318
|
-
if params['_id'].nil?
|
319
|
-
parent.__send__(target_model.convert_model_name.to_s).push(
|
320
|
-
target_model.new((params.new_hashize)))
|
321
|
-
else
|
322
|
-
parent.__send__(target_model.convert_model_name.to_s).push(
|
323
|
-
target_model._find((params.find_hashize['_id'])))
|
324
|
-
end
|
325
|
-
begin
|
326
|
-
parent.save!
|
327
|
-
rescue Exception
|
328
|
-
return_object= false
|
329
|
-
end
|
330
|
-
|
331
|
-
if return_object.nil?
|
332
|
-
return_object= parent.__send__(target_model.convert_model_name.to_s).last['_id']
|
333
|
-
end
|
334
|
-
|
335
|
-
end
|
336
|
-
|
337
|
-
when model_type.downcase.include?("embedded::one"),
|
338
|
-
model_type.downcase.include?("referenced::one")
|
339
|
-
begin
|
340
|
-
parent= parent_model._find(properties['parent_id'])
|
341
|
-
if params['_id'].nil?
|
342
|
-
parent.__send__("#{target_model.convert_model_name}=",
|
343
|
-
target_model.new(params.new_hashize))
|
344
|
-
else
|
345
|
-
parent.__send__("#{target_model.convert_model_name}=",
|
346
|
-
target_model._find((params.find_hashize['_id'])))
|
347
|
-
end
|
348
|
-
|
349
|
-
begin
|
350
|
-
parent.save
|
351
|
-
rescue Exception
|
352
|
-
return_object= false
|
353
|
-
end
|
354
|
-
|
355
|
-
if return_object.nil?
|
356
|
-
return_object= parent.__send__(target_model.convert_model_name.to_s)['_id']
|
357
|
-
end
|
358
|
-
|
359
|
-
end
|
360
|
-
|
361
|
-
end
|
362
|
-
end
|
363
|
-
|
364
|
-
### return return_obj
|
365
|
-
begin
|
366
|
-
#return { return_key => return_object }
|
367
|
-
return return_object
|
368
|
-
|
369
|
-
end
|
370
|
-
|
371
|
-
end
|
372
|
-
|
373
|
-
def update(*args)
|
374
|
-
|
375
|
-
### defaults
|
376
|
-
begin
|
377
|
-
input_hash = self.input(*args)
|
378
|
-
parent_model = input_hash[:parent_model]
|
379
|
-
target_model = input_hash[:target_model]
|
380
|
-
model_type = input_hash[:model_type]
|
381
|
-
params = input_hash[:params]
|
382
|
-
end
|
383
|
-
|
384
|
-
### processing
|
385
|
-
begin
|
386
|
-
case true
|
387
|
-
|
388
|
-
when false
|
389
|
-
#do nothing
|
390
|
-
|
391
|
-
else
|
392
|
-
begin
|
393
|
-
|
394
|
-
new_data= target_model._find(params['_id'])
|
395
|
-
params.new_hashize.each do |key,value|
|
396
|
-
new_data[key]=value
|
397
|
-
end
|
398
|
-
new_data.save!
|
399
|
-
|
400
|
-
end
|
401
|
-
|
402
|
-
end
|
403
|
-
end
|
404
|
-
|
405
|
-
end
|
406
|
-
|
407
|
-
def delete(*args)
|
408
|
-
|
409
|
-
### defaults
|
410
|
-
begin
|
411
|
-
input_hash = self.input(*args)
|
412
|
-
parent_model = input_hash[:parent_model]
|
413
|
-
target_model = input_hash[:target_model]
|
414
|
-
model_type = input_hash[:model_type]
|
415
|
-
params = input_hash[:params]
|
416
|
-
end
|
417
|
-
|
418
|
-
### processing
|
419
|
-
begin
|
420
|
-
case true
|
421
|
-
|
422
|
-
when false
|
423
|
-
#do nothing
|
424
|
-
|
425
|
-
else
|
426
|
-
### embeds collections
|
427
|
-
begin
|
428
|
-
|
429
|
-
something_to_delete= target_model._find(params['_id'])
|
430
|
-
something_to_delete.delete
|
431
|
-
begin
|
432
|
-
something_to_delete.save
|
433
|
-
rescue Exception
|
434
|
-
false
|
435
|
-
end
|
436
|
-
|
437
|
-
end
|
438
|
-
|
439
|
-
end
|
440
|
-
end
|
441
|
-
|
442
|
-
end
|
443
|
-
|
444
|
-
end
|
445
|
-
end
|
446
|
-
end
|