grape-dsl 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/Gemfile +2 -0
- data/LICENSE +20 -0
- data/LICENSE.txt +20 -0
- data/README.md +31 -0
- data/Rakefile +1 -0
- data/VERSION +1 -0
- data/files.rb +24 -0
- data/grape-dsl.gemspec +25 -0
- data/lib/grape-dsl.rb +11 -0
- data/lib/grape-dsl/config.rb +9 -0
- data/lib/grape-dsl/doc.rb +506 -0
- data/lib/grape-dsl/dsl.rb +46 -0
- data/lib/grape-dsl/endpoint.rb +15 -0
- data/lib/grape-dsl/headers.rb +76 -0
- metadata +88 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
M2E2YzI4MjRlZjRiMjQ3MTljN2UxNTM1NWE0MmJkYjMzZWQ3ZjNlOQ==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZDczZDFkNGQ0Njk4MjFiMzVmNGU1MzZkZmJmYTM3ZDgwYzZmY2RkYw==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
MDJlNzExMWIzMzdjOTg1ZWU3YjRmMGRhYWRjYmYzZWVjNzRmM2I4NWYwZDc4
|
10
|
+
YjFiOTQyOWU3ZGVhNzhkMTg4ZGY2M2IwNzg0OGNhZDM0OTJiYzhhYTI1ZmU4
|
11
|
+
NDQ5NzRhY2U0ZDVlYTcxZGQwYTMwY2Y5NTQ3MjM0YTY5OWFlNGE=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MzE1ZTdjNTkwNjMxYTA0ZDVlMDdlMjgxYzI5NDE4ZDliNjQ5OWRkODFjYmVm
|
14
|
+
Mjc0ZjkxYjE1NmUzODgyOWEwOWY0ZDY1M2U4OGMwOWZlMzE2OTA1ZjcxOGFk
|
15
|
+
YTEwMGRkMTc4OTE0ZjYzZjFiOTY4ZDcyM2RhZjU5MzllZjY5MTE=
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2014 Adam Luzsi
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
6
|
+
this software and associated documentation files (the "Software"), to deal in
|
7
|
+
the Software without restriction, including without limitation the rights to
|
8
|
+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
9
|
+
the Software, and to permit persons to whom the Software is furnished to do so,
|
10
|
+
subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
17
|
+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
18
|
+
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
19
|
+
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 Adam Luzsi
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
Grape-DSL
|
2
|
+
============
|
3
|
+
|
4
|
+
DSL for Grape module that let you use some basic function much easier
|
5
|
+
if you use redmine wiki you can even create doc into it
|
6
|
+
|
7
|
+
|
8
|
+
## LICENSE
|
9
|
+
|
10
|
+
(The MIT License)
|
11
|
+
|
12
|
+
Copyright (c) 2014++ Adam Luzsi <adamluzsi@gmail.com>
|
13
|
+
|
14
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
15
|
+
a copy of this software and associated documentation files (the
|
16
|
+
'Software'), to deal in the Software without restriction, including
|
17
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
18
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
19
|
+
permit persons to whom the Software is furnished to do so, subject to
|
20
|
+
the following conditions:
|
21
|
+
|
22
|
+
The above copyright notice and this permission notice shall be
|
23
|
+
included in all copies or substantial portions of the Software.
|
24
|
+
|
25
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
26
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
27
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
28
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
29
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
30
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
31
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.join "bundler","gem_tasks"
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
data/files.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
### Get Files from dir
|
2
|
+
begin
|
3
|
+
|
4
|
+
files_to_be_loaded = %w[version.rb]
|
5
|
+
|
6
|
+
SpecFiles= Array.new
|
7
|
+
|
8
|
+
Dir[File.expand_path(File.join(File.dirname(__FILE__),"**","*"))].sort.uniq.each do |one_file_name|
|
9
|
+
one_file_name = File.expand_path one_file_name
|
10
|
+
file_name = one_file_name[(File.expand_path(File.dirname(__FILE__)).to_s.length+1)..(one_file_name.length-1)]
|
11
|
+
|
12
|
+
if !one_file_name.include?("pkg")
|
13
|
+
if !File.directory? file_name
|
14
|
+
SpecFiles.push file_name
|
15
|
+
STDOUT.puts file_name if $DEBUG
|
16
|
+
if files_to_be_loaded.include? one_file_name.split(File::SEPARATOR).last
|
17
|
+
load one_file_name
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
data/grape-dsl.gemspec
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require File.expand_path(File.join(File.dirname(__FILE__),"files.rb"))
|
4
|
+
|
5
|
+
### Specification for the new Gem
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
|
8
|
+
spec.name = "grape-dsl"
|
9
|
+
spec.version = File.open(File.join(File.dirname(__FILE__),"VERSION")).read.split("\n")[0].chomp.gsub(' ','')
|
10
|
+
spec.authors = ["Adam Luzsi"]
|
11
|
+
spec.email = ["adamluzsi@gmail.com"]
|
12
|
+
spec.description = %q{DSL for Grape module that let you use some basic function much easier. For example mount all Grape class into a single one with a simple line}
|
13
|
+
spec.summary = %q{Simple Grape DSL for easer use cases}
|
14
|
+
spec.homepage = "https://github.com/adamluzsi/grape-dsl"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = SpecFiles
|
18
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
19
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency "procemon"
|
23
|
+
spec.add_dependency "grape"
|
24
|
+
|
25
|
+
end
|
data/lib/grape-dsl.rb
ADDED
@@ -0,0 +1,506 @@
|
|
1
|
+
|
2
|
+
class Array
|
3
|
+
|
4
|
+
def convert_all_value_to_s
|
5
|
+
|
6
|
+
self.count.times do |index|
|
7
|
+
|
8
|
+
case self[index].class.to_s.downcase
|
9
|
+
|
10
|
+
when "hash"
|
11
|
+
self[index].convert_all_value_to_s
|
12
|
+
|
13
|
+
when "array"
|
14
|
+
self[index].convert_all_value_to_s
|
15
|
+
|
16
|
+
else
|
17
|
+
self[index]= self[index].to_s
|
18
|
+
|
19
|
+
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
return self
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
class Hash
|
31
|
+
|
32
|
+
def convert_all_value_to_s
|
33
|
+
|
34
|
+
self.each do |key,value|
|
35
|
+
|
36
|
+
case value.class.to_s.downcase
|
37
|
+
|
38
|
+
when "hash"
|
39
|
+
value.convert_all_value_to_s
|
40
|
+
|
41
|
+
when "array"
|
42
|
+
value.convert_all_value_to_s
|
43
|
+
|
44
|
+
else
|
45
|
+
self[key]= value.to_s
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
return self
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
module Grape
|
57
|
+
class << self
|
58
|
+
|
59
|
+
# helpers for doc generation
|
60
|
+
def redmine_body(route)
|
61
|
+
|
62
|
+
description_key= :body
|
63
|
+
tmp_array= Array.new()
|
64
|
+
params= nil
|
65
|
+
evalue= nil
|
66
|
+
content_type= nil
|
67
|
+
|
68
|
+
#if route.route_path == "/booking/request(.:format)"
|
69
|
+
# debugger
|
70
|
+
#end
|
71
|
+
|
72
|
+
case route.route_description.class.to_s.downcase
|
73
|
+
|
74
|
+
when "string"
|
75
|
+
params= route.route_params
|
76
|
+
|
77
|
+
when "hash"
|
78
|
+
|
79
|
+
if !route.route_description[:content_type].nil?
|
80
|
+
content_type= route.route_description[:content_type]
|
81
|
+
end
|
82
|
+
|
83
|
+
if description_key.nil?
|
84
|
+
params= route.route_params
|
85
|
+
evalue= "value[:type]"
|
86
|
+
else
|
87
|
+
params= route.route_description[description_key]
|
88
|
+
evalue= "value"
|
89
|
+
end
|
90
|
+
|
91
|
+
when "nilclass"
|
92
|
+
params= route.route_params
|
93
|
+
params ||= "no return"
|
94
|
+
content_type= "TXT"
|
95
|
+
|
96
|
+
else
|
97
|
+
params= route.route_params
|
98
|
+
content_type= "TXT"
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
case params.class.to_s.downcase
|
103
|
+
|
104
|
+
when "hash"
|
105
|
+
|
106
|
+
if params == route.route_params
|
107
|
+
tmp_hash= Hash.new
|
108
|
+
params.each do |key,value|
|
109
|
+
tmp_hash[key]= value[:type].to_s
|
110
|
+
end
|
111
|
+
params= tmp_hash
|
112
|
+
end
|
113
|
+
|
114
|
+
params = params.convert_all_value_to_s
|
115
|
+
|
116
|
+
when "class"
|
117
|
+
begin
|
118
|
+
if params.to_s.include? '::'
|
119
|
+
if params.to_s.downcase.include? 'boolean'
|
120
|
+
params= params.to_s.split('::').last
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
content_type= "TXT"
|
125
|
+
end
|
126
|
+
|
127
|
+
when "string"
|
128
|
+
content_type= "TXT"
|
129
|
+
|
130
|
+
else
|
131
|
+
begin
|
132
|
+
params= "no params spec"
|
133
|
+
content_type= "TXT"
|
134
|
+
end
|
135
|
+
|
136
|
+
end
|
137
|
+
|
138
|
+
content_type ||= "TXT"
|
139
|
+
case content_type.to_s.downcase
|
140
|
+
|
141
|
+
when "json"
|
142
|
+
begin
|
143
|
+
|
144
|
+
|
145
|
+
|
146
|
+
tmp_array.push("<pre><code class=\"#{content_type.to_s.upcase}\">")
|
147
|
+
|
148
|
+
require "json"
|
149
|
+
|
150
|
+
formatted_string= params.to_json
|
151
|
+
|
152
|
+
{
|
153
|
+
"{" => "{\n",
|
154
|
+
"}" => "\n}",
|
155
|
+
"," => ",\n"
|
156
|
+
}.each do |from,to|
|
157
|
+
formatted_string.gsub!(from,to)
|
158
|
+
end
|
159
|
+
|
160
|
+
formatted_string.gsub!(/^"/," \"")
|
161
|
+
|
162
|
+
tmp_array.push formatted_string
|
163
|
+
tmp_array.push("</code></pre>")
|
164
|
+
end
|
165
|
+
|
166
|
+
when "txt"
|
167
|
+
begin
|
168
|
+
|
169
|
+
tmp_array.push("<pre>")
|
170
|
+
tmp_array.push(params.inspect)
|
171
|
+
tmp_array.push("</pre>")
|
172
|
+
|
173
|
+
end
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
end
|
178
|
+
|
179
|
+
return tmp_array
|
180
|
+
|
181
|
+
end
|
182
|
+
|
183
|
+
# this method help create from grape params and description a ppt like redmine wiki doc
|
184
|
+
# Usage:
|
185
|
+
#
|
186
|
+
##> example variable for description (hash obj)
|
187
|
+
#description= Hash.new
|
188
|
+
#
|
189
|
+
##> optional -> :description
|
190
|
+
#description[:desc]= String.new
|
191
|
+
#
|
192
|
+
##> response body like if JSON than a ruby Hash obj with the Structure and the values are the types
|
193
|
+
#description[:body]= Hash.new
|
194
|
+
#
|
195
|
+
##> response body code type -> like json usually same as content_type (format :xy)
|
196
|
+
#description[:content_type]= String.new #> "JSON"
|
197
|
+
#
|
198
|
+
#desc description
|
199
|
+
#params do
|
200
|
+
# optional :blabla, :type => String, :desc => "bla bla desc"
|
201
|
+
# requires :xy, type: String, desc: "XY desc"
|
202
|
+
#end
|
203
|
+
#get "xy" do
|
204
|
+
#
|
205
|
+
#end
|
206
|
+
#
|
207
|
+
##>---------------------------------------------------------------------------------------------------
|
208
|
+
#> OR the classic
|
209
|
+
#desc "My awsome String Description"
|
210
|
+
#params do
|
211
|
+
# optional :blabla, :type => String, :desc => "bla bla desc"
|
212
|
+
# requires :xy, type: String, desc: "XY desc"
|
213
|
+
#end
|
214
|
+
#delete "xy" do
|
215
|
+
#
|
216
|
+
#end
|
217
|
+
#
|
218
|
+
##>---------------------------------------------------------------------
|
219
|
+
## For the method use
|
220
|
+
#
|
221
|
+
## for a targeted specified class
|
222
|
+
#Grape.create_redmine_wiki_doc target_class: REST::API,
|
223
|
+
# path: File.expand_path(File.join(File.dirname(__FILE__),"test_file.txt"))
|
224
|
+
#
|
225
|
+
## for all grape subclass (directs and indirects)
|
226
|
+
#Grape.create_redmine_wiki_doc path: File.expand_path(File.join(File.dirname(__FILE__),"test_file.txt"))
|
227
|
+
#
|
228
|
+
def create_redmine_wiki_doc(*args)
|
229
|
+
|
230
|
+
# default set in args
|
231
|
+
begin
|
232
|
+
|
233
|
+
args= Hash[*args]
|
234
|
+
args.dup.each do |key,value|
|
235
|
+
if key.class != Symbol
|
236
|
+
args[key.to_s.to_sym]= value
|
237
|
+
args.delete key
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
if args[:path].nil?
|
242
|
+
raise ArgumentError,"You must set a file path with a file name in order to create documentation for grape!"
|
243
|
+
end
|
244
|
+
|
245
|
+
args[:desc_files] ||= Array.new
|
246
|
+
if !args[:desc_files].nil? && args[:desc_files].class != Array
|
247
|
+
args[:desc_files]= Array.new.push(args[:desc_files])
|
248
|
+
end
|
249
|
+
|
250
|
+
[:desc,:desc_file,:extra_desc_file].each do |one_key|
|
251
|
+
unless args[one_key].nil?
|
252
|
+
args[:desc_files].push args[one_key]
|
253
|
+
args.delete one_key
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
#args[:path],
|
260
|
+
#args[:extra_desc_file]
|
261
|
+
#args[:target_class]
|
262
|
+
|
263
|
+
end
|
264
|
+
|
265
|
+
# site name
|
266
|
+
begin
|
267
|
+
write_out_array = Array.new
|
268
|
+
write_out_array.push "h1. Database Rest Control Layer Documentation\n"
|
269
|
+
write_out_array.push "h2. REST application routes:\n"
|
270
|
+
end
|
271
|
+
|
272
|
+
# description
|
273
|
+
begin
|
274
|
+
write_out_array.push "h3. this is the documentation for #{$0} rest calls\n\n"+
|
275
|
+
" the main function is to create a control layer to the database,\n"+
|
276
|
+
"with interactive commands, that can handle multiple way from ask requests,\n"+
|
277
|
+
"like regexp search by string, or different parameters for an array ask,\n"+
|
278
|
+
"relation connection handle.\n\n"+
|
279
|
+
" The calls input are the parameters, the description tells what does it do,\n"+
|
280
|
+
"like read from db, create in the db or update in the db by xy params, and how.\n"
|
281
|
+
|
282
|
+
args[:desc_files].each do |extra_desc_file_path|
|
283
|
+
write_out_array.push "h3. #{extra_desc_file_path.split(File::Separator).last.split('.')[0].downcase.capitalize}\n"
|
284
|
+
write_out_array.push "<pre>"
|
285
|
+
write_out_array.push File.open(extra_desc_file_path,"r").read
|
286
|
+
write_out_array.push "</pre>\n"
|
287
|
+
end
|
288
|
+
end
|
289
|
+
|
290
|
+
# table of contents
|
291
|
+
begin
|
292
|
+
write_out_array.push "\n{{>toc}}\n"
|
293
|
+
end
|
294
|
+
|
295
|
+
|
296
|
+
# classes array
|
297
|
+
begin
|
298
|
+
rest_models= Array.new
|
299
|
+
end
|
300
|
+
if args[:target_class].nil?
|
301
|
+
Grape::API.each_subclass do |one_class|
|
302
|
+
rest_models.push(one_class)
|
303
|
+
end
|
304
|
+
else
|
305
|
+
if args[:target_class].class != Class && args[:target_class] != nil
|
306
|
+
raise ArgumentError, "invalid input :target_class is not a Class obj"
|
307
|
+
end
|
308
|
+
rest_models.push(args[:target_class])
|
309
|
+
end
|
310
|
+
|
311
|
+
rest_models.each do |rest_api_model|
|
312
|
+
next if Grape::API == rest_api_model
|
313
|
+
rest_api_model.routes.map do |route|
|
314
|
+
|
315
|
+
# defaults
|
316
|
+
begin
|
317
|
+
|
318
|
+
uni_tab= " "*0
|
319
|
+
mid_tab= " "*3
|
320
|
+
|
321
|
+
bsym= "*"
|
322
|
+
isym= "_"
|
323
|
+
|
324
|
+
htsym= "* "
|
325
|
+
mtsym= "** "
|
326
|
+
stsym= "*** "
|
327
|
+
|
328
|
+
hheader= "h3. "
|
329
|
+
mheader= "h4. "
|
330
|
+
sheader= "h5. "
|
331
|
+
method_name= "#{hheader}Request: #{route.route_path} call: #{route.route_method.to_s.downcase} part"
|
332
|
+
|
333
|
+
|
334
|
+
|
335
|
+
end
|
336
|
+
|
337
|
+
# check that does the method already in the documentation
|
338
|
+
unless write_out_array.include?(method_name)
|
339
|
+
|
340
|
+
# create call name
|
341
|
+
begin
|
342
|
+
write_out_array.push method_name
|
343
|
+
end
|
344
|
+
|
345
|
+
# request
|
346
|
+
begin
|
347
|
+
|
348
|
+
# create request description
|
349
|
+
begin
|
350
|
+
write_out_array.push("\n"+(uni_tab*1)+"#{mheader}Request description")
|
351
|
+
case route.route_description.class.to_s.downcase
|
352
|
+
|
353
|
+
when "string"
|
354
|
+
route.route_description.each_line do |one_line|
|
355
|
+
write_out_array.push((uni_tab*2)+htsym+one_line.chomp)
|
356
|
+
end
|
357
|
+
|
358
|
+
when "hash"
|
359
|
+
begin
|
360
|
+
sym_to_find= :desc
|
361
|
+
if route.route_description[sym_to_find].nil?
|
362
|
+
sym_to_find= :description
|
363
|
+
end
|
364
|
+
route.route_description[sym_to_find].each_line do |one_line|
|
365
|
+
write_out_array.push((uni_tab*2)+htsym+one_line.chomp)
|
366
|
+
end
|
367
|
+
end
|
368
|
+
|
369
|
+
|
370
|
+
end
|
371
|
+
end
|
372
|
+
|
373
|
+
# pre request
|
374
|
+
begin
|
375
|
+
write_out_array.push("\n#{mheader}request\n")
|
376
|
+
end
|
377
|
+
|
378
|
+
# create route method
|
379
|
+
begin
|
380
|
+
write_out_array.push((uni_tab*2)+"#{htsym}#{bsym}method:#{bsym}#{mid_tab} #{route.route_method}")
|
381
|
+
end
|
382
|
+
|
383
|
+
# create route path
|
384
|
+
begin
|
385
|
+
write_out_array.push((uni_tab*2)+"#{htsym}#{bsym}path:#{bsym}#{mid_tab} #{route.route_path}")
|
386
|
+
end
|
387
|
+
|
388
|
+
# create route content_type
|
389
|
+
begin
|
390
|
+
write_out_array.push((uni_tab*2)+"#{htsym}#{bsym}headers:#{bsym}#{mid_tab}")
|
391
|
+
rest_api_model.content_types.each do |one_format_type,one_format_header|
|
392
|
+
write_out_array.push "#{mtsym}#{uni_tab*2}#{one_format_header}"
|
393
|
+
end
|
394
|
+
|
395
|
+
write_out_array.push ""
|
396
|
+
end
|
397
|
+
|
398
|
+
# create request type for code format class
|
399
|
+
# create request body contents
|
400
|
+
#begin
|
401
|
+
# if rest_api_model.content_types.count == 1
|
402
|
+
# write_out_array.push((uni_tab*2)+"#{htsym}*body:*")
|
403
|
+
#
|
404
|
+
# redmine_body(rest_api_model,route).each do |one_element|
|
405
|
+
# write_out_array.push one_element
|
406
|
+
# end
|
407
|
+
#
|
408
|
+
# end
|
409
|
+
# write_out_array.push ""
|
410
|
+
#end
|
411
|
+
|
412
|
+
# parameters
|
413
|
+
begin
|
414
|
+
new_docs_element= Array.new
|
415
|
+
if route.route_params.count == 0
|
416
|
+
new_docs_element.push " No specified or special params"
|
417
|
+
else
|
418
|
+
new_docs_element.push ""
|
419
|
+
new_docs_element.push "#{htsym}#{isym}#{bsym}Parameters#{bsym}#{isym}"
|
420
|
+
route.route_params.each do |key,value|
|
421
|
+
new_docs_element.push "#{mtsym}#{isym}#{key}#{isym}"
|
422
|
+
value.each do |value_key,value_value|
|
423
|
+
new_docs_element.push "#{stsym}#{value_key}: #{value_value}"
|
424
|
+
end
|
425
|
+
end
|
426
|
+
new_docs_element.push "\n"
|
427
|
+
end
|
428
|
+
refactored_element= Array.new
|
429
|
+
new_docs_element.each do |one_element|
|
430
|
+
refactored_element.push((uni_tab*2)+one_element)
|
431
|
+
end
|
432
|
+
write_out_array.push refactored_element.join("\n")
|
433
|
+
end
|
434
|
+
|
435
|
+
end
|
436
|
+
|
437
|
+
# response
|
438
|
+
begin
|
439
|
+
|
440
|
+
# pre response
|
441
|
+
begin
|
442
|
+
write_out_array.push("\n#{mheader}response\n")
|
443
|
+
end
|
444
|
+
|
445
|
+
# create route content_type
|
446
|
+
begin
|
447
|
+
write_out_array.push((uni_tab*2)+"#{htsym}#{bsym}headers:#{bsym}#{mid_tab}")
|
448
|
+
rest_api_model.content_types.each do |one_format_type,one_format_header|
|
449
|
+
write_out_array.push "#{mtsym}#{uni_tab*2}#{one_format_header}"
|
450
|
+
end
|
451
|
+
|
452
|
+
write_out_array.push ""
|
453
|
+
end
|
454
|
+
|
455
|
+
# create response bodies
|
456
|
+
begin
|
457
|
+
#TODO check out why not working normaly with evry path!
|
458
|
+
write_out_array.push((uni_tab*2)+"#{htsym}*body:*")
|
459
|
+
redmine_body(route).each do |one_element|
|
460
|
+
write_out_array.push one_element
|
461
|
+
end
|
462
|
+
write_out_array.push ""
|
463
|
+
end
|
464
|
+
|
465
|
+
end
|
466
|
+
|
467
|
+
# error resp
|
468
|
+
begin
|
469
|
+
|
470
|
+
# pre error
|
471
|
+
begin
|
472
|
+
write_out_array.push("\n#{mheader}response in case of failure\n")
|
473
|
+
end
|
474
|
+
|
475
|
+
# create error response headers
|
476
|
+
begin
|
477
|
+
|
478
|
+
end
|
479
|
+
|
480
|
+
# create error response bodies
|
481
|
+
begin
|
482
|
+
#write_out_array.push((uni_tab*2)+"*body:*")
|
483
|
+
write_out_array.push((uni_tab*2)+"#{htsym}*Internal Server Error:500*")
|
484
|
+
end
|
485
|
+
|
486
|
+
end
|
487
|
+
|
488
|
+
# after space
|
489
|
+
begin
|
490
|
+
write_out_array.push "\n----\n"
|
491
|
+
end
|
492
|
+
|
493
|
+
end
|
494
|
+
|
495
|
+
end
|
496
|
+
end
|
497
|
+
|
498
|
+
File.new(args[:path],"w").write write_out_array.join("\n")
|
499
|
+
|
500
|
+
return nil
|
501
|
+
end
|
502
|
+
|
503
|
+
alias :create_ppt_doc :create_redmine_wiki_doc
|
504
|
+
|
505
|
+
end
|
506
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
#encoding: UTF-8
|
2
|
+
module Grape
|
3
|
+
# The API class is the primary entry point for
|
4
|
+
# creating Grape APIs.Users should subclass this
|
5
|
+
# class in order to build an API.
|
6
|
+
class API
|
7
|
+
class << self
|
8
|
+
|
9
|
+
# mount all the rest api classes that is subclass of the Grape::API
|
10
|
+
# make easy to manage
|
11
|
+
def mount_subclasses(*exception)
|
12
|
+
|
13
|
+
# mark self as exception
|
14
|
+
begin
|
15
|
+
exception.push(self)
|
16
|
+
end
|
17
|
+
|
18
|
+
# mount components
|
19
|
+
begin
|
20
|
+
Grape::API.subclasses.each do |component|
|
21
|
+
unless exception.include?(component)
|
22
|
+
mount(component)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
return nil
|
28
|
+
|
29
|
+
end
|
30
|
+
|
31
|
+
# write out to the console the class routes
|
32
|
+
def console_write_out_routes
|
33
|
+
|
34
|
+
$stdout.puts "\n\nREST::API ROUTES:"
|
35
|
+
self.routes.map do |route|
|
36
|
+
$stdout.puts "\t#{route.route_method}","#{route.route_path}"
|
37
|
+
end
|
38
|
+
|
39
|
+
return nil
|
40
|
+
end
|
41
|
+
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Grape
|
2
|
+
# An Endpoint is the proxy scope in which all routing
|
3
|
+
# blocks are executed. In other words, any methods
|
4
|
+
# on the instance level of this class may be called
|
5
|
+
# from inside a `get`, `post`, etc.
|
6
|
+
class Endpoint
|
7
|
+
class << self
|
8
|
+
attr_accessor :header_config_obj
|
9
|
+
|
10
|
+
alias :config_obj :header_config_obj
|
11
|
+
alias :config_obj= :header_config_obj=
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# this is super if you want CORS with Grape
|
2
|
+
module Grape
|
3
|
+
class << self
|
4
|
+
|
5
|
+
# example in yaml format
|
6
|
+
# "header_name":
|
7
|
+
# - "header values"
|
8
|
+
# - "header value 2"
|
9
|
+
#
|
10
|
+
#
|
11
|
+
# real example for cors
|
12
|
+
# "Access-Control-Allow-Headers":
|
13
|
+
# - "X-Idp-Id"
|
14
|
+
# - "X-Token"
|
15
|
+
# - "Content-Type"
|
16
|
+
# "Access-Control-Allow-Origin":
|
17
|
+
# - "*"
|
18
|
+
# "Access-Control-Allow-Methods":
|
19
|
+
# - HEAD
|
20
|
+
# - OPTIONS
|
21
|
+
# - GET
|
22
|
+
# - POST
|
23
|
+
# - PUT
|
24
|
+
# - DELETE
|
25
|
+
#
|
26
|
+
#
|
27
|
+
# This will give headers to all call request response made after this
|
28
|
+
# make sure to load BEFORE every route call going to be made
|
29
|
+
def response_headers_to_new_calls(config_obj=nil)
|
30
|
+
|
31
|
+
Grape::Endpoint.config_obj= config_obj unless config_obj.nil?
|
32
|
+
Grape::API.inject_singleton_method :inherited, add: "after" do |subclass|
|
33
|
+
|
34
|
+
subclass.class_eval do
|
35
|
+
|
36
|
+
before do
|
37
|
+
Grape::Endpoint.header_config_obj.each do |header_key,header_value|
|
38
|
+
header header_key, header_value.join(', ')
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
return nil
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
# same config obj format like to "response_headers_to_new_calls"
|
51
|
+
# this will create headers for the options call to ALL already made route
|
52
|
+
# make sure to load after every route has been made
|
53
|
+
def response_headers_to_routes_options_request(config_obj=nil)
|
54
|
+
|
55
|
+
Grape::Endpoint.header_config_obj= config_obj unless config_obj.nil?
|
56
|
+
Grape::API.subclasses.each do |rest_api_model|
|
57
|
+
rest_api_model.routes.map { |route| route.route_path.split('(.:format)')[0] }.uniq.each do |path|
|
58
|
+
rest_api_model.class_eval do
|
59
|
+
|
60
|
+
options path do
|
61
|
+
Grape::Endpoint.header_config_obj.each do |header_key,header_value|
|
62
|
+
header header_key, header_value.join(', ')
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
return nil
|
72
|
+
end
|
73
|
+
|
74
|
+
|
75
|
+
end
|
76
|
+
end
|
metadata
ADDED
@@ -0,0 +1,88 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: grape-dsl
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adam Luzsi
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: procemon
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ! '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ! '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: grape
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ! '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: DSL for Grape module that let you use some basic function much easier.
|
42
|
+
For example mount all Grape class into a single one with a simple line
|
43
|
+
email:
|
44
|
+
- adamluzsi@gmail.com
|
45
|
+
executables: []
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- VERSION
|
55
|
+
- files.rb
|
56
|
+
- grape-dsl.gemspec
|
57
|
+
- lib/grape-dsl.rb
|
58
|
+
- lib/grape-dsl/config.rb
|
59
|
+
- lib/grape-dsl/doc.rb
|
60
|
+
- lib/grape-dsl/dsl.rb
|
61
|
+
- lib/grape-dsl/endpoint.rb
|
62
|
+
- lib/grape-dsl/headers.rb
|
63
|
+
homepage: https://github.com/adamluzsi/grape-dsl
|
64
|
+
licenses:
|
65
|
+
- MIT
|
66
|
+
metadata: {}
|
67
|
+
post_install_message:
|
68
|
+
rdoc_options: []
|
69
|
+
require_paths:
|
70
|
+
- lib
|
71
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ! '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
77
|
+
requirements:
|
78
|
+
- - ! '>='
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: '0'
|
81
|
+
requirements: []
|
82
|
+
rubyforge_project:
|
83
|
+
rubygems_version: 2.2.1
|
84
|
+
signing_key:
|
85
|
+
specification_version: 4
|
86
|
+
summary: Simple Grape DSL for easer use cases
|
87
|
+
test_files: []
|
88
|
+
has_rdoc:
|