grape-dsl 1.3.0 → 2.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +63 -0
- data/LICENSE +17 -17
- data/README.md +89 -30
- data/VERSION +1 -1
- data/grape-dsl.gemspec +2 -2
- data/lib/grape-dsl.rb +13 -2
- data/lib/grape-dsl/ace.rb +110 -0
- data/lib/grape-dsl/doc.rb +7 -54
- data/lib/grape-dsl/doc_mp.rb +58 -0
- data/lib/grape-dsl/dsl.rb +64 -48
- data/lib/grape-dsl/mnt.rb +155 -0
- metadata +9 -23
- data/LICENSE.txt +0 -20
- data/lib/grape-dsl/endpoint.rb +0 -13
- data/lib/grape-dsl/headers.rb +0 -78
- data/lib/grape-dsl/mounter.rb +0 -131
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c7fd4082602f01e51467ed2c8140655173728963
|
4
|
+
data.tar.gz: 2f7021dfcfb5c9ca5c62f7c7b0e8fd5e52a8cea0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e10239cd86baaa86728eb9bf0dc68fd7d01d1dca05905a1b196a7e83c65014a6f216018251255170342b67cf177e2785763ded55807b5e678d240f41bb1b1ff6
|
7
|
+
data.tar.gz: ef7859cc6a82767ec9b0246b59f432bbd6d4dd5a06e93c217418ed46f94d29b33a5ca44864529dffe6d16d34f462f3f74a63f0959ffe7067d8c10b1b18e343e9
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
grape-dsl (2.0.0)
|
5
|
+
grape
|
6
|
+
mpatch
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
activesupport (4.1.0)
|
12
|
+
i18n (~> 0.6, >= 0.6.9)
|
13
|
+
json (~> 1.7, >= 1.7.7)
|
14
|
+
minitest (~> 5.1)
|
15
|
+
thread_safe (~> 0.1)
|
16
|
+
tzinfo (~> 1.1)
|
17
|
+
axiom-types (0.1.1)
|
18
|
+
descendants_tracker (~> 0.0.4)
|
19
|
+
ice_nine (~> 0.11.0)
|
20
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
21
|
+
builder (3.2.2)
|
22
|
+
coercible (1.0.0)
|
23
|
+
descendants_tracker (~> 0.0.1)
|
24
|
+
descendants_tracker (0.0.4)
|
25
|
+
thread_safe (~> 0.3, >= 0.3.1)
|
26
|
+
equalizer (0.0.9)
|
27
|
+
grape (0.7.0)
|
28
|
+
activesupport
|
29
|
+
builder
|
30
|
+
hashie (>= 1.2.0)
|
31
|
+
multi_json (>= 1.3.2)
|
32
|
+
multi_xml (>= 0.5.2)
|
33
|
+
rack (>= 1.3.0)
|
34
|
+
rack-accept
|
35
|
+
rack-mount
|
36
|
+
virtus (>= 1.0.0)
|
37
|
+
hashie (2.1.1)
|
38
|
+
i18n (0.6.9)
|
39
|
+
ice_nine (0.11.0)
|
40
|
+
json (1.8.1)
|
41
|
+
minitest (5.3.2)
|
42
|
+
mpatch (2.8.0)
|
43
|
+
multi_json (1.9.2)
|
44
|
+
multi_xml (0.5.5)
|
45
|
+
rack (1.5.2)
|
46
|
+
rack-accept (0.4.5)
|
47
|
+
rack (>= 0.4)
|
48
|
+
rack-mount (0.8.3)
|
49
|
+
rack (>= 1.0.0)
|
50
|
+
thread_safe (0.3.3)
|
51
|
+
tzinfo (1.1.0)
|
52
|
+
thread_safe (~> 0.1)
|
53
|
+
virtus (1.0.2)
|
54
|
+
axiom-types (~> 0.1)
|
55
|
+
coercible (~> 1.0)
|
56
|
+
descendants_tracker (~> 0.0.3)
|
57
|
+
equalizer (~> 0.0.9)
|
58
|
+
|
59
|
+
PLATFORMS
|
60
|
+
ruby
|
61
|
+
|
62
|
+
DEPENDENCIES
|
63
|
+
grape-dsl!
|
data/LICENSE
CHANGED
@@ -1,20 +1,20 @@
|
|
1
|
-
|
1
|
+
Copyright (c) 2013 Adam Luzsi
|
2
2
|
|
3
|
-
|
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:
|
4
10
|
|
5
|
-
|
6
|
-
|
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
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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.
|
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
CHANGED
@@ -4,17 +4,63 @@ Grape-DSL
|
|
4
4
|
DSL for Grape module that let you use some basic function much easier
|
5
5
|
if you use redmine wiki you can even create doc into it
|
6
6
|
|
7
|
-
|
7
|
+
## Use case
|
8
|
+
|
9
|
+
### Mount Grape api subclasses
|
8
10
|
|
9
11
|
you can mount Grape::API-s all child class with
|
10
12
|
```ruby
|
13
|
+
|
14
|
+
# options = grape options for call
|
15
|
+
# class = target class
|
16
|
+
# rest = method name / REST METHOD NAME
|
17
|
+
# prc = These procs will be called with the binding of GrapeEndpoint,
|
18
|
+
# so params and headers Hash::Mash will be allowed to use
|
19
|
+
# they will run BEFORE the method been called, so ideal for auth stuffs
|
20
|
+
#
|
21
|
+
# args = This is for argument pre parsing,
|
22
|
+
# like when you use "hash" type for an argument
|
23
|
+
# and the input should be sent as json, but you want it to be preparsed when the method receive
|
24
|
+
#
|
25
|
+
# #> method hello parameter will be preparsed before passing to method
|
26
|
+
# simple use case => args: [:hello,:json],[:sup,:yaml]
|
27
|
+
# or
|
28
|
+
# args: { hello: :json, sup: :yaml }
|
29
|
+
#
|
30
|
+
# you can give hash options just like to any other get,post put delete etc methods, it will work
|
31
|
+
#
|
32
|
+
|
33
|
+
class HelloApi < Grape::API
|
34
|
+
|
35
|
+
get 'hello' do
|
36
|
+
puts 'hello world'
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
class SupApi < Grape::API
|
42
|
+
|
43
|
+
get 'sup' do
|
44
|
+
puts 'what\'s up?'
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
|
11
50
|
class MainApi < Grape::API
|
51
|
+
|
52
|
+
# all pre app now is mounted here ("/hello","/sup")
|
12
53
|
mount_subclasses
|
54
|
+
|
13
55
|
end
|
56
|
+
|
14
57
|
```
|
15
58
|
|
16
|
-
|
17
|
-
|
59
|
+
### Mount singleton methods as Rest calls
|
60
|
+
|
61
|
+
You can even set arguments to be json or yaml so it will be parsed before passing to method
|
62
|
+
In the default usecase, the mount process will read the method source for documentation for making desc
|
63
|
+
|
18
64
|
```ruby
|
19
65
|
|
20
66
|
class TestClass
|
@@ -23,7 +69,6 @@ ps.: you can even set arguments to be json or yaml so it will be parsed before p
|
|
23
69
|
|
24
70
|
end
|
25
71
|
|
26
|
-
def self.complex_method
|
27
72
|
def self.complex_method hello, world="default", opts={},*args
|
28
73
|
|
29
74
|
puts "hello: #{hello}"
|
@@ -38,43 +83,57 @@ ps.: you can even set arguments to be json or yaml so it will be parsed before p
|
|
38
83
|
|
39
84
|
class Api < Grape::API
|
40
85
|
|
41
|
-
mount_method TestClass, :test_method
|
42
|
-
|
86
|
+
mount_method class: TestClass,method: :test_method
|
87
|
+
# or
|
88
|
+
mount_method method: TestClass.method(:test_method)
|
89
|
+
|
90
|
+
mount_method class: Test,
|
91
|
+
method: :test,
|
92
|
+
path: "hello_world",
|
93
|
+
args: [[:opts,:yaml],[:args,:json]]
|
94
|
+
|
43
95
|
|
44
96
|
end
|
45
97
|
|
46
98
|
```
|
47
99
|
|
48
|
-
|
49
|
-
|
50
|
-
|
100
|
+
### Access Control for ips
|
101
|
+
|
102
|
+
you can manipulate and ban ips from unwelcomed sources
|
51
103
|
|
52
|
-
|
104
|
+
you can give static ips , or ranges by replacing number parts with stars
|
105
|
+
|
106
|
+
```ruby
|
53
107
|
|
54
|
-
|
108
|
+
"192.168.1.2" == "192.168.1.2"
|
109
|
+
"192.168.1.*" == ["192.168.1.0".."192.168.1.255"]
|
55
110
|
|
111
|
+
```
|
112
|
+
|
113
|
+
here is an example for the use
|
114
|
+
|
115
|
+
```ruby
|
56
116
|
|
57
|
-
|
117
|
+
class API < Grape::API
|
58
118
|
|
59
|
-
|
119
|
+
get :hello do
|
60
120
|
|
61
|
-
|
121
|
+
allowed_ips "192.168.*.*"
|
122
|
+
banned_ip "192.168.1.2"
|
62
123
|
|
63
|
-
|
64
|
-
a copy of this software and associated documentation files (the
|
65
|
-
'Software'), to deal in the Software without restriction, including
|
66
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
67
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
68
|
-
permit persons to whom the Software is furnished to do so, subject to
|
69
|
-
the following conditions:
|
124
|
+
# some stuff to do here
|
70
125
|
|
71
|
-
|
72
|
-
|
126
|
+
end
|
127
|
+
|
128
|
+
get :hello_world do
|
129
|
+
|
130
|
+
allowed_ips %W[ 192.168.*.* 127.0.0.1 ]
|
131
|
+
banned_ip ["192.168.1.2","192.168.1.1"]
|
132
|
+
|
133
|
+
# some stuff to do here
|
134
|
+
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
73
138
|
|
74
|
-
|
75
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
76
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
77
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
78
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
79
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
80
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
139
|
+
```
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
2.0.1
|
data/grape-dsl.gemspec
CHANGED
@@ -19,8 +19,8 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.add_dependency "
|
22
|
+
#spec.add_dependency "bindless"
|
23
|
+
spec.add_dependency "mpatch", '>= 2.8.0'
|
23
24
|
spec.add_dependency "grape"
|
24
|
-
spec.add_dependency "bindless"
|
25
25
|
|
26
26
|
end
|
data/lib/grape-dsl.rb
CHANGED
@@ -1,11 +1,22 @@
|
|
1
1
|
#encoding: UTF-8
|
2
2
|
module GrapeDSL
|
3
3
|
|
4
|
-
require '
|
4
|
+
#require 'bindless'
|
5
|
+
#require 'procemon'
|
6
|
+
#require 'mpatch'
|
7
|
+
|
8
|
+
require 'mpatch/module'
|
9
|
+
require 'mpatch/method'
|
10
|
+
MPatch.patch!
|
11
|
+
|
5
12
|
require 'grape'
|
13
|
+
|
6
14
|
require 'json'
|
7
15
|
require 'yaml'
|
8
16
|
|
9
|
-
|
17
|
+
require 'grape-dsl/doc'
|
18
|
+
require 'grape-dsl/dsl'
|
19
|
+
require 'grape-dsl/ace'
|
20
|
+
require 'grape-dsl/mnt'
|
10
21
|
|
11
22
|
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
module GrapeDSL
|
2
|
+
module Include
|
3
|
+
module AccessControlEndpoint
|
4
|
+
|
5
|
+
def generate_ip_regexp_collection *args
|
6
|
+
|
7
|
+
if args.empty?
|
8
|
+
raise ArgumentError, "missing ip(s) for allowed sources"
|
9
|
+
end
|
10
|
+
|
11
|
+
@cached_regexp_collection ||= {}
|
12
|
+
if @cached_regexp_collection[args].nil?
|
13
|
+
@cached_regexp_collection= {}
|
14
|
+
|
15
|
+
ip_regex_collection= []
|
16
|
+
args.each do |ip_addr|
|
17
|
+
|
18
|
+
ip_regex_builder= [[],[],[],[]]
|
19
|
+
|
20
|
+
#ip_addr.to_s.check(/([0-9\*]{1,3}\.){3}([0-9\*]{1,3})/)#(/([0-9\*]{1,3}\.){3}(0|\*)$/)
|
21
|
+
if (ip_addr.to_s =~ /([0-9\*]{1,3}\.){3}([0-9\*]{1,3})/).nil? ? false : true
|
22
|
+
|
23
|
+
ip_addr_index= 0
|
24
|
+
ip_addr.split('.').each do |ip_addr_part|
|
25
|
+
|
26
|
+
# 0.0.0.0
|
27
|
+
# 255.255.255.255
|
28
|
+
|
29
|
+
if ip_addr_part.include?("*")
|
30
|
+
ip_regex_builder[ip_addr_index]= "([0-9]{1,2}|1[0-9]{2}|2[0-4][0-9]|25[0-5])"
|
31
|
+
else
|
32
|
+
ip_regex_builder[ip_addr_index].push(ip_addr_part)
|
33
|
+
end
|
34
|
+
|
35
|
+
# increment index
|
36
|
+
ip_addr_index += 1
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
else
|
41
|
+
next
|
42
|
+
end
|
43
|
+
|
44
|
+
ip_regex_builder.map! do |element|
|
45
|
+
|
46
|
+
case true
|
47
|
+
|
48
|
+
when element.class <= Regexp
|
49
|
+
element.inspect[1..(element.inspect.length-2)]
|
50
|
+
|
51
|
+
when element.class <= String
|
52
|
+
element
|
53
|
+
|
54
|
+
when element.class <= Array
|
55
|
+
"(#{element.join('|')})"
|
56
|
+
|
57
|
+
else
|
58
|
+
element.to_s
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
ip_regex_collection.push /#{ip_regex_builder.join('\.')}/
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
@cached_regexp_collection[args]= ip_regex_collection
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
return @cached_regexp_collection[args]
|
73
|
+
|
74
|
+
end
|
75
|
+
|
76
|
+
def allowed_ips *args
|
77
|
+
|
78
|
+
tests= generate_ip_regexp_collection(*args).map{ |regexp|
|
79
|
+
request.instance_variable_get("@env")['REMOTE_ADDR'] =~ regexp
|
80
|
+
}.compact
|
81
|
+
|
82
|
+
if tests.empty?
|
83
|
+
error!('403.6 - IP address rejected.', 403)
|
84
|
+
end
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
alias :allowed_ip :allowed_ips
|
89
|
+
|
90
|
+
def banned_ips *args
|
91
|
+
|
92
|
+
tests= generate_ip_regexp_collection(*args).map{ |regexp|
|
93
|
+
request.instance_variable_get("@env")['REMOTE_ADDR'] =~ regexp
|
94
|
+
}.compact
|
95
|
+
|
96
|
+
unless tests.empty?
|
97
|
+
error!('403.6 - IP address rejected.', 403)
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
alias :banned_ip :banned_ips
|
103
|
+
|
104
|
+
|
105
|
+
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
110
|
+
Grape::Endpoint.__send__ :include, ::GrapeDSL::Include::AccessControlEndpoint
|
data/lib/grape-dsl/doc.rb
CHANGED
@@ -1,52 +1,3 @@
|
|
1
|
-
|
2
|
-
class Array
|
3
|
-
def convert_all_value_to_s
|
4
|
-
|
5
|
-
self.count.times do |index|
|
6
|
-
|
7
|
-
case self[index].class.to_s.downcase
|
8
|
-
|
9
|
-
when "hash"
|
10
|
-
self[index].convert_all_value_to_s
|
11
|
-
|
12
|
-
when "array"
|
13
|
-
self[index].convert_all_value_to_s
|
14
|
-
|
15
|
-
else
|
16
|
-
self[index]= self[index].to_s
|
17
|
-
|
18
|
-
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
22
|
-
|
23
|
-
return self
|
24
|
-
end
|
25
|
-
end
|
26
|
-
class Hash
|
27
|
-
def convert_all_value_to_s
|
28
|
-
|
29
|
-
self.each do |key,value|
|
30
|
-
|
31
|
-
case value.class.to_s.downcase
|
32
|
-
|
33
|
-
when "hash"
|
34
|
-
value.convert_all_value_to_s
|
35
|
-
|
36
|
-
when "array"
|
37
|
-
value.convert_all_value_to_s
|
38
|
-
|
39
|
-
else
|
40
|
-
self[key]= value.to_s
|
41
|
-
|
42
|
-
end
|
43
|
-
|
44
|
-
end
|
45
|
-
|
46
|
-
return self
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
1
|
module GrapeDSL
|
51
2
|
module Extend
|
52
3
|
module Doc
|
@@ -58,6 +9,8 @@ module GrapeDSL
|
|
58
9
|
# helpers for doc generation
|
59
10
|
def wiki_body(route,wrapper_begin,wrapper_end,wrapper_close)
|
60
11
|
|
12
|
+
require 'grape-dsl/doc_mp'
|
13
|
+
|
61
14
|
description_key= :body
|
62
15
|
tmp_array= Array.new()
|
63
16
|
params= nil
|
@@ -296,12 +249,12 @@ module GrapeDSL
|
|
296
249
|
isym= "_"
|
297
250
|
|
298
251
|
htsym= "* "
|
299
|
-
mtsym=
|
300
|
-
stsym=
|
252
|
+
mtsym= " * "
|
253
|
+
stsym= " * "
|
301
254
|
|
302
|
-
hheader= "
|
303
|
-
mheader=
|
304
|
-
sheader=
|
255
|
+
hheader= "## "
|
256
|
+
mheader= "### "
|
257
|
+
sheader= "#### "
|
305
258
|
|
306
259
|
container_markup_begin= "```"
|
307
260
|
container_markup_end= ""
|
@@ -0,0 +1,58 @@
|
|
1
|
+
|
2
|
+
module GrapeDSL
|
3
|
+
module EXT
|
4
|
+
|
5
|
+
module ArrayMP
|
6
|
+
def convert_all_value_to_s
|
7
|
+
|
8
|
+
self.count.times do |index|
|
9
|
+
|
10
|
+
case self[index].class.to_s.downcase
|
11
|
+
|
12
|
+
when "hash"
|
13
|
+
self[index].convert_all_value_to_s
|
14
|
+
|
15
|
+
when "array"
|
16
|
+
self[index].convert_all_value_to_s
|
17
|
+
|
18
|
+
else
|
19
|
+
self[index]= self[index].to_s
|
20
|
+
|
21
|
+
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
return self
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
module HashMP
|
31
|
+
def convert_all_value_to_s
|
32
|
+
|
33
|
+
self.each do |key,value|
|
34
|
+
|
35
|
+
case value.class.to_s.downcase
|
36
|
+
|
37
|
+
when "hash"
|
38
|
+
value.convert_all_value_to_s
|
39
|
+
|
40
|
+
when "array"
|
41
|
+
value.convert_all_value_to_s
|
42
|
+
|
43
|
+
else
|
44
|
+
self[key]= value.to_s
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
return self
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
Array.__send__ :include, GrapeDSL::EXT::ArrayMP
|
58
|
+
Hash.__send__ :include, GrapeDSL::EXT::HashMP
|
data/lib/grape-dsl/dsl.rb
CHANGED
@@ -1,75 +1,91 @@
|
|
1
1
|
#encoding: UTF-8
|
2
|
-
|
3
2
|
module GrapeDSL
|
4
3
|
module Extend
|
5
4
|
|
6
|
-
module
|
5
|
+
module APIMNT
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
# defaults
|
8
|
+
# desc -> description for path
|
9
|
+
# body -> return body from the call
|
10
|
+
# convent_type -> real content type
|
11
|
+
def description
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
13
|
+
if desc.class <= String
|
14
|
+
tmp_string= desc
|
15
|
+
desc ::Hashie::Mash.new
|
16
|
+
desc[:desc]= tmp_string
|
17
|
+
end
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
unless desc.class <= Hash
|
20
|
+
desc ::Hashie::Mash.new
|
21
|
+
end
|
23
22
|
|
24
|
-
|
23
|
+
unless self.content_types.keys.empty?
|
25
24
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
end
|
25
|
+
content_type_name= nil
|
26
|
+
[:json,:xml,:txt].each do |element|
|
27
|
+
if self.content_types.keys.include? element
|
28
|
+
content_type_name ||= element.to_s.upcase
|
31
29
|
end
|
32
|
-
desc[:convent_type] ||= content_type_name
|
33
|
-
|
34
30
|
end
|
35
|
-
|
36
|
-
return desc
|
31
|
+
desc[:convent_type] ||= content_type_name
|
37
32
|
|
38
33
|
end
|
39
34
|
|
40
|
-
|
41
|
-
# make easy to manage
|
42
|
-
def mount_subclasses(*exception)
|
35
|
+
return desc
|
43
36
|
|
44
|
-
|
45
|
-
begin
|
46
|
-
exception.push(self)
|
47
|
-
end
|
37
|
+
end
|
48
38
|
|
49
|
-
|
50
|
-
|
51
|
-
Grape::API.subclasses.each do |component|
|
52
|
-
unless exception.include?(component)
|
53
|
-
mount(component)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
39
|
+
# mount all the rest api classes that is subclass of the Grape::API
|
40
|
+
# make easy to manage
|
57
41
|
|
58
|
-
|
42
|
+
def mount_api opts= {}
|
59
43
|
|
44
|
+
unless opts.class <= Hash
|
45
|
+
raise ArgumentError,"invalid option object given, must be hash like!"
|
60
46
|
end
|
61
47
|
|
62
|
-
|
63
|
-
|
48
|
+
opts[:ex] ||= opts[:except] || opts[:exception] || opts[:e] || []
|
49
|
+
opts[:in] ||= opts[:include] || opts[:inclusion] || opts[:i] || []
|
50
|
+
|
51
|
+
[:ex,:in].each{|sym| (opts[sym]=[opts[sym]]) unless opts[sym].class <= Array }
|
52
|
+
|
53
|
+
# mount components
|
54
|
+
Grape::API.inherited_by.each do |component|
|
64
55
|
|
65
|
-
|
66
|
-
|
67
|
-
$stdout.puts "\t#{route.route_method}","#{route.route_path}"
|
56
|
+
unless opts[:ex].include?(component) || self == component
|
57
|
+
mount(component)
|
68
58
|
end
|
69
59
|
|
70
|
-
return nil
|
71
60
|
end
|
72
61
|
|
62
|
+
opts[:in].each{|cls| self.mount(cls) }
|
63
|
+
|
64
|
+
return nil
|
65
|
+
|
66
|
+
end
|
67
|
+
|
68
|
+
alias :mount_apis :mount_api
|
69
|
+
|
70
|
+
def mount_subclasses(*exception)
|
71
|
+
mount_api ex: exception
|
72
|
+
end
|
73
|
+
|
74
|
+
alias :mount_classes :mount_subclasses
|
75
|
+
|
76
|
+
# write out to the console the class routes
|
77
|
+
def console_write_out_routes
|
78
|
+
|
79
|
+
$stdout.puts "\n\nREST::API ROUTES:"
|
80
|
+
self.routes.each do |route|
|
81
|
+
$stdout.puts "#{route.route_method}","\t#{route.route_path}\n---\n"
|
82
|
+
end
|
83
|
+
|
84
|
+
return nil
|
85
|
+
end
|
86
|
+
|
87
|
+
alias :cw_routes :console_write_out_routes
|
88
|
+
|
73
89
|
|
74
90
|
end
|
75
91
|
|
@@ -77,4 +93,4 @@ module GrapeDSL
|
|
77
93
|
|
78
94
|
end
|
79
95
|
|
80
|
-
Grape::API.__send__ :extend, ::GrapeDSL::Extend::
|
96
|
+
Grape::API.__send__ :extend, ::GrapeDSL::Extend::APIMNT
|
@@ -0,0 +1,155 @@
|
|
1
|
+
# this is super if you want CORS with Grape
|
2
|
+
# This is a plugin for Mongoid
|
3
|
+
# models rest layer generate
|
4
|
+
module GrapeDSL
|
5
|
+
module Extend
|
6
|
+
module Mounter
|
7
|
+
|
8
|
+
# options = grape options element
|
9
|
+
# class = target class
|
10
|
+
# rest = method name / REST METHOD NAME
|
11
|
+
# prc = These procs will be called with the binding of GrapeEndpoint,
|
12
|
+
# so params and headers Hash::Mash will be allowed to use
|
13
|
+
# they will run BEFORE the method been called, so ideal for auth stuffs
|
14
|
+
#
|
15
|
+
# args = This is for argument pre parsing,
|
16
|
+
# like when you use "hash" type for an argument
|
17
|
+
# and the input should be sent as json, but you want it to be preparsed when the method receive
|
18
|
+
#
|
19
|
+
# #> method hello parameter will be preparsed before passing to method
|
20
|
+
# simple use case => args: [:hello,:json],[:sup,:yaml]
|
21
|
+
# or
|
22
|
+
# args: { hello: :json, sup: :yaml }
|
23
|
+
#
|
24
|
+
#
|
25
|
+
# ---------------
|
26
|
+
#
|
27
|
+
# looks like this with FULL POWER:
|
28
|
+
# mount_method rest: :get,
|
29
|
+
# class: TestClass,
|
30
|
+
# method: :test_method,
|
31
|
+
# path: "funny_path/okey",
|
32
|
+
# args: [[:arg_hello,:json]],#> or args: { arg_hello: :json }
|
33
|
+
# prc: Proc{ authorize_instance_method_from_grape_endpoint }
|
34
|
+
#
|
35
|
+
# you can give hash options just like to any other get,post put delete etc methods, it will work
|
36
|
+
#
|
37
|
+
def mount_method opts= {}, &block
|
38
|
+
|
39
|
+
unless opts.class <= Hash
|
40
|
+
raise ArgumentError, "invalid input, must be Hash like obj"
|
41
|
+
end
|
42
|
+
|
43
|
+
# required
|
44
|
+
opts[:method] ||= opts[:m] || raise(ArgumentError,"missing method input(:method)")
|
45
|
+
|
46
|
+
# optional
|
47
|
+
opts[:options] ||= opts[:o] || {}
|
48
|
+
opts[:rest_method] ||= opts[:r] || opts[:protocol] || opts[:rest] || opts[:rm] || :get
|
49
|
+
opts[:proc] ||= opts[:h] || opts[:prc] || opts[:hook] || block || Proc.new{}
|
50
|
+
opts[:path] ||= opts[:p] || opts[:method].name
|
51
|
+
opts[:args] ||= opts[:a] || opts[:arg] || {}
|
52
|
+
|
53
|
+
if opts[:method].class <= String || opts[:method].class <= Symbol
|
54
|
+
|
55
|
+
opts[:class] ||= opts[:c] || opts[:module] || raise(ArgumentError,"missing method input(:method)")
|
56
|
+
opts[:method] = opts[:class].method(opts[:method])
|
57
|
+
|
58
|
+
end
|
59
|
+
|
60
|
+
if opts[:args].class <= Array
|
61
|
+
|
62
|
+
tmp_hash = Hash.new
|
63
|
+
opts[:args].each do |array_obj|
|
64
|
+
if array_obj.count == 2
|
65
|
+
tmp_hash[array_obj[0]]= array_obj[1]
|
66
|
+
end
|
67
|
+
end
|
68
|
+
opts[:args]= tmp_hash
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
{
|
73
|
+
|
74
|
+
options: Hash,
|
75
|
+
rest_method: Symbol,
|
76
|
+
proc: Proc,
|
77
|
+
path: String,
|
78
|
+
args: Hash,
|
79
|
+
method: Method
|
80
|
+
|
81
|
+
}.each { |key,type|
|
82
|
+
unless opts[key].class <= type
|
83
|
+
raise(ArgumentError,"invalid #{key} value, must instance of an inherited class from #{type}")
|
84
|
+
end
|
85
|
+
}
|
86
|
+
|
87
|
+
opts[:rest_method] = opts[:rest_method].to_s.downcase.to_sym
|
88
|
+
|
89
|
+
desc opts[:method].get_comments
|
90
|
+
|
91
|
+
params do
|
92
|
+
|
93
|
+
opts[:method].parameters.each do |array_obj|
|
94
|
+
|
95
|
+
case array_obj[0]
|
96
|
+
|
97
|
+
when :req
|
98
|
+
requires array_obj[1]
|
99
|
+
when :opt
|
100
|
+
optional array_obj[1]
|
101
|
+
when :rest
|
102
|
+
optional array_obj[1],
|
103
|
+
type: Array
|
104
|
+
|
105
|
+
#when :block
|
106
|
+
# optional array_obj[1],
|
107
|
+
# type: String,
|
108
|
+
# desc: "Ruby code to be used"
|
109
|
+
|
110
|
+
|
111
|
+
end
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
|
117
|
+
self.__send__(opts[:rest_method], opts[:path], opts[:options]) do
|
118
|
+
|
119
|
+
opts[:proc].call_with_binding self.binding?
|
120
|
+
opts[:method].call(
|
121
|
+
|
122
|
+
*opts[:method].parameters.map { |element|
|
123
|
+
|
124
|
+
unless params[element[1]].nil?
|
125
|
+
|
126
|
+
# parse if requested
|
127
|
+
case opts[:args][element[1]].to_s
|
128
|
+
when 'json'
|
129
|
+
params[element[1]]= JSON.parse(params[element[1]])
|
130
|
+
|
131
|
+
when 'yaml', 'yml'
|
132
|
+
params[element[1]]= YAML.parse(params[element[1]])
|
133
|
+
|
134
|
+
end
|
135
|
+
|
136
|
+
# add new element
|
137
|
+
params[element[1]]
|
138
|
+
|
139
|
+
end
|
140
|
+
|
141
|
+
}.compact
|
142
|
+
|
143
|
+
)
|
144
|
+
|
145
|
+
end
|
146
|
+
|
147
|
+
|
148
|
+
end
|
149
|
+
|
150
|
+
|
151
|
+
end
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
Grape::API.__send__ :extend, ::GrapeDSL::Extend::Mounter
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grape-dsl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.1
|
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-04-
|
11
|
+
date: 2014-04-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: mpatch
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 2.8.0
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
26
|
+
version: 2.8.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: grape
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -38,20 +38,6 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: bindless
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - ">="
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '0'
|
48
|
-
type: :runtime
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '0'
|
55
41
|
description: DSL for Grape module that let you use some basic function much easier.
|
56
42
|
For example mount all Grape class into a single one with a simple line
|
57
43
|
email:
|
@@ -61,19 +47,19 @@ extensions: []
|
|
61
47
|
extra_rdoc_files: []
|
62
48
|
files:
|
63
49
|
- Gemfile
|
50
|
+
- Gemfile.lock
|
64
51
|
- LICENSE
|
65
|
-
- LICENSE.txt
|
66
52
|
- README.md
|
67
53
|
- Rakefile
|
68
54
|
- VERSION
|
69
55
|
- files.rb
|
70
56
|
- grape-dsl.gemspec
|
71
57
|
- lib/grape-dsl.rb
|
58
|
+
- lib/grape-dsl/ace.rb
|
72
59
|
- lib/grape-dsl/doc.rb
|
60
|
+
- lib/grape-dsl/doc_mp.rb
|
73
61
|
- lib/grape-dsl/dsl.rb
|
74
|
-
- lib/grape-dsl/
|
75
|
-
- lib/grape-dsl/headers.rb
|
76
|
-
- lib/grape-dsl/mounter.rb
|
62
|
+
- lib/grape-dsl/mnt.rb
|
77
63
|
homepage: https://github.com/adamluzsi/grape-dsl
|
78
64
|
licenses:
|
79
65
|
- MIT
|
data/LICENSE.txt
DELETED
@@ -1,20 +0,0 @@
|
|
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/lib/grape-dsl/endpoint.rb
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
module GrapeDSL
|
2
|
-
module Extend
|
3
|
-
module Endpoint
|
4
|
-
|
5
|
-
attr_accessor :header_config_obj
|
6
|
-
alias :config_obj :header_config_obj
|
7
|
-
alias :config_obj= :header_config_obj=
|
8
|
-
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
Grape::Endpoint.__send__ :extend, ::GrapeDSL::Extend::Endpoint
|
data/lib/grape-dsl/headers.rb
DELETED
@@ -1,78 +0,0 @@
|
|
1
|
-
|
2
|
-
module GrapeDSL
|
3
|
-
module Extend
|
4
|
-
module Headers
|
5
|
-
|
6
|
-
# example in yaml format
|
7
|
-
# "header_name":
|
8
|
-
# - "header values"
|
9
|
-
# - "header value 2"
|
10
|
-
#
|
11
|
-
#
|
12
|
-
# real example for cors
|
13
|
-
# "Access-Control-Allow-Headers":
|
14
|
-
# - "X-Idp-Id"
|
15
|
-
# - "X-Token"
|
16
|
-
# - "Content-Type"
|
17
|
-
# "Access-Control-Allow-Origin":
|
18
|
-
# - "*"
|
19
|
-
# "Access-Control-Allow-Methods":
|
20
|
-
# - HEAD
|
21
|
-
# - OPTIONS
|
22
|
-
# - GET
|
23
|
-
# - POST
|
24
|
-
# - PUT
|
25
|
-
# - DELETE
|
26
|
-
#
|
27
|
-
#
|
28
|
-
# This will give headers to all call request response made after this
|
29
|
-
# make sure to load BEFORE every route call going to be made
|
30
|
-
def response_headers_to_new_calls(config_obj=nil)
|
31
|
-
|
32
|
-
Grape::Endpoint.config_obj= config_obj unless config_obj.nil?
|
33
|
-
Grape::API.inject_singleton_method :inherited, add: "after" do |subclass|
|
34
|
-
|
35
|
-
subclass.class_eval do
|
36
|
-
|
37
|
-
before do
|
38
|
-
Grape::Endpoint.header_config_obj.each do |header_key,header_value|
|
39
|
-
header header_key, header_value.join(', ')
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
end
|
44
|
-
|
45
|
-
end
|
46
|
-
|
47
|
-
return nil
|
48
|
-
end
|
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
|
-
end
|
75
|
-
end
|
76
|
-
end
|
77
|
-
|
78
|
-
Grape.__send__ :extend, ::GrapeDSL::Extend::Headers
|
data/lib/grape-dsl/mounter.rb
DELETED
@@ -1,131 +0,0 @@
|
|
1
|
-
# this is super if you want CORS with Grape
|
2
|
-
# This is a plugin for Mongoid
|
3
|
-
# models rest layer generate
|
4
|
-
module GrapeDSL
|
5
|
-
module Extend
|
6
|
-
module Mounter
|
7
|
-
|
8
|
-
# Args will be seperated by they class type
|
9
|
-
# string = path part, will be joined with "/"
|
10
|
-
# hash = grape options element
|
11
|
-
# Class = target class
|
12
|
-
# Symbol = method name / REST METHOD NAME
|
13
|
-
# Proc = These procs will be called with the binding of GrapeEndpoint,
|
14
|
-
# so params and headers Hash::Mash will be allowed to use
|
15
|
-
# they will run BEFORE the method been called, so ideal for auth stuffs
|
16
|
-
#
|
17
|
-
# Array = This is for argument pre parsing, like when you use "hash" and the input will be a json
|
18
|
-
#
|
19
|
-
# simple use case: [:hello,:json],[:sup,:yaml]
|
20
|
-
#
|
21
|
-
#
|
22
|
-
# ---------------
|
23
|
-
#
|
24
|
-
# looks like this with FULL POWER:
|
25
|
-
# mount_method :GET,
|
26
|
-
# TestClass,
|
27
|
-
# :test_method,
|
28
|
-
# "funny_path_first_part",
|
29
|
-
# "funny_path_second_part",
|
30
|
-
# [:arg_hello,:json],
|
31
|
-
# Proc{ authorize_instance_method_from_grape_endpoint }
|
32
|
-
#
|
33
|
-
# you can give hash options just like to any other get,post put delete etc methods, it will work
|
34
|
-
#
|
35
|
-
def mount_method *args
|
36
|
-
|
37
|
-
options = Hash[*args.extract_class!(Hash)]
|
38
|
-
path_name = args.extract_class!(String).join('/')
|
39
|
-
class_name = args.extract_class!(Class)[0]
|
40
|
-
before_procs = args.extract_class!(Proc)
|
41
|
-
|
42
|
-
tmp_array = args.extract_class!(Array)
|
43
|
-
adapter_opt = Hash.new
|
44
|
-
|
45
|
-
tmp_array.each do |array_obj|
|
46
|
-
if array_obj.count == 2
|
47
|
-
adapter_opt[array_obj[0]]= array_obj[1]
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
method_name = nil
|
52
|
-
rest_method = nil
|
53
|
-
|
54
|
-
args.extract_class!(Symbol).each do |element|
|
55
|
-
if element.to_s == element.to_s.downcase
|
56
|
-
method_name = element
|
57
|
-
elsif element.to_s == element.to_s.upcase
|
58
|
-
rest_method = element.to_s.downcase
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
rest_method ||= "get"
|
63
|
-
method_obj = class_name.method(method_name).clone
|
64
|
-
|
65
|
-
if path_name == String.new
|
66
|
-
path_name= method_name.to_s
|
67
|
-
end
|
68
|
-
|
69
|
-
|
70
|
-
params do
|
71
|
-
|
72
|
-
method_obj.parameters.each do |array_obj|
|
73
|
-
|
74
|
-
case array_obj[0]
|
75
|
-
|
76
|
-
when :req
|
77
|
-
requires array_obj[1]
|
78
|
-
when :opt
|
79
|
-
optional array_obj[1]
|
80
|
-
when :rest
|
81
|
-
optional array_obj[1],
|
82
|
-
type: Array
|
83
|
-
|
84
|
-
#when :block
|
85
|
-
# optional array_obj[1],
|
86
|
-
# type: String,
|
87
|
-
# desc: "Ruby code to be used"
|
88
|
-
|
89
|
-
|
90
|
-
end
|
91
|
-
|
92
|
-
end
|
93
|
-
|
94
|
-
end
|
95
|
-
|
96
|
-
__send__(rest_method,path_name,options) do
|
97
|
-
|
98
|
-
|
99
|
-
method_arguments= (method_obj.parameters.map{|element|
|
100
|
-
if !params[element[1]].nil?
|
101
|
-
|
102
|
-
case adapter_opt[element[1]]
|
103
|
-
when :json
|
104
|
-
params[element[1]]= JSON.parse(params[element[1]])
|
105
|
-
|
106
|
-
when :yaml
|
107
|
-
params[element[1]]= YAML.parse(params[element[1]])
|
108
|
-
|
109
|
-
end
|
110
|
-
|
111
|
-
params[element[1]]
|
112
|
-
end
|
113
|
-
}-[nil])
|
114
|
-
|
115
|
-
before_procs.each do |proc_obj|
|
116
|
-
proc_obj.call_with_binding self.binding?
|
117
|
-
end
|
118
|
-
|
119
|
-
method_obj.call(*method_arguments)
|
120
|
-
|
121
|
-
end
|
122
|
-
|
123
|
-
|
124
|
-
end
|
125
|
-
|
126
|
-
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
Grape::API.__send__ :extend, ::GrapeDSL::Extend::Mounter
|