dandy 0.12.0 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +2 -2
- data/README.md +4 -3
- data/dandy.gemspec +4 -4
- data/lib/dandy/app.rb +8 -6
- data/lib/dandy/chain.rb +8 -29
- data/lib/dandy/generators/cli.rb +5 -2
- data/lib/dandy/generators/templates/actions/common/close_db_session.rb +12 -0
- data/lib/dandy/generators/templates/actions/common/handle_errors_jet_set.rb +20 -0
- data/lib/dandy/generators/templates/app/app.jet_set.routes +7 -0
- data/lib/dandy/loaders/type_loader.rb +2 -2
- data/lib/dandy/request.rb +44 -30
- data/lib/dandy/response.rb +11 -0
- data/lib/dandy/safe_executor.rb +39 -0
- data/lib/dandy/version.rb +1 -1
- data/lib/dandy/view_factory.rb +7 -1
- metadata +16 -13
- data/lib/dandy/chain_factory.rb +0 -39
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 10c1d06be946e67fdc9c9e2dd27e37015aa5c315006f153364f6a729eecadc8c
|
4
|
+
data.tar.gz: eb3055e8a23b44e78661f7ae89896bb96748fb71bb2dbd9122f5f9f6a4271a94
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40389e9152244e5949e539d18caa4fd35604286721d327543bc2e20765d078e4888f2da0225bd052f54ec0e817e4cef7b50b5cf1092afdd09e5aed9364da66e3
|
7
|
+
data.tar.gz: d6966b353e974d10a755677b84a1a5943a59cf2335eeec2a396203df118a03161fec03bd7f72b63a83467595d92ab019aac30c1d82412a9b5017e553bd8e43ae
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
Dandy is a minimalistic web API framework. Its main idea is to implement an approach
|
4
4
|
from Clean Architecture principles - "web is just a delivery mechanism".
|
5
|
-
Dandy is build on top of IoC container Hypo and forces to use dependency injection
|
5
|
+
Dandy is build on top of IoC container [Hypo](https://github.com/cylon-v/hypo) and forces to use dependency injection
|
6
6
|
approach everywhere.
|
7
7
|
|
8
8
|
## Basic Concepts
|
@@ -109,13 +109,14 @@ or just
|
|
109
109
|
$ rackup -p 8000 config.ru
|
110
110
|
```
|
111
111
|
|
112
|
-
4.
|
112
|
+
4. Run curl command `curl http://localhost:8000 -H "Accept: application/json"` and you'll see:
|
113
113
|
|
114
114
|
```json
|
115
115
|
{"message": "Welcome to dandy-app!"}
|
116
116
|
```
|
117
|
+
Please take attention - HTTP header "Accept: application/json" is a mandatory.
|
117
118
|
|
118
|
-
5. Investigate example application code, it
|
119
|
+
5. Investigate example application code, it explains most of Dandy aspects.
|
119
120
|
6. For more details visit our [Wiki](https://github.com/cylon-v/dandy/wiki).
|
120
121
|
|
121
122
|
## Development
|
data/dandy.gemspec
CHANGED
@@ -30,8 +30,8 @@ Gem::Specification.new do |spec|
|
|
30
30
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
31
31
|
spec.require_paths = ['lib']
|
32
32
|
|
33
|
-
spec.add_dependency 'hypo', '~> 0.
|
34
|
-
spec.add_dependency 'rack', '~> 2.
|
33
|
+
spec.add_dependency 'hypo', '~> 1.0.0'
|
34
|
+
spec.add_dependency 'rack', '~> 2.2.3'
|
35
35
|
spec.add_dependency 'thor', '~> 0.20.0'
|
36
36
|
spec.add_dependency 'treetop', '~> 1.6.8'
|
37
37
|
spec.add_dependency 'jbuilder', '~> 2.7.0'
|
@@ -40,8 +40,8 @@ Gem::Specification.new do |spec|
|
|
40
40
|
spec.add_dependency 'awrence', '~> 1.0.0'
|
41
41
|
spec.add_dependency 'plissken', '~> 1.2.0'
|
42
42
|
|
43
|
-
spec.add_development_dependency 'bundler', '~> 1
|
44
|
-
spec.add_development_dependency 'rake', '~>
|
43
|
+
spec.add_development_dependency 'bundler', '~> 2.1'
|
44
|
+
spec.add_development_dependency 'rake', '~> 13.0'
|
45
45
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
46
46
|
spec.add_development_dependency 'rspec-mocks', '~> 3.6'
|
47
47
|
spec.add_development_dependency 'simplecov', '~> 0.15'
|
data/lib/dandy/app.rb
CHANGED
@@ -9,9 +9,9 @@ require 'dandy/request'
|
|
9
9
|
require 'dandy/template_registry'
|
10
10
|
require 'dandy/view_builder_registry'
|
11
11
|
require 'dandy/view_factory'
|
12
|
-
require 'dandy/chain_factory'
|
13
12
|
require 'dandy/view_builders/json'
|
14
13
|
require 'dandy/routing/routing'
|
14
|
+
require 'dandy/safe_executor'
|
15
15
|
|
16
16
|
module Dandy
|
17
17
|
class App
|
@@ -27,7 +27,7 @@ module Dandy
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def call(env)
|
30
|
-
request = Request.new(@route_matcher, @container, @
|
30
|
+
request = Request.new(@route_matcher, @container, @safe_executor)
|
31
31
|
request.handle(env)
|
32
32
|
end
|
33
33
|
|
@@ -46,7 +46,8 @@ module Dandy
|
|
46
46
|
def register_dependencies
|
47
47
|
instances = {
|
48
48
|
config_file_path: 'dandy.yml',
|
49
|
-
dandy_env: ENV['DANDY_ENV'] || 'development'
|
49
|
+
dandy_env: ENV['DANDY_ENV'] || 'development',
|
50
|
+
env: ENV
|
50
51
|
}
|
51
52
|
|
52
53
|
instances.keys.each do |name|
|
@@ -61,12 +62,12 @@ module Dandy
|
|
61
62
|
template_registry: TemplateRegistry,
|
62
63
|
view_builder_registry: ViewBuilderRegistry,
|
63
64
|
view_factory: ViewFactory,
|
64
|
-
chain_factory: ChainFactory,
|
65
65
|
file_reader: Routing::FileReader,
|
66
66
|
syntax_parser: SyntaxParser,
|
67
67
|
syntax_error_interpreter: Routing::SyntaxErrorInterpreter,
|
68
68
|
routes_builder: Routing::Builder,
|
69
|
-
route_parser: Routing::Parser
|
69
|
+
route_parser: Routing::Parser,
|
70
|
+
safe_executor: SafeExecutor
|
70
71
|
}
|
71
72
|
|
72
73
|
singletons.keys.each do |name|
|
@@ -76,11 +77,12 @@ module Dandy
|
|
76
77
|
end
|
77
78
|
|
78
79
|
def load_basic_dependencies
|
79
|
-
@
|
80
|
+
@dandy_config = @container.resolve(:dandy_config)
|
80
81
|
@view_factory = @container.resolve(:view_factory)
|
81
82
|
@dependency_loader = @container.resolve(:dependency_loader)
|
82
83
|
@view_builder_registry = @container.resolve(:view_builder_registry)
|
83
84
|
@route_parser = @container.resolve(:route_parser)
|
85
|
+
@safe_executor = @container.resolve(:safe_executor)
|
84
86
|
|
85
87
|
@dependency_loader.load_components
|
86
88
|
end
|
data/lib/dandy/chain.rb
CHANGED
@@ -2,46 +2,23 @@ require 'timeout'
|
|
2
2
|
|
3
3
|
module Dandy
|
4
4
|
class Chain
|
5
|
-
def initialize(container, dandy_config
|
6
|
-
@commands = commands
|
7
|
-
@last_command = last_command
|
5
|
+
def initialize(container, dandy_config)
|
8
6
|
@container = container
|
9
|
-
@catch_command = catch_command
|
10
7
|
@async_timeout = dandy_config[:action][:async_timeout]
|
11
8
|
end
|
12
9
|
|
13
|
-
def
|
14
|
-
if @catch_command.nil?
|
15
|
-
run_commands
|
16
|
-
else
|
17
|
-
begin
|
18
|
-
run_commands
|
19
|
-
rescue Exception => error
|
20
|
-
@container
|
21
|
-
.register_instance(error, :dandy_error)
|
22
|
-
.using_lifetime(:scope)
|
23
|
-
.bound_to(:dandy_request)
|
24
|
-
|
25
|
-
action = @container.resolve(@catch_command.name.to_sym)
|
26
|
-
action.call
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
def run_commands
|
10
|
+
def run_commands(commands, last_command)
|
34
11
|
threads = []
|
35
12
|
Thread.abort_on_exception = true
|
36
13
|
|
37
14
|
result = nil
|
38
|
-
|
15
|
+
commands.each_with_index do |command, index|
|
39
16
|
if command.sequential?
|
40
17
|
# all previous parallel commands should be done before the current sequential
|
41
18
|
threads.each {|t| t.join}
|
42
19
|
threads = []
|
43
20
|
|
44
|
-
if
|
21
|
+
if last_command && (command.name == last_command.name)
|
45
22
|
result = run_command(command)
|
46
23
|
else
|
47
24
|
run_command(command)
|
@@ -49,7 +26,7 @@ module Dandy
|
|
49
26
|
else
|
50
27
|
thread = Thread.new {
|
51
28
|
Timeout::timeout(@async_timeout) {
|
52
|
-
if
|
29
|
+
if last_command && (command.name == last_command.name)
|
53
30
|
result = run_command(command)
|
54
31
|
else
|
55
32
|
run_command(command)
|
@@ -60,7 +37,7 @@ module Dandy
|
|
60
37
|
end
|
61
38
|
|
62
39
|
# if it's last item in chain then wait until parallel commands are done
|
63
|
-
if index ==
|
40
|
+
if index == commands.length - 1
|
64
41
|
threads.each {|t| t.join}
|
65
42
|
end
|
66
43
|
end
|
@@ -68,6 +45,8 @@ module Dandy
|
|
68
45
|
result
|
69
46
|
end
|
70
47
|
|
48
|
+
private
|
49
|
+
|
71
50
|
def run_command(command)
|
72
51
|
if command.entity?
|
73
52
|
entity = @container.resolve(command.entity_name.to_sym)
|
data/lib/dandy/generators/cli.rb
CHANGED
@@ -19,16 +19,19 @@ module Dandy
|
|
19
19
|
copy_file 'templates/Gemfile_jet_set', "#{name}/Gemfile"
|
20
20
|
copy_file 'templates/db/mapping.rb', "#{name}/db/mapping.rb"
|
21
21
|
copy_file 'templates/actions/common/open_db_session.rb', "#{name}/app/actions/common/open_db_session.rb"
|
22
|
+
copy_file 'templates/actions/common/close_db_session.rb', "#{name}/app/actions/common/close_db_session.rb"
|
23
|
+
copy_file 'templates/actions/common/handle_errors_jet_set.rb', "#{name}/app/actions/common/handle_errors.rb"
|
24
|
+
copy_file 'templates/app/app.jet_set.routes', "#{name}/app/app.routes"
|
22
25
|
else
|
23
26
|
copy_file 'templates/app/app.rb', "#{name}/app/app.rb"
|
24
27
|
copy_file 'templates/Gemfile', "#{name}/Gemfile"
|
28
|
+
copy_file 'templates/actions/common/handle_errors.rb', "#{name}/app/actions/common/handle_errors.rb"
|
29
|
+
copy_file 'templates/app/app.routes', "#{name}/app/app.routes"
|
25
30
|
end
|
26
31
|
|
27
|
-
copy_file 'templates/app/app.routes', "#{name}/app/app.routes"
|
28
32
|
copy_file 'templates/dandy.yml', "#{name}/dandy.yml"
|
29
33
|
copy_file 'templates/config.ru', "#{name}/config.ru"
|
30
34
|
copy_file 'templates/views/show_welcome.json.jbuilder', "#{name}/app/views/show_welcome.json.jbuilder"
|
31
|
-
copy_file 'templates/actions/common/handle_errors.rb', "#{name}/app/actions/common/handle_errors.rb"
|
32
35
|
template 'templates/actions/welcome.tt', "#{name}/app/actions/welcome.rb", {app_name: name}
|
33
36
|
|
34
37
|
if options[:jet_set]
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class HandleErrors < Dandy::HandleErrors
|
2
|
+
def initialize(container, dandy_error, sequel)
|
3
|
+
super(container, dandy_error)
|
4
|
+
|
5
|
+
@sequel = sequel
|
6
|
+
end
|
7
|
+
|
8
|
+
def call
|
9
|
+
@sequel.disconnect
|
10
|
+
|
11
|
+
# implement your own error handling logic here.
|
12
|
+
# by default let's print the error to standard output
|
13
|
+
puts @dandy_error.message
|
14
|
+
puts @dandy_error.backtrace
|
15
|
+
|
16
|
+
# use preferred HTTP status code for different cases
|
17
|
+
# i.e. set_http_status(403) for authorization issue
|
18
|
+
set_http_status(500)
|
19
|
+
end
|
20
|
+
end
|
@@ -9,8 +9,8 @@ module Dandy
|
|
9
9
|
@directories.each do |directory|
|
10
10
|
dir = File.join(directory, '**/*')
|
11
11
|
files = Dir.glob(dir).reject {|file_path| File.directory?(file_path)}
|
12
|
-
|
13
|
-
files.each do |file|
|
12
|
+
test_patterns = %w(_spec.rb .spec.rb _test.rb .test.rb)
|
13
|
+
files.select {|f| !f.end_with?(*test_patterns)}.each do |file|
|
14
14
|
path = File.join(Dir.pwd, file)
|
15
15
|
require path
|
16
16
|
file_name = File.basename(file).gsub(File.extname(file), '')
|
data/lib/dandy/request.rb
CHANGED
@@ -1,21 +1,19 @@
|
|
1
1
|
require 'json'
|
2
|
+
require 'awrence'
|
3
|
+
require 'plissken'
|
2
4
|
require 'rack/multipart'
|
3
5
|
require 'dandy/extensions/hash'
|
4
|
-
require 'dandy/chain_factory'
|
5
6
|
require 'dandy/view_factory'
|
6
|
-
require '
|
7
|
-
require 'plissken'
|
8
|
-
|
7
|
+
require 'dandy/chain'
|
9
8
|
|
10
9
|
module Dandy
|
11
10
|
class Request
|
12
11
|
include Hypo::Scope
|
13
12
|
|
14
|
-
def initialize(route_matcher, container,
|
13
|
+
def initialize(route_matcher, container, safe_executor)
|
15
14
|
@container = container
|
16
15
|
@route_matcher = route_matcher
|
17
|
-
@
|
18
|
-
@view_factory = view_factory
|
16
|
+
@safe_executor = safe_executor
|
19
17
|
end
|
20
18
|
|
21
19
|
def handle(rack_env)
|
@@ -31,42 +29,38 @@ module Dandy
|
|
31
29
|
.collect {|k, v| [k.split('_').collect(&:capitalize).join('-'), v]}
|
32
30
|
.flatten
|
33
31
|
]
|
34
|
-
|
32
|
+
|
33
|
+
register_context(headers, :dandy_headers)
|
35
34
|
|
36
35
|
if match.nil?
|
37
36
|
result = [404, {'Content-Type' => headers['Accept']}, []]
|
37
|
+
release
|
38
38
|
else
|
39
|
+
status = match.route.http_status || default_http_status(match.route.http_verb)
|
40
|
+
register_params(match.params)
|
41
|
+
register_status(status)
|
42
|
+
|
39
43
|
query = Rack::Utils.parse_nested_query(rack_env['QUERY_STRING']).to_snake_keys.symbolize_keys
|
40
|
-
|
44
|
+
register_context(query, :dandy_query)
|
41
45
|
|
42
46
|
data = rack_env['rack.parser.result'] ? rack_env['rack.parser.result'].to_snake_keys.deep_symbolize_keys! : {}
|
43
|
-
|
47
|
+
register_context(data, :dandy_data)
|
44
48
|
|
45
49
|
multipart = Rack::Multipart.parse_multipart(rack_env) || {}
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
if chain_result.is_a?(String)
|
55
|
-
body = chain_result
|
56
|
-
else # generate JSON when nothing other is requested
|
57
|
-
if headers['Keys-Format'] == 'camel' && chain_result
|
58
|
-
chain_result = chain_result.to_camelback_keys
|
59
|
-
end
|
60
|
-
|
61
|
-
body = JSON.generate(chain_result)
|
62
|
-
end
|
50
|
+
register_context(multipart.values, :dandy_files)
|
51
|
+
|
52
|
+
body = @safe_executor.execute(match.route, headers)
|
53
|
+
|
54
|
+
begin
|
55
|
+
release
|
56
|
+
rescue Exception => error
|
57
|
+
body = @safe_executor.handle_error(match.route, headers, error)
|
63
58
|
end
|
64
59
|
|
65
60
|
status = @container.resolve(:dandy_status)
|
66
|
-
result = [status, {'Content-Type' =>
|
61
|
+
result = [status, {'Content-Type' => 'application/json'}, [body]]
|
67
62
|
end
|
68
63
|
|
69
|
-
release
|
70
64
|
|
71
65
|
result
|
72
66
|
end
|
@@ -80,12 +74,32 @@ module Dandy
|
|
80
74
|
.bound_to(self)
|
81
75
|
end
|
82
76
|
|
83
|
-
def
|
77
|
+
def register_context(params, name)
|
84
78
|
unless params.nil?
|
85
79
|
@container.register_instance(params, name)
|
86
80
|
.using_lifetime(:scope)
|
87
81
|
.bound_to(:dandy_request)
|
88
82
|
end
|
89
83
|
end
|
84
|
+
|
85
|
+
def register_params(params)
|
86
|
+
params.keys.each do |key|
|
87
|
+
@container
|
88
|
+
.register_instance(params[key], key.to_sym)
|
89
|
+
.using_lifetime(:scope)
|
90
|
+
.bound_to(:dandy_request)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
def register_status(status)
|
95
|
+
@container
|
96
|
+
.register_instance(status, :dandy_status)
|
97
|
+
.using_lifetime(:scope)
|
98
|
+
.bound_to(:dandy_request)
|
99
|
+
end
|
100
|
+
|
101
|
+
def default_http_status(http_verb)
|
102
|
+
http_verb == 'POST' ? 201 : 200
|
103
|
+
end
|
90
104
|
end
|
91
105
|
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'dandy/response'
|
2
|
+
|
3
|
+
module Dandy
|
4
|
+
class SafeExecutor
|
5
|
+
def initialize(container, dandy_config, view_factory)
|
6
|
+
@container = container
|
7
|
+
@dandy_config = dandy_config
|
8
|
+
@view_factory = view_factory
|
9
|
+
end
|
10
|
+
|
11
|
+
def execute(route, headers)
|
12
|
+
chain = Chain.new(@container, @dandy_config)
|
13
|
+
|
14
|
+
begin
|
15
|
+
result = chain.run_commands(route.commands, route.last_command)
|
16
|
+
if route.view
|
17
|
+
result = @view_factory.create(route.view, headers['Accept'], {keys_format: headers['Keys-Format'] || 'snake'})
|
18
|
+
end
|
19
|
+
|
20
|
+
body = result.is_a?(String) ? result : Response.format(result, headers)
|
21
|
+
rescue Exception => error
|
22
|
+
p error
|
23
|
+
body = handle_error(route, headers, error)
|
24
|
+
end
|
25
|
+
|
26
|
+
body
|
27
|
+
end
|
28
|
+
|
29
|
+
def handle_error(route, headers, error)
|
30
|
+
@container
|
31
|
+
.register_instance(error, :dandy_error)
|
32
|
+
.using_lifetime(:scope)
|
33
|
+
.bound_to(:dandy_request)
|
34
|
+
|
35
|
+
action = @container.resolve(route.catch.name.to_sym)
|
36
|
+
Response.format(action.call, headers)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/dandy/version.rb
CHANGED
data/lib/dandy/view_factory.rb
CHANGED
@@ -12,8 +12,14 @@ module Dandy
|
|
12
12
|
|
13
13
|
def create(name, content_type, options = {})
|
14
14
|
type = content_type ? content_type.split('/')[1] : 'json'
|
15
|
-
template = @template_registry.get(name, type)
|
16
15
|
builder = @view_builder_registry.get(type)
|
16
|
+
|
17
|
+
if builder.nil?
|
18
|
+
type = 'json'
|
19
|
+
builder = @view_builder_registry.get(type)
|
20
|
+
end
|
21
|
+
|
22
|
+
template = @template_registry.get(name, type)
|
17
23
|
view = builder.new(template, @container, options)
|
18
24
|
view.process
|
19
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dandy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladimir Kalinkin
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-09-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hypo
|
@@ -16,28 +16,28 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: 1.0.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: 0.
|
26
|
+
version: 1.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rack
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 2.
|
33
|
+
version: 2.2.3
|
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
|
-
version: 2.
|
40
|
+
version: 2.2.3
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: thor
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -142,28 +142,28 @@ dependencies:
|
|
142
142
|
requirements:
|
143
143
|
- - "~>"
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version: '1
|
145
|
+
version: '2.1'
|
146
146
|
type: :development
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
150
|
- - "~>"
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version: '1
|
152
|
+
version: '2.1'
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
154
|
name: rake
|
155
155
|
requirement: !ruby/object:Gem::Requirement
|
156
156
|
requirements:
|
157
157
|
- - "~>"
|
158
158
|
- !ruby/object:Gem::Version
|
159
|
-
version: '
|
159
|
+
version: '13.0'
|
160
160
|
type: :development
|
161
161
|
prerelease: false
|
162
162
|
version_requirements: !ruby/object:Gem::Requirement
|
163
163
|
requirements:
|
164
164
|
- - "~>"
|
165
165
|
- !ruby/object:Gem::Version
|
166
|
-
version: '
|
166
|
+
version: '13.0'
|
167
167
|
- !ruby/object:Gem::Dependency
|
168
168
|
name: rspec
|
169
169
|
requirement: !ruby/object:Gem::Requirement
|
@@ -230,7 +230,6 @@ files:
|
|
230
230
|
- lib/dandy/app.rb
|
231
231
|
- lib/dandy/base/handle_errors.rb
|
232
232
|
- lib/dandy/chain.rb
|
233
|
-
- lib/dandy/chain_factory.rb
|
234
233
|
- lib/dandy/config.rb
|
235
234
|
- lib/dandy/errors/dandy_error.rb
|
236
235
|
- lib/dandy/errors/syntax_error.rb
|
@@ -240,9 +239,12 @@ files:
|
|
240
239
|
- lib/dandy/generators/templates/.gitignore
|
241
240
|
- lib/dandy/generators/templates/Gemfile
|
242
241
|
- lib/dandy/generators/templates/Gemfile_jet_set
|
242
|
+
- lib/dandy/generators/templates/actions/common/close_db_session.rb
|
243
243
|
- lib/dandy/generators/templates/actions/common/handle_errors.rb
|
244
|
+
- lib/dandy/generators/templates/actions/common/handle_errors_jet_set.rb
|
244
245
|
- lib/dandy/generators/templates/actions/common/open_db_session.rb
|
245
246
|
- lib/dandy/generators/templates/actions/welcome.tt
|
247
|
+
- lib/dandy/generators/templates/app/app.jet_set.routes
|
246
248
|
- lib/dandy/generators/templates/app/app.rb
|
247
249
|
- lib/dandy/generators/templates/app/app.routes
|
248
250
|
- lib/dandy/generators/templates/app/app_jet_set.rb
|
@@ -254,6 +256,7 @@ files:
|
|
254
256
|
- lib/dandy/loaders/template_loader.rb
|
255
257
|
- lib/dandy/loaders/type_loader.rb
|
256
258
|
- lib/dandy/request.rb
|
259
|
+
- lib/dandy/response.rb
|
257
260
|
- lib/dandy/routing/builder.rb
|
258
261
|
- lib/dandy/routing/file_reader.rb
|
259
262
|
- lib/dandy/routing/match.rb
|
@@ -288,6 +291,7 @@ files:
|
|
288
291
|
- lib/dandy/routing/syntax/view.rb
|
289
292
|
- lib/dandy/routing/syntax_error_interpreter.rb
|
290
293
|
- lib/dandy/routing/syntax_grammar.tt
|
294
|
+
- lib/dandy/safe_executor.rb
|
291
295
|
- lib/dandy/template_registry.rb
|
292
296
|
- lib/dandy/version.rb
|
293
297
|
- lib/dandy/view_builder.rb
|
@@ -314,8 +318,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
314
318
|
- !ruby/object:Gem::Version
|
315
319
|
version: '0'
|
316
320
|
requirements: []
|
317
|
-
|
318
|
-
rubygems_version: 2.6.12
|
321
|
+
rubygems_version: 3.1.2
|
319
322
|
signing_key:
|
320
323
|
specification_version: 4
|
321
324
|
summary: Dandy is a minimalistic web API framework.
|
data/lib/dandy/chain_factory.rb
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
require 'dandy/chain'
|
2
|
-
|
3
|
-
module Dandy
|
4
|
-
class ChainFactory
|
5
|
-
def initialize(container, dandy_config)
|
6
|
-
@container = container
|
7
|
-
@dandy_config = dandy_config
|
8
|
-
end
|
9
|
-
|
10
|
-
def create(match)
|
11
|
-
status = match.route.http_status || default_http_status(match.route.http_verb)
|
12
|
-
register_params(match.params)
|
13
|
-
register_status(status)
|
14
|
-
Chain.new(@container, @dandy_config, match.route.commands, match.route.last_command, match.route.catch)
|
15
|
-
end
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
def register_params(params)
|
20
|
-
params.keys.each do |key|
|
21
|
-
@container
|
22
|
-
.register_instance(params[key], key.to_sym)
|
23
|
-
.using_lifetime(:scope)
|
24
|
-
.bound_to(:dandy_request)
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def register_status(status)
|
29
|
-
@container
|
30
|
-
.register_instance(status, :dandy_status)
|
31
|
-
.using_lifetime(:scope)
|
32
|
-
.bound_to(:dandy_request)
|
33
|
-
end
|
34
|
-
|
35
|
-
def default_http_status(http_verb)
|
36
|
-
http_verb == 'POST' ? 201 : 200
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|