oven 0.1.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +23 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +7 -0
- data/LICENSE.txt +21 -0
- data/README.md +39 -0
- data/Rakefile +15 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/oven.rb +54 -0
- data/lib/oven/builders.rb +82 -0
- data/lib/oven/dsl_context.rb +88 -0
- data/lib/oven/extension_configurers.rb +125 -0
- data/lib/oven/http_statuses.rb +46 -0
- data/lib/oven/path_parser.rb +142 -0
- data/lib/oven/path_parser.y +28 -0
- data/lib/oven/path_parser/nodes.rb +49 -0
- data/lib/oven/path_parser/parser_extension.rb +26 -0
- data/lib/oven/path_parser/path_ast.rb +21 -0
- data/lib/oven/path_parser/scanner.rb +32 -0
- data/lib/oven/refinements.rb +27 -0
- data/lib/oven/templates/client.rb.erb +82 -0
- data/lib/oven/templates/exceptions.rb.erb +45 -0
- data/lib/oven/templates/json.rb.erb +47 -0
- data/lib/oven/templates/models.rb.erb +21 -0
- data/lib/oven/templates/object_mapping.rb.erb +39 -0
- data/lib/oven/templates/poro.rb.erb +13 -0
- data/lib/oven/version.rb +3 -0
- data/oven.gemspec +22 -0
- metadata +130 -0
@@ -0,0 +1,125 @@
|
|
1
|
+
module Oven
|
2
|
+
class ApiClientConfigurer
|
3
|
+
def filename(path, client_filename)
|
4
|
+
File.join(path, "#{client_filename}.rb")
|
5
|
+
end
|
6
|
+
|
7
|
+
def template_path
|
8
|
+
"#{__dir__}/templates/client.rb.erb"
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class ExceptionConfigurer
|
13
|
+
def filename(path, client_filename)
|
14
|
+
File.join(path, 'exceptions.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
def template_path
|
18
|
+
"#{__dir__}/templates/exceptions.rb.erb"
|
19
|
+
end
|
20
|
+
|
21
|
+
def configure_observers(observers)
|
22
|
+
observers << 'ResponseHandler'
|
23
|
+
end
|
24
|
+
|
25
|
+
def configure_requires(requires)
|
26
|
+
requires << 'exceptions'
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
class JsonConfigurer
|
31
|
+
def filename(path, client_filename)
|
32
|
+
File.join(path, 'json_handler.rb')
|
33
|
+
end
|
34
|
+
|
35
|
+
def template_path
|
36
|
+
"#{__dir__}/templates/json.rb.erb"
|
37
|
+
end
|
38
|
+
|
39
|
+
def configure_interceptors(interceptors)
|
40
|
+
interceptors << 'JsonSerializer'
|
41
|
+
end
|
42
|
+
|
43
|
+
def configure_observers(observers)
|
44
|
+
observers << 'JsonDeserializer'
|
45
|
+
end
|
46
|
+
|
47
|
+
def configure_requires(requires)
|
48
|
+
requires << 'json_handler'
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
class ModelsConfigurer
|
53
|
+
PRIMITIVE_CLASSES = [
|
54
|
+
'Integer',
|
55
|
+
'String',
|
56
|
+
'Boolean',
|
57
|
+
'Date',
|
58
|
+
'Time',
|
59
|
+
'DateTime',
|
60
|
+
'Hash',
|
61
|
+
'Array(Integer)',
|
62
|
+
'Array(String)',
|
63
|
+
'Array(Boolean)',
|
64
|
+
'Array(Date)',
|
65
|
+
'Array(Time)',
|
66
|
+
'Array(DateTime)',
|
67
|
+
'Array(Hash)'
|
68
|
+
].freeze
|
69
|
+
|
70
|
+
def initialize(object_mapping_path)
|
71
|
+
@object_mapping_path = object_mapping_path
|
72
|
+
end
|
73
|
+
|
74
|
+
def primitive_classes
|
75
|
+
PRIMITIVE_CLASSES
|
76
|
+
end
|
77
|
+
|
78
|
+
def object_mapping
|
79
|
+
@object_mapping ||= YAML.load_file(@object_mapping_path)
|
80
|
+
end
|
81
|
+
|
82
|
+
def class_names
|
83
|
+
object_mapping.keys
|
84
|
+
end
|
85
|
+
|
86
|
+
def filename(path, client_filename)
|
87
|
+
File.join(path, 'models.rb')
|
88
|
+
end
|
89
|
+
|
90
|
+
def template_path
|
91
|
+
"#{__dir__}/templates/models.rb.erb"
|
92
|
+
end
|
93
|
+
|
94
|
+
def configure_requires(requires)
|
95
|
+
requires << 'models'
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
class ObjectMapperConfigurer
|
100
|
+
attr_reader :method_definitions
|
101
|
+
|
102
|
+
def initialize(method_definitions)
|
103
|
+
@method_definitions = method_definitions
|
104
|
+
end
|
105
|
+
|
106
|
+
def filename(path, client_filename)
|
107
|
+
File.join(path, 'object_mapping.rb')
|
108
|
+
end
|
109
|
+
|
110
|
+
def template_path
|
111
|
+
"#{__dir__}/templates/object_mapping.rb.erb"
|
112
|
+
end
|
113
|
+
|
114
|
+
def configure_observers(observers)
|
115
|
+
observers << 'ObjectConverter'
|
116
|
+
end
|
117
|
+
|
118
|
+
def configure_requires(requires)
|
119
|
+
requires << 'object_mapping'
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
private_constant :ApiClientConfigurer, :ExceptionConfigurer, :JsonConfigurer, :ObjectMapperConfigurer,
|
124
|
+
:ModelsConfigurer
|
125
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Oven
|
2
|
+
CLIENT_ERROR_STATUSES = {
|
3
|
+
400 => 'Bad Request',
|
4
|
+
401 => 'Unauthorized',
|
5
|
+
402 => 'Payment Required',
|
6
|
+
403 => 'Forbidden',
|
7
|
+
404 => 'Not Found',
|
8
|
+
405 => 'Method Not Allowed',
|
9
|
+
406 => 'Not Acceptable',
|
10
|
+
407 => 'Proxy Authentication Required',
|
11
|
+
408 => 'Request Timeout',
|
12
|
+
409 => 'Conflict',
|
13
|
+
410 => 'Gone',
|
14
|
+
411 => 'Length Required',
|
15
|
+
412 => 'Precondition Failed',
|
16
|
+
413 => 'Payload Too Large',
|
17
|
+
414 => 'URI Too Long',
|
18
|
+
415 => 'Unsupported Media Type',
|
19
|
+
416 => 'Range Not Satisfiable',
|
20
|
+
417 => 'Expectation Failed',
|
21
|
+
418 => 'Im a Teapot',
|
22
|
+
421 => 'Misdirected Request',
|
23
|
+
422 => 'Unprocessable Entity',
|
24
|
+
423 => 'Locked',
|
25
|
+
424 => 'Failed Dependency',
|
26
|
+
426 => 'Upgrade Required',
|
27
|
+
428 => 'Precondition Required',
|
28
|
+
429 => 'Too Many Requests',
|
29
|
+
431 => 'Request Header Fields Too Large',
|
30
|
+
451 => 'Unavailable For Legal Reasons'
|
31
|
+
}.freeze
|
32
|
+
|
33
|
+
SERVER_ERROR_STATUSES = {
|
34
|
+
500 => 'Internal Server Error',
|
35
|
+
501 => 'Not Implemented',
|
36
|
+
502 => 'Bad Gateway',
|
37
|
+
503 => 'Service Unavailable',
|
38
|
+
504 => 'Gateway Timeout',
|
39
|
+
505 => 'HTTP Version Not Supported',
|
40
|
+
506 => 'Variant Also Negotiates',
|
41
|
+
507 => 'Insufficient Storage',
|
42
|
+
508 => 'Loop Detected',
|
43
|
+
510 => 'Not Extended',
|
44
|
+
511 => 'Network Authentication Required'
|
45
|
+
}.freeze
|
46
|
+
end
|
@@ -0,0 +1,142 @@
|
|
1
|
+
#
|
2
|
+
# DO NOT MODIFY!!!!
|
3
|
+
# This file is automatically generated by Racc 1.4.14
|
4
|
+
# from Racc grammer file "".
|
5
|
+
#
|
6
|
+
|
7
|
+
require 'racc/parser.rb'
|
8
|
+
|
9
|
+
require 'oven/path_parser/parser_extension'
|
10
|
+
module Oven
|
11
|
+
class PathParser < Racc::Parser
|
12
|
+
##### State transition tables begin ###
|
13
|
+
|
14
|
+
racc_action_table = [
|
15
|
+
6, 8, 7, 6, 8, 7, 9, 11 ]
|
16
|
+
|
17
|
+
racc_action_check = [
|
18
|
+
0, 0, 0, 2, 2, 2, 1, 9 ]
|
19
|
+
|
20
|
+
racc_action_pointer = [
|
21
|
+
-2, 6, 1, nil, nil, nil, nil, nil, nil, 7,
|
22
|
+
nil, nil ]
|
23
|
+
|
24
|
+
racc_action_default = [
|
25
|
+
-9, -9, -2, -3, -4, -5, -6, -7, -8, -9,
|
26
|
+
-1, 12 ]
|
27
|
+
|
28
|
+
racc_goto_table = [
|
29
|
+
1, nil, 10 ]
|
30
|
+
|
31
|
+
racc_goto_check = [
|
32
|
+
1, nil, 1 ]
|
33
|
+
|
34
|
+
racc_goto_pointer = [
|
35
|
+
nil, 0, nil, nil, nil, nil ]
|
36
|
+
|
37
|
+
racc_goto_default = [
|
38
|
+
nil, nil, 2, 3, 4, 5 ]
|
39
|
+
|
40
|
+
racc_reduce_table = [
|
41
|
+
0, 0, :racc_error,
|
42
|
+
2, 6, :_reduce_1,
|
43
|
+
1, 6, :_reduce_2,
|
44
|
+
1, 7, :_reduce_none,
|
45
|
+
1, 7, :_reduce_none,
|
46
|
+
1, 7, :_reduce_none,
|
47
|
+
1, 8, :_reduce_6,
|
48
|
+
1, 9, :_reduce_7,
|
49
|
+
1, 10, :_reduce_8 ]
|
50
|
+
|
51
|
+
racc_reduce_n = 9
|
52
|
+
|
53
|
+
racc_shift_n = 12
|
54
|
+
|
55
|
+
racc_token_table = {
|
56
|
+
false => 0,
|
57
|
+
:error => 1,
|
58
|
+
:SLASH => 2,
|
59
|
+
:LITERAL => 3,
|
60
|
+
:SYMBOL => 4 }
|
61
|
+
|
62
|
+
racc_nt_base = 5
|
63
|
+
|
64
|
+
racc_use_result_var = false
|
65
|
+
|
66
|
+
Racc_arg = [
|
67
|
+
racc_action_table,
|
68
|
+
racc_action_check,
|
69
|
+
racc_action_default,
|
70
|
+
racc_action_pointer,
|
71
|
+
racc_goto_table,
|
72
|
+
racc_goto_check,
|
73
|
+
racc_goto_default,
|
74
|
+
racc_goto_pointer,
|
75
|
+
racc_nt_base,
|
76
|
+
racc_reduce_table,
|
77
|
+
racc_token_table,
|
78
|
+
racc_shift_n,
|
79
|
+
racc_reduce_n,
|
80
|
+
racc_use_result_var ]
|
81
|
+
|
82
|
+
Racc_token_to_s_table = [
|
83
|
+
"$end",
|
84
|
+
"error",
|
85
|
+
"SLASH",
|
86
|
+
"LITERAL",
|
87
|
+
"SYMBOL",
|
88
|
+
"$start",
|
89
|
+
"expressions",
|
90
|
+
"expression",
|
91
|
+
"slash",
|
92
|
+
"symbol",
|
93
|
+
"literal" ]
|
94
|
+
|
95
|
+
Racc_debug_parser = false
|
96
|
+
|
97
|
+
##### State transition tables end #####
|
98
|
+
|
99
|
+
# reduce 0 omitted
|
100
|
+
|
101
|
+
module_eval(<<'.,.,', 'path_parser.y', 6)
|
102
|
+
def _reduce_1(val, _values)
|
103
|
+
val.flatten
|
104
|
+
end
|
105
|
+
.,.,
|
106
|
+
|
107
|
+
module_eval(<<'.,.,', 'path_parser.y', 7)
|
108
|
+
def _reduce_2(val, _values)
|
109
|
+
val.first
|
110
|
+
end
|
111
|
+
.,.,
|
112
|
+
|
113
|
+
# reduce 3 omitted
|
114
|
+
|
115
|
+
# reduce 4 omitted
|
116
|
+
|
117
|
+
# reduce 5 omitted
|
118
|
+
|
119
|
+
module_eval(<<'.,.,', 'path_parser.y', 15)
|
120
|
+
def _reduce_6(val, _values)
|
121
|
+
Slash.new('/')
|
122
|
+
end
|
123
|
+
.,.,
|
124
|
+
|
125
|
+
module_eval(<<'.,.,', 'path_parser.y', 18)
|
126
|
+
def _reduce_7(val, _values)
|
127
|
+
Symbol.new(val.first)
|
128
|
+
end
|
129
|
+
.,.,
|
130
|
+
|
131
|
+
module_eval(<<'.,.,', 'path_parser.y', 21)
|
132
|
+
def _reduce_8(val, _values)
|
133
|
+
Literal.new(val.first)
|
134
|
+
end
|
135
|
+
.,.,
|
136
|
+
|
137
|
+
def _reduce_none(val, _values)
|
138
|
+
val[0]
|
139
|
+
end
|
140
|
+
|
141
|
+
end # class PathParser
|
142
|
+
end # module Oven
|
@@ -0,0 +1,28 @@
|
|
1
|
+
class Oven::PathParser
|
2
|
+
options no_result_var
|
3
|
+
token SLASH LITERAL SYMBOL
|
4
|
+
|
5
|
+
rule
|
6
|
+
expressions
|
7
|
+
: expression expressions { val.flatten }
|
8
|
+
| expression { val.first }
|
9
|
+
;
|
10
|
+
expression
|
11
|
+
: slash
|
12
|
+
| symbol
|
13
|
+
| literal
|
14
|
+
;
|
15
|
+
slash
|
16
|
+
: SLASH { Slash.new('/') }
|
17
|
+
;
|
18
|
+
symbol
|
19
|
+
: SYMBOL { Symbol.new(val.first) }
|
20
|
+
;
|
21
|
+
literal
|
22
|
+
: LITERAL { Literal.new(val.first) }
|
23
|
+
;
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
---- header
|
28
|
+
require 'oven/path_parser/parser_extension'
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Oven
|
2
|
+
module Nodes
|
3
|
+
class Expressions
|
4
|
+
include Enumerable
|
5
|
+
|
6
|
+
def initialize(values)
|
7
|
+
@expressions = values
|
8
|
+
end
|
9
|
+
|
10
|
+
def each(&block)
|
11
|
+
@expressions.each(&block)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class Node
|
16
|
+
attr_reader :value
|
17
|
+
|
18
|
+
def initialize(value)
|
19
|
+
@value = value
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_s
|
23
|
+
@value.to_s
|
24
|
+
end
|
25
|
+
alias to_argument_expression to_s
|
26
|
+
|
27
|
+
def argument?
|
28
|
+
false
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
class Slash < Node; end
|
33
|
+
class Literal < Node; end
|
34
|
+
|
35
|
+
class Symbol < Node
|
36
|
+
def to_argument_expression
|
37
|
+
"\#{#{value.tr(':', '')}}"
|
38
|
+
end
|
39
|
+
|
40
|
+
def argument?
|
41
|
+
true
|
42
|
+
end
|
43
|
+
|
44
|
+
def to_sym
|
45
|
+
value.tr(":", "").to_sym
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'oven/path_parser/scanner'
|
2
|
+
require 'oven/path_parser/nodes'
|
3
|
+
require 'oven/path_parser/path_ast'
|
4
|
+
|
5
|
+
module Oven
|
6
|
+
class PathParser < Racc::Parser # :nodoc:
|
7
|
+
include Oven::Nodes
|
8
|
+
|
9
|
+
def self.parse(path_str)
|
10
|
+
scanner = PathScanner.new(path_str)
|
11
|
+
parser = PathParser.new(scanner)
|
12
|
+
|
13
|
+
PathAst.new(parser.parse)
|
14
|
+
end
|
15
|
+
|
16
|
+
def initialize(scanner)
|
17
|
+
@scanner = scanner
|
18
|
+
end
|
19
|
+
|
20
|
+
alias parse do_parse
|
21
|
+
|
22
|
+
def next_token
|
23
|
+
@scanner.next_token
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Oven
|
2
|
+
class PathAst
|
3
|
+
include Enumerable
|
4
|
+
|
5
|
+
def initialize(expressions)
|
6
|
+
@expressions = expressions
|
7
|
+
end
|
8
|
+
|
9
|
+
def each(&block)
|
10
|
+
@expressions.each(&block)
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_argument_expression
|
14
|
+
map(&:to_argument_expression).join
|
15
|
+
end
|
16
|
+
|
17
|
+
def parameters
|
18
|
+
select(&:argument?).map(&:to_sym)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require "strscan"
|
2
|
+
|
3
|
+
module Oven
|
4
|
+
class PathScanner # :nodoc:
|
5
|
+
def initialize(path_str)
|
6
|
+
@ss = StringScanner.new(path_str)
|
7
|
+
end
|
8
|
+
|
9
|
+
def next_token
|
10
|
+
return if @ss.eos?
|
11
|
+
|
12
|
+
scan
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def scan
|
18
|
+
case
|
19
|
+
# /
|
20
|
+
when text = @ss.scan(/\//)
|
21
|
+
[:SLASH, text]
|
22
|
+
when text = @ss.scan(/(?<!\\):\w+/)
|
23
|
+
[:SYMBOL, text]
|
24
|
+
when text = @ss.scan(/(?:[\w%\-~!$&'*+,;=@]|\\:|\\\(|\\\))+/)
|
25
|
+
[:LITERAL, text.tr('\\', "")]
|
26
|
+
# any char
|
27
|
+
when text = @ss.scan(/./)
|
28
|
+
[:LITERAL, text]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|