grape-dsl 1.2.2 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,46 +1,80 @@
1
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
2
 
18
- # mount components
19
- begin
20
- Grape::API.subclasses.each do |component|
21
- unless exception.include?(component)
22
- mount(component)
3
+ module GrapeDSL
4
+ module Extend
5
+
6
+ module API
7
+
8
+ # defaults
9
+ # desc -> description for path
10
+ # body -> return body from the call
11
+ # convent_type -> real content type
12
+ def description
13
+
14
+ if desc.class <= String
15
+ tmp_string= desc
16
+ desc ::Hashie::Mash.new
17
+ desc[:desc]= tmp_string
18
+ end
19
+
20
+ unless desc.class <= Hash
21
+ desc ::Hashie::Mash.new
22
+ end
23
+
24
+ unless self.content_types.keys.empty?
25
+
26
+ content_type_name= nil
27
+ [:json,:xml,:txt].each do |element|
28
+ if self.content_types.keys.include? element
29
+ content_type_name ||= element.to_s.upcase
30
+ end
23
31
  end
32
+ desc[:convent_type] ||= content_type_name
33
+
24
34
  end
35
+
36
+ return desc
37
+
25
38
  end
26
39
 
27
- return nil
40
+ # mount all the rest api classes that is subclass of the Grape::API
41
+ # make easy to manage
42
+ def mount_subclasses(*exception)
43
+
44
+ # mark self as exception
45
+ begin
46
+ exception.push(self)
47
+ end
28
48
 
29
- end
49
+ # mount components
50
+ begin
51
+ Grape::API.subclasses.each do |component|
52
+ unless exception.include?(component)
53
+ mount(component)
54
+ end
55
+ end
56
+ end
30
57
 
31
- # write out to the console the class routes
32
- def console_write_out_routes
58
+ return nil
33
59
 
34
- $stdout.puts "\n\nREST::API ROUTES:"
35
- self.routes.map do |route|
36
- $stdout.puts "\t#{route.route_method}","#{route.route_path}"
37
60
  end
38
61
 
39
- return nil
40
- end
62
+ # write out to the console the class routes
63
+ def console_write_out_routes
64
+
65
+ $stdout.puts "\n\nREST::API ROUTES:"
66
+ self.routes.map do |route|
67
+ $stdout.puts "\t#{route.route_method}","#{route.route_path}"
68
+ end
69
+
70
+ return nil
71
+ end
41
72
 
42
73
 
43
74
  end
75
+
44
76
  end
77
+
45
78
  end
46
79
 
80
+ Grape::API.__send__ :extend, ::GrapeDSL::Extend::API
@@ -1,15 +1,13 @@
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
1
+ module GrapeDSL
2
+ module Extend
3
+ module Endpoint
9
4
 
5
+ attr_accessor :header_config_obj
10
6
  alias :config_obj :header_config_obj
11
7
  alias :config_obj= :header_config_obj=
12
8
 
13
9
  end
14
10
  end
15
- end
11
+ end
12
+
13
+ Grape::Endpoint.__send__ :extend, ::GrapeDSL::Extend::Endpoint
@@ -1,76 +1,78 @@
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(', ')
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
39
41
  end
42
+
40
43
  end
41
44
 
42
45
  end
43
46
 
47
+ return nil
44
48
  end
45
49
 
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)
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
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
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
59
 
60
- options path do
61
- Grape::Endpoint.header_config_obj.each do |header_key,header_value|
62
- header header_key, header_value.join(', ')
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
63
64
  end
64
- end
65
65
 
66
+ end
66
67
  end
68
+
67
69
  end
68
70
 
71
+ return nil
69
72
  end
70
73
 
71
- return nil
72
74
  end
73
-
74
-
75
75
  end
76
- end
76
+ end
77
+
78
+ Grape.__send__ :extend, ::GrapeDSL::Extend::Headers
@@ -1,21 +1,15 @@
1
1
  # this is super if you want CORS with Grape
2
2
  # This is a plugin for Mongoid
3
3
  # models rest layer generate
4
- module Grape
5
- # The API class is the primary entry point for
6
- # creating Grape APIs.Users should subclass this
7
- # class in order to build an API.
8
-
9
- class API
10
-
11
- class << self
12
-
4
+ module GrapeDSL
5
+ module Extend
6
+ module Mounter
13
7
 
14
8
  # Args will be seperated by they class type
15
9
  # string = path part, will be joined with "/"
16
- # hash = options element
10
+ # hash = grape options element
17
11
  # Class = target class
18
- # Symbol = method name
12
+ # Symbol = method name / REST METHOD NAME
19
13
  # Proc = These procs will be called with the binding of GrapeEndpoint,
20
14
  # so params and headers Hash::Mash will be allowed to use
21
15
  # they will run BEFORE the method been called, so ideal for auth stuffs
@@ -27,8 +21,14 @@ module Grape
27
21
  #
28
22
  # ---------------
29
23
  #
30
- # looks like this:
31
- # mount_method TestClass, :test_method, "funny_path",:GET
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
32
  #
33
33
  # you can give hash options just like to any other get,post put delete etc methods, it will work
34
34
  #
@@ -93,7 +93,6 @@ module Grape
93
93
 
94
94
  end
95
95
 
96
-
97
96
  __send__(rest_method,path_name,options) do
98
97
 
99
98
 
@@ -124,6 +123,9 @@ module Grape
124
123
 
125
124
  end
126
125
 
126
+
127
127
  end
128
128
  end
129
- end
129
+ end
130
+
131
+ Grape::API.__send__ :extend, ::GrapeDSL::Extend::Mounter
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape-dsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Luzsi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-02-25 00:00:00.000000000 Z
11
+ date: 2014-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: loader
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>='
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
19
  version: '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
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: grape
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ! '>='
31
+ - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ! '>='
38
+ - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bindless
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  description: DSL for Grape module that let you use some basic function much easier.
@@ -69,7 +69,6 @@ files:
69
69
  - files.rb
70
70
  - grape-dsl.gemspec
71
71
  - lib/grape-dsl.rb
72
- - lib/grape-dsl/config.rb
73
72
  - lib/grape-dsl/doc.rb
74
73
  - lib/grape-dsl/dsl.rb
75
74
  - lib/grape-dsl/endpoint.rb
@@ -85,19 +84,18 @@ require_paths:
85
84
  - lib
86
85
  required_ruby_version: !ruby/object:Gem::Requirement
87
86
  requirements:
88
- - - ! '>='
87
+ - - ">="
89
88
  - !ruby/object:Gem::Version
90
89
  version: '0'
91
90
  required_rubygems_version: !ruby/object:Gem::Requirement
92
91
  requirements:
93
- - - ! '>='
92
+ - - ">="
94
93
  - !ruby/object:Gem::Version
95
94
  version: '0'
96
95
  requirements: []
97
96
  rubyforge_project:
98
- rubygems_version: 2.2.1
97
+ rubygems_version: 2.2.2
99
98
  signing_key:
100
99
  specification_version: 4
101
100
  summary: Simple Grape DSL for easer use cases
102
101
  test_files: []
103
- has_rdoc:
@@ -1,9 +0,0 @@
1
- module Grape
2
-
3
- # for security on/off functions
4
- class << self
5
- attr_accessor :security
6
- end
7
- self.security= true
8
-
9
- end