culpa 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +8 -8
- data/bin/culpa +1 -0
- data/lib/culpa.rb +50 -9
- data/templates/Dockerfile +1 -1
- data/templates/config.ru +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YTNmOTRkMzhlZjlhYTQ5ZmQ0MGNiNjQ0Mjc3MTQyZjhjMDQzNmVlYg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
ZWEwODA0NzhiZTdkYjgyOWZkOGJiMmY3NWYzOGFhZGZmMTlhZDg0MA==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
NjZkZmJiMzJjZGYyNjkzODYzMmMyZTI2YmY1OWU5MmZiYzBkNDBjOGYwZDE5
|
10
|
+
ZTk0NWQ3MmMzZTVjMGI1OTUwN2QzY2U4YWNhMmJjZTUxOTJhYTY4MDIwMzU5
|
11
|
+
MDdkNjAwODhmNzA5NWQ5NzM3YWYyZTQ5NWEyYTIzMzRhYmU4ZjE=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
ZmEwZDQ3ODAwNmMyZDg2Njc2NzA1ZjI5ZGNhYzdhNmY0YWVkMmI1NjdhYTRh
|
14
|
+
ZGU5ZWRiNzU5MWY1MjUxZmE5ZmNiMGM4MTU5NzNjMTJmMjI4YTM1YjBjNWZl
|
15
|
+
YjBhNmE4YzNiZDJmYTk1MDhkNTAzMzcxOGFhMzNiYWU5OTE0ODE=
|
data/bin/culpa
CHANGED
@@ -17,6 +17,7 @@ def create_project(project_path)
|
|
17
17
|
FileUtils.touch "#{project_path}/models/.keep"
|
18
18
|
FileUtils.mkdir "#{project_path}/config"
|
19
19
|
FileUtils.touch "#{project_path}/config/router.yml"
|
20
|
+
FileUtils.touch "#{project_path}/config/rev_router.yml"
|
20
21
|
FileUtils.mkdir "#{project_path}/config/initializers"
|
21
22
|
FileUtils.touch "#{project_path}/config/initializers/.keep"
|
22
23
|
|
data/lib/culpa.rb
CHANGED
@@ -30,17 +30,20 @@ module Culpa
|
|
30
30
|
|
31
31
|
class Application
|
32
32
|
|
33
|
-
def initialize(
|
34
|
-
|
33
|
+
def initialize(options = {})
|
34
|
+
@brick_call_chains_cache = {}
|
35
|
+
@router = YAML.load_file(options[:router] || './config/router.yml')
|
36
|
+
@rev_router = YAML.load_file(options[:rev_router] || './config/rev_router.yml')
|
35
37
|
end
|
36
38
|
|
37
39
|
def call_action(options)
|
38
40
|
router_method_name = "#{options[:sub_call]}_#{options[:res_name]}"
|
39
41
|
envelope = Envelope.new
|
40
42
|
request = EnvelopeRequest.new(options)
|
41
|
-
|
42
|
-
|
43
|
-
|
43
|
+
bricks = brick_call_chain(router_method_name)
|
44
|
+
return not_found unless bricks
|
45
|
+
bricks.each do |brick|
|
46
|
+
action_class_name, method_name = brick.split('.')
|
44
47
|
action_class = Actions.const_get(action_class_name).new(envelope, request)
|
45
48
|
action_class.send method_name
|
46
49
|
return do_render action_class.to_render if action_class.to_render
|
@@ -48,7 +51,42 @@ module Culpa
|
|
48
51
|
raise NoRenderCalled.new
|
49
52
|
end
|
50
53
|
|
51
|
-
|
54
|
+
##
|
55
|
+
# Building the brick chain for a router method.
|
56
|
+
# Gets before and after bricks in reverse router and merge it with standard calls.
|
57
|
+
# Keeps the brickchain in cache for later calls.
|
58
|
+
def brick_call_chain(router_method_name)
|
59
|
+
unless @brick_call_chains_cache.has_key? router_method_name
|
60
|
+
return unless @router.has_key? router_method_name
|
61
|
+
final_call_chain = []
|
62
|
+
# Search for rev_router matches
|
63
|
+
@rev_router.each do |rev_router_item|
|
64
|
+
if rev_router_item.has_key? 'match_only'
|
65
|
+
rev_router_item['match_only'].each do |matcher|
|
66
|
+
if router_method_name.match(Regexp.new("^#{matcher}$"))
|
67
|
+
final_call_chain.concat rev_router_item['bricks']
|
68
|
+
break
|
69
|
+
end
|
70
|
+
end
|
71
|
+
elsif rev_router_item.has_key? 'all_except'
|
72
|
+
one_match = false
|
73
|
+
rev_router_item['all_except'].each do |matcher|
|
74
|
+
one_match ||= router_method_name.match(Regexp.new("^#{matcher}$"))
|
75
|
+
break if one_match
|
76
|
+
end
|
77
|
+
final_call_chain.concat rev_router_item['bricks'] unless one_match
|
78
|
+
end
|
79
|
+
end
|
80
|
+
# Append router call chain
|
81
|
+
final_call_chain.concat @router[router_method_name]
|
82
|
+
# Save in cache
|
83
|
+
@brick_call_chains_cache[router_method_name] = final_call_chain
|
84
|
+
end
|
85
|
+
@brick_call_chains_cache[router_method_name]
|
86
|
+
end
|
87
|
+
|
88
|
+
##
|
89
|
+
# Renders a json or anything else
|
52
90
|
def do_render(to_render)
|
53
91
|
body = case to_render[:format]
|
54
92
|
when :json
|
@@ -61,7 +99,8 @@ module Culpa
|
|
61
99
|
[ to_render[:status], to_render[:headers], body ]
|
62
100
|
end
|
63
101
|
|
64
|
-
|
102
|
+
##
|
103
|
+
# Rack entrypoint
|
65
104
|
def call(env)
|
66
105
|
call_options = {
|
67
106
|
verb: env['REQUEST_METHOD'].downcase.to_sym
|
@@ -108,12 +147,14 @@ module Culpa
|
|
108
147
|
call_action call_options
|
109
148
|
end
|
110
149
|
|
111
|
-
|
150
|
+
##
|
151
|
+
# Rack pre-formatted 400 : Bad request
|
112
152
|
def bad_request
|
113
153
|
['400', {'Content-Type' => 'application/json'}, []]
|
114
154
|
end
|
115
155
|
|
116
|
-
|
156
|
+
##
|
157
|
+
# Rack pre-formatted 404 : Not found
|
117
158
|
def not_found
|
118
159
|
['404', {'Content-Type' => 'application/json'}, []]
|
119
160
|
end
|
data/templates/Dockerfile
CHANGED
data/templates/config.ru
CHANGED