grape-dsl 1.1.4 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- ZjI4ZmEzZDhmMjI2YzkzODFmNjg1NzcwMzU1NDAyOTI3ODE5NzU3Yg==
4
+ NTVjYzEwMjMxMmJhNDAyMzg4ODk5YjhlYjE4YWNjMzhlOTc0MzEzOQ==
5
5
  data.tar.gz: !binary |-
6
- OGUwMTMwNzA3NDE0ZmVhODE2ZmYwMWYyZDE0ODk2NTkwNzRmNGUwYQ==
6
+ ZTBlNDAwZTk2YjE2YjA1MGE1YzliOGVjYjUzZjI2MDU3ZGI0NDk3Yg==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MjhiZWZhOTg0N2RkMDUxMmRhNTU1Y2M2ZWI0ZmNhZGI5NTRlOGE2Y2ZjZDhj
10
- MmU0ODEwOGIzMmViNGNmN2UyMWViNzlkOTFjMmQ0YzcyMjQ2NDk5YWRjZTQw
11
- YTgxYTk1ZDJhNDRhZTk1MGJlMjM1OWVkZThhMzJhMDU4MWUwMDI=
9
+ ZTE0ZmVmMzIwYmJmMmJhNDVkYWIwNzI2NDhmYjljMjdmNDI0NDFjN2JhYjhk
10
+ ZjU2MzZjODZhODBiYzhkMjYxODZhMWE0NTA0N2I0MmU1YmFjYTg2YjJiYTNm
11
+ YTQ2ZDhkMGY1MGJkMjE5MTVhMjE3NzA1ZjQ2OWQ3YTE0OGE0YTM=
12
12
  data.tar.gz: !binary |-
13
- NWE2N2ViMDgwMmIzYmFlOTg3MGE1NzA4OWI1MTI2NDA3YmFjMjI4YTJlMjFi
14
- OWVkMWEyMjUzYzk5MzNiM2IxZTc5YmNkODA4NzdmNzRjMjgzMTg3NDIyNzgx
15
- MWQ3MThlMTNiNjI3MTBiMjg0MmM2NDIxOGVmMTQ3NzhmMDk5OTU=
13
+ Y2NmZjI2NDZlYzUwYTM3YTA1MTBlYzNkNGNkNjlhMWQ4YzE0MWQ4MTk0MmRi
14
+ ZDYzOTY4OGM5ZWJkOGI4ODNmMjEwYzFjM2NmOGE3NjdjNjlmODljM2JkNTIz
15
+ NjAxY2IxY2FiZjgxMTRjMzA5NjE2MGUzNDk2NzRmZjI1Yjg2OGU=
data/README.md CHANGED
@@ -4,6 +4,55 @@ 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
+ ### Use case
8
+
9
+ you can mount Grape::API-s all child class with
10
+ ```ruby
11
+ class MainApi < Grape::API
12
+ mount_subclasses
13
+ end
14
+ ```
15
+
16
+ you can mount only a single singleton method from a class like this
17
+ ps.: you can even set arguments to be json or yaml so it will be parsed before passing to method
18
+ ```ruby
19
+
20
+ class TestClass
21
+
22
+ def self.test_method hello
23
+
24
+ end
25
+
26
+ def self.complex_method
27
+ def self.complex_method hello, world="default", opts={},*args
28
+
29
+ puts "hello: #{hello}"
30
+ puts "world: #{world}"
31
+ puts "opts: #{opts.inspect}"
32
+ puts "args: #{args.inspect}"
33
+ puts "---"
34
+
35
+ end
36
+
37
+ end
38
+
39
+ class Api < Grape::API
40
+
41
+ mount_method TestClass, :test_method
42
+ mount_method Test,:test, "hello_world",[:opts,:json],[:args,:json]
43
+
44
+ end
45
+
46
+ ```
47
+
48
+ or if you are big fan of the CURS , then you can use this two method:
49
+ response_headers_to_new_calls
50
+ response_headers_to_routes_options_request
51
+
52
+ there is description in he headers file.
53
+
54
+ so stuffs like this can be found in this project
55
+
7
56
 
8
57
  ## LICENSE
9
58
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.4
1
+ 1.2.0
data/lib/grape-dsl.rb CHANGED
@@ -4,6 +4,8 @@ module Grape
4
4
 
5
5
  require 'procemon'
6
6
  require 'grape'
7
+ require 'json'
8
+ require 'yaml'
7
9
 
8
10
  require_relative_directory 'grape-dsl'
9
11
 
@@ -0,0 +1,116 @@
1
+ # this is super if you want CORS with Grape
2
+ # This is a plugin for Mongoid
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
+
13
+
14
+ # Args description
15
+ # string = path part, will be joined with "/"
16
+ # hash = options element
17
+ # Class = target class
18
+ # Symbol = method name
19
+ #
20
+ # Array = This is for argument pre parsing, like when you use "hash" and the input will be a json
21
+ #
22
+ # simple use case: [:hello,:json],[:sup,:yaml]
23
+ #
24
+ #
25
+ # ---------------
26
+ #
27
+ # looks like this:
28
+ # mount_method TestClass, :test_method, "funny_path",:GET
29
+ #
30
+ # you can give hash options just like to any othere get,post put delete etc methods, it will work
31
+ #
32
+ def mount_method *args
33
+
34
+ options = Hash[*args.extract_class!(Hash)]
35
+ path_name = args.extract_class!(String).join('/')
36
+ class_name = args.extract_class!(Class)[0]
37
+
38
+ tmp_array = args.extract_class!(Array)
39
+ adapter_opt = Hash.new
40
+
41
+ tmp_array.each do |array_obj|
42
+ if array_obj.count == 2
43
+ adapter_opt[array_obj[0]]= array_obj[1]
44
+ end
45
+ end
46
+
47
+ method_name = nil
48
+ rest_method = nil
49
+
50
+ args.extract_class!(Symbol).each do |element|
51
+ if element.to_s == element.to_s.downcase
52
+ method_name = element
53
+ elsif element.to_s == element.to_s.upcase
54
+ rest_method = element.to_s.downcase
55
+ end
56
+ end
57
+
58
+ rest_method ||= "get"
59
+ method_obj = class_name.method(method_name).clone
60
+
61
+
62
+ params do
63
+
64
+ method_obj.parameters.each do |array_obj|
65
+
66
+ case array_obj[0]
67
+
68
+ when :req
69
+ requires array_obj[1]
70
+ when :opt
71
+ optional array_obj[1]
72
+ when :rest
73
+ optional array_obj[1],
74
+ type: Array
75
+
76
+ #when :block
77
+ # optional array_obj[1],
78
+ # type: String,
79
+ # desc: "Ruby code to be used"
80
+
81
+
82
+ end
83
+
84
+ end
85
+
86
+ end
87
+
88
+
89
+ __send__(rest_method,path_name,options) do
90
+
91
+
92
+ method_arguments= (method_obj.parameters.map{|element|
93
+ if !params[element[1]].nil?
94
+
95
+ case adapter_opt[element[1]]
96
+ when :json
97
+ params[element[1]]= JSON.parse(params[element[1]])
98
+
99
+ when :yaml
100
+ params[element[1]]= YAML.parse(params[element[1]])
101
+
102
+ end
103
+
104
+ params[element[1]]
105
+ end
106
+ }-[nil])
107
+
108
+ method_obj.call(*method_arguments)
109
+ end
110
+
111
+
112
+ end
113
+
114
+ end
115
+ end
116
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grape-dsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.4
4
+ version: 1.2.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-07 00:00:00.000000000 Z
11
+ date: 2014-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: procemon
@@ -60,6 +60,7 @@ files:
60
60
  - lib/grape-dsl/dsl.rb
61
61
  - lib/grape-dsl/endpoint.rb
62
62
  - lib/grape-dsl/headers.rb
63
+ - lib/grape-dsl/mounter.rb
63
64
  homepage: https://github.com/adamluzsi/grape-dsl
64
65
  licenses:
65
66
  - MIT