culpa 0.4.2 → 0.5.0
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 +0 -1
- data/lib/culpa.rb +4 -36
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
NmIyYjkwNWQxYjk0ODc5MzQ5MWIxOTFmMGUzYTYwNThlZWU3ZGI0Ng==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
NGQzM2I2ZGY0NzE5ODg0OTlkYWU5MjM2MzYxOGViMjdjMGE2YTExZQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
MWVlZTE0Y2EyZjgzNzg2YWZmZjBlODdkZTEyZjMwMmFkODA4ZmI1MmNhOGVj
|
10
|
+
MzkxYjA4NzdlMTc0NTk3MTcyMzdlZGYxZDM0YWFhMWQ1YjY0NTYxYTU2NTQ2
|
11
|
+
YWRkYTFiZTkwNGQ2MzIyYWM1Y2JmZGFiOWViY2NlMjkzOGI0Mjc=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
YjYyY2QxZGViYWE3ZTI5NTA2MDU0OWVkM2NiMjIwNzY1YTM2NjE1ODU1NWEy
|
14
|
+
MzlmNWQ1ZmMyZDhhNTBjNTJlM2U5MDc5YWIwMWQ4YmUxNzYxNDhhYzYwYTZm
|
15
|
+
YTg5NmVlYWQ1MzMxNjcxNTMwMWI4OGRjYmMzNmExODAwNzAwM2Q=
|
data/bin/culpa
CHANGED
@@ -20,7 +20,6 @@ def create_project(project_path)
|
|
20
20
|
FileUtils.touch "#{project_path}/models/.keep"
|
21
21
|
FileUtils.mkdir "#{project_path}/config"
|
22
22
|
FileUtils.touch "#{project_path}/config/router.yml"
|
23
|
-
FileUtils.touch "#{project_path}/config/rev_router.yml"
|
24
23
|
FileUtils.mkdir "#{project_path}/config/initializers"
|
25
24
|
FileUtils.touch "#{project_path}/config/initializers/.keep"
|
26
25
|
|
data/lib/culpa.rb
CHANGED
@@ -38,14 +38,13 @@ module Culpa
|
|
38
38
|
def initialize(options = {})
|
39
39
|
@brick_call_chains_cache = {}
|
40
40
|
@router = YAML.load_file(options[:router] || './config/router.yml')
|
41
|
-
@rev_router = YAML.load_file(options[:rev_router] || './config/rev_router.yml')
|
42
41
|
end
|
43
42
|
|
44
43
|
def call_brickchain(options)
|
45
44
|
router_method_name = "#{options[:sub_call]}_#{options[:res_name]}"
|
46
45
|
envelope = Envelope.new
|
47
46
|
request = EnvelopeRequest.new(options)
|
48
|
-
bricks =
|
47
|
+
bricks = @router[router_method_name]
|
49
48
|
return not_found unless bricks
|
50
49
|
bricks.each do |brick|
|
51
50
|
action_class_name, method_name = brick.split('.')
|
@@ -56,40 +55,6 @@ module Culpa
|
|
56
55
|
raise NoRenderCalled.new
|
57
56
|
end
|
58
57
|
|
59
|
-
##
|
60
|
-
# Building the brick chain for a router method.
|
61
|
-
# Gets before bricks in reverse router and merge it with standard calls.
|
62
|
-
# Keeps the brickchain in cache for later calls.
|
63
|
-
def generate_brickchain(router_method_name)
|
64
|
-
unless @brick_call_chains_cache.has_key? router_method_name
|
65
|
-
return unless @router.has_key? router_method_name
|
66
|
-
final_call_chain = []
|
67
|
-
# Search for rev_router matches
|
68
|
-
@rev_router.each do |rev_router_item|
|
69
|
-
if rev_router_item.has_key? 'match_only'
|
70
|
-
rev_router_item['match_only'].each do |matcher|
|
71
|
-
if router_method_name.match(Regexp.new("^#{matcher}$"))
|
72
|
-
final_call_chain.concat rev_router_item['bricks']
|
73
|
-
break
|
74
|
-
end
|
75
|
-
end
|
76
|
-
elsif rev_router_item.has_key? 'all_except'
|
77
|
-
one_match = false
|
78
|
-
rev_router_item['all_except'].each do |matcher|
|
79
|
-
one_match ||= router_method_name.match(Regexp.new("^#{matcher}$"))
|
80
|
-
break if one_match
|
81
|
-
end
|
82
|
-
final_call_chain.concat rev_router_item['bricks'] unless one_match
|
83
|
-
end
|
84
|
-
end
|
85
|
-
# Append router call chain
|
86
|
-
final_call_chain.concat @router[router_method_name]
|
87
|
-
# Save in cache
|
88
|
-
@brick_call_chains_cache[router_method_name] = final_call_chain
|
89
|
-
end
|
90
|
-
@brick_call_chains_cache[router_method_name]
|
91
|
-
end
|
92
|
-
|
93
58
|
##
|
94
59
|
# Renders a json or anything else
|
95
60
|
def do_render(to_render)
|
@@ -111,6 +76,7 @@ module Culpa
|
|
111
76
|
verb: env['REQUEST_METHOD'].downcase.to_sym,
|
112
77
|
params: Rack::Utils.parse_nested_query(env['QUERY_STRING'])
|
113
78
|
}
|
79
|
+
# Parse body if in JSON
|
114
80
|
if env['CONTENT_TYPE'] == 'application/json'
|
115
81
|
body = JSON.parse(env['rack.input'].read)
|
116
82
|
if body.has_key? 'sub_call'
|
@@ -120,6 +86,7 @@ module Culpa
|
|
120
86
|
else
|
121
87
|
call_options[:input] = env['rack.input']
|
122
88
|
end
|
89
|
+
# Try the known routes
|
123
90
|
if !(route_params = PathParser.parse('/:res_name', env['PATH_INFO'])).nil?
|
124
91
|
call_options[:res_name] = route_params[:res_name]
|
125
92
|
case call_options[:verb]
|
@@ -150,6 +117,7 @@ module Culpa
|
|
150
117
|
else
|
151
118
|
return bad_request
|
152
119
|
end
|
120
|
+
# Call the brickchain and return the value to Rack
|
153
121
|
call_brickchain call_options
|
154
122
|
end
|
155
123
|
|