rad_core 0.2.6 → 0.2.7
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.
- data/Rakefile +2 -2
- data/bin/rad +20 -25
- data/lib/components/config.rb +1 -1
- data/lib/components/configurators.rb +2 -2
- data/lib/components/controller.rb +2 -2
- data/lib/components/conveyors.rb +2 -2
- data/lib/components/environment.rb +1 -1
- data/lib/components/environment.yml +28 -28
- data/lib/components/flash.rb +1 -1
- data/lib/components/html.rb +1 -1
- data/lib/components/http.rb +1 -1
- data/lib/components/http.yml +1 -1
- data/lib/components/logger.rb +2 -2
- data/lib/components/mailer.rb +2 -2
- data/lib/components/remote.rb +1 -1
- data/lib/components/router.rb +3 -3
- data/lib/components/template.rb +2 -2
- data/lib/components/web.rb +3 -3
- data/lib/rad.rb +1 -1
- data/lib/rad/_support/active_support.rb +7 -7
- data/lib/rad/_support/active_support/locales/ru/actionview.yml +8 -8
- data/lib/rad/_support/active_support/locales/ru/activesupport.yml +4 -4
- data/lib/rad/_support/active_support/locales/ru/datetime.yml +5 -5
- data/lib/rad/_support/active_support/time.rb +2 -2
- data/lib/rad/_support/addressable.rb +6 -6
- data/lib/rad/_support/class_loader.rb +1 -1
- data/lib/rad/_support/extensions.rb +5 -5
- data/lib/rad/_support/filters.rb +13 -13
- data/lib/rad/_support/hacks_and_fixes.rb +5 -5
- data/lib/rad/_support/mime.rb +4 -4
- data/lib/rad/_support/module.rb +11 -11
- data/lib/rad/_support/require.rb +5 -5
- data/lib/rad/_support/rson.rb +4 -4
- data/lib/rad/_support/string.rb +9 -9
- data/lib/rad/cli/helper.rb +5 -5
- data/lib/rad/configurators/_require.rb +2 -2
- data/lib/rad/configurators/abstract.rb +5 -5
- data/lib/rad/configurators/web.rb +8 -8
- data/lib/rad/controller/_abstract.rb +15 -14
- data/lib/rad/controller/_abstract/miscellaneous.rb +5 -5
- data/lib/rad/controller/_abstract/render.rb +40 -40
- data/lib/rad/controller/_abstract/responder.rb +1 -1
- data/lib/rad/controller/_context.rb +1 -1
- data/lib/rad/controller/_http.rb +11 -11
- data/lib/rad/controller/_require.rb +6 -6
- data/lib/rad/controller/processors/controller_caller.rb +3 -3
- data/lib/rad/controller/processors/controller_error_handling.rb +14 -14
- data/lib/rad/controller/processors/controller_logger.rb +1 -1
- data/lib/rad/conveyors/_conveyor.rb +9 -9
- data/lib/rad/conveyors/_conveyors.rb +4 -4
- data/lib/rad/conveyors/_params.rb +5 -5
- data/lib/rad/conveyors/_processor.rb +2 -2
- data/lib/rad/conveyors/_workspace.rb +5 -5
- data/lib/rad/conveyors/processors/conveyor_logger.rb +3 -3
- data/lib/rad/environment/_config.rb +4 -4
- data/lib/rad/environment/_environment.rb +10 -10
- data/lib/rad/environment/_files_helper.rb +5 -5
- data/lib/rad/environment/_logger.rb +9 -9
- data/lib/rad/environment/_require.rb +4 -4
- data/lib/rad/gems.rb +14 -14
- data/lib/rad/html/_flash.rb +5 -5
- data/lib/rad/html/_helpers/basic_html_helper.rb +12 -12
- data/lib/rad/html/_helpers/form_helper.rb +19 -19
- data/lib/rad/html/_helpers/javascript_helper.rb +6 -6
- data/lib/rad/html/_helpers/model_helper.rb +17 -17
- data/lib/rad/html/_require.rb +1 -1
- data/lib/rad/html/processors/prepare_flash.rb +3 -3
- data/lib/rad/html/processors/scoped_params.rb +4 -4
- data/lib/rad/http/_http.rb +4 -4
- data/lib/rad/http/_http_adapter.rb +5 -5
- data/lib/rad/http/_request.rb +11 -11
- data/lib/rad/http/_require.rb +8 -8
- data/lib/rad/http/_response.rb +5 -5
- data/lib/rad/http/_support/rack/fixes.rb +3 -3
- data/lib/rad/http/_support/rack/rack_adapter.rb +5 -5
- data/lib/rad/http/processors/evaluate_format.rb +4 -4
- data/lib/rad/http/processors/http_logger.rb +3 -3
- data/lib/rad/http/processors/http_writer.rb +7 -7
- data/lib/rad/http/processors/prepare_params.rb +5 -5
- data/lib/rad/mailer/_letter.rb +1 -1
- data/lib/rad/mailer/_mailer.rb +1 -1
- data/lib/rad/mailer/_mailer_controller.rb +6 -6
- data/lib/rad/mailer/_require.rb +1 -1
- data/lib/rad/mailer/processors/letter_builder.rb +6 -6
- data/lib/rad/profiles/mailer.rb +2 -2
- data/lib/rad/profiles/web.rb +13 -13
- data/lib/rad/remote/processors/remote_caller.rb +10 -10
- data/lib/rad/remote/processors/remote_logger.rb +1 -1
- data/lib/rad/router/_abstract_router.rb +9 -9
- data/lib/rad/router/_alias_router.rb +34 -34
- data/lib/rad/router/_basic_router.rb +12 -12
- data/lib/rad/router/_configurator.rb +6 -6
- data/lib/rad/router/_core_routing_helper.rb +4 -4
- data/lib/rad/router/_object_router.rb +45 -45
- data/lib/rad/router/_require.rb +8 -8
- data/lib/rad/router/_restful_router.rb +25 -25
- data/lib/rad/router/_router.rb +78 -78
- data/lib/rad/router/_simple_router.rb +5 -5
- data/lib/rad/router/processors/router.rb +6 -6
- data/lib/rad/spec/controller.rb +9 -9
- data/lib/rad/spec/environment.rb +7 -7
- data/lib/rad/spec/http.rb +2 -2
- data/lib/rad/spec/http_controller.rb +22 -22
- data/lib/rad/spec/mailer.rb +4 -4
- data/lib/rad/spec/remote.rb +1 -1
- data/lib/rad/spec/router.rb +4 -4
- data/lib/rad/spec/template.rb +2 -2
- data/lib/rad/tasks.rb +2 -2
- data/lib/rad/template/_context.rb +15 -15
- data/lib/rad/template/_relative_path_resolver.rb +1 -1
- data/lib/rad/template/_support/tilt.rb +17 -17
- data/lib/rad/template/_support/tilt_fixes.rb +3 -3
- data/lib/rad/template/_template.rb +47 -47
- data/lib/rad/web/_ajax_helper.rb +4 -4
- data/lib/rad/web/_controller_miscellaneous_helper.rb +5 -5
- data/lib/rad/web/_ensure_no_www.rb +5 -5
- data/lib/rad/web/_protect_from_forgery.rb +18 -18
- data/lib/rad/web/_require.rb +7 -7
- data/lib/rad/web/_router/abstract_routing_helper.rb +4 -4
- data/lib/rad/web/_router/controller_routing_helper.rb +15 -15
- data/lib/rad/web/_router/view_routing_helper.rb +12 -12
- data/readme.md +5 -5
- data/spec/controller/abstract_spec.rb +29 -29
- data/spec/controller/context_spec.rb +32 -32
- data/spec/controller/error_handling_spec.rb +31 -31
- data/spec/controller/helper_spec.rb +13 -13
- data/spec/controller/http_spec.rb +32 -32
- data/spec/controller/render_spec.rb +59 -59
- data/spec/conveyors/conveyors_spec.rb +32 -32
- data/spec/environment/config_spec.rb +6 -6
- data/spec/environment/environment_spec.rb +7 -7
- data/spec/environment/minimal_app_spec.rb +4 -4
- data/spec/environment/standard_app_spec.rb +10 -10
- data/spec/html/basic_html_helper_spec.rb +6 -6
- data/spec/html/form_helper_spec.rb +5 -5
- data/spec/html/javascript_helper_spec.rb +4 -4
- data/spec/html/model_helper_spec.rb +12 -12
- data/spec/html/scoped_params_spec.rb +2 -2
- data/spec/html/spec_helper.rb +3 -3
- data/spec/http/http_spec.rb +9 -9
- data/spec/http/miscellaneous_spec.rb +2 -2
- data/spec/mailer/mail_controller_spec.rb +23 -23
- data/spec/remote/remote_spec.rb +26 -26
- data/spec/router/alias_router_spec.rb +22 -22
- data/spec/router/basic_router_spec.rb +8 -8
- data/spec/router/configurator_spec.rb +4 -4
- data/spec/router/integration_spec.rb +17 -17
- data/spec/router/object_router_spec.rb +47 -47
- data/spec/router/persistent_params_spec.rb +18 -18
- data/spec/router/restful_router_spec.rb +39 -39
- data/spec/router/router_spec.rb +37 -37
- data/spec/router/routing_helper_spec.rb +18 -18
- data/spec/support/filters_spec.rb +11 -13
- data/spec/template/template_spec.rb +43 -45
- data/spec/template/template_spec/views/layout/content_for/content.erb +3 -1
- data/spec/template/template_spec/views/layout/content_for/layout.erb +1 -1
- data/spec/template/tilt_spec.rb +24 -24
- data/spec/web/basic_spec.rb +25 -25
- data/spec/web/controller_routing_helper_spec.rb +26 -26
- data/spec/web/flash_spec.rb +31 -31
- data/spec/web/protect_from_forgery_spec.rb +44 -44
- data/spec/web/spec_helper_spec.rb +16 -16
- data/spec/web/view_routing_helper_spec.rb +31 -31
- metadata +46 -49
- data/lib/rad/_support/callbacks.rb +0 -166
- data/lib/rad/_support/ruby_ext_with_active_support.rb +0 -4
- data/spec/support/callbacks_spec.rb +0 -157
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
module Rad::Controller::Abstract::Miscellaneous
|
|
2
|
-
#
|
|
2
|
+
#
|
|
3
3
|
# respond_to
|
|
4
|
-
#
|
|
4
|
+
#
|
|
5
5
|
def respond_to &block
|
|
6
6
|
@_responder.must_be.nil
|
|
7
7
|
@_responder = Rad::Controller::Abstract::Responder.new
|
|
@@ -12,9 +12,9 @@ module Rad::Controller::Abstract::Miscellaneous
|
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
module ClassMethods
|
|
15
|
-
#
|
|
15
|
+
#
|
|
16
16
|
# filter_parameter_logging
|
|
17
|
-
#
|
|
17
|
+
#
|
|
18
18
|
inheritable_accessor :filter_parameter_logging, []
|
|
19
19
|
def filter_parameter_logging_with_sugar *parameters
|
|
20
20
|
if parameters.empty?
|
|
@@ -22,6 +22,6 @@ module Rad::Controller::Abstract::Miscellaneous
|
|
|
22
22
|
else
|
|
23
23
|
filter_parameter_logging_without_sugar.push *parameters.collect(&:to_s)
|
|
24
24
|
end
|
|
25
|
-
end
|
|
25
|
+
end
|
|
26
26
|
end
|
|
27
27
|
end
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
module Rad::Controller::Abstract::Render
|
|
1
|
+
module Rad::Controller::Abstract::Render
|
|
2
2
|
SPECIAL_FORMAT_HANDLERS = {
|
|
3
3
|
json: lambda{|o| o.to_json},
|
|
4
4
|
xml: lambda{|o| o.to_xml},
|
|
5
|
-
js: lambda{|o| o},
|
|
5
|
+
js: lambda{|o| o},
|
|
6
6
|
}
|
|
7
7
|
|
|
8
|
-
def _layout *args
|
|
8
|
+
def _layout *args
|
|
9
9
|
@_layout = *args unless args.empty?
|
|
10
10
|
@_layout
|
|
11
11
|
end
|
|
@@ -14,24 +14,24 @@ module Rad::Controller::Abstract::Render
|
|
|
14
14
|
end
|
|
15
15
|
|
|
16
16
|
def render *args
|
|
17
|
-
options = rad.template.parse_arguments *args
|
|
18
|
-
|
|
19
|
-
instance_variables = {
|
|
17
|
+
options = rad.template.parse_arguments *args
|
|
18
|
+
|
|
19
|
+
instance_variables = {
|
|
20
20
|
controller_name: self.class.controller_name
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
instance_variable_names.each do |name|
|
|
24
24
|
instance_variables[name[1..-1]] = instance_variable_get name unless name =~ /^@_/
|
|
25
25
|
end
|
|
26
|
-
|
|
26
|
+
|
|
27
27
|
instance_variables[:action_name] = options[:action] if options[:action]
|
|
28
|
-
|
|
29
|
-
context = self.class.context_class.new(instance_variables, self)
|
|
30
|
-
|
|
28
|
+
|
|
29
|
+
context = self.class.context_class.new(instance_variables, self)
|
|
30
|
+
|
|
31
31
|
options.reverse_merge! \
|
|
32
32
|
context: context,
|
|
33
33
|
format: params.format,
|
|
34
|
-
exact_format: true,
|
|
34
|
+
exact_format: true,
|
|
35
35
|
relative_path_resolver: self.class
|
|
36
36
|
|
|
37
37
|
content = render_content options
|
|
@@ -41,37 +41,37 @@ module Rad::Controller::Abstract::Render
|
|
|
41
41
|
end
|
|
42
42
|
|
|
43
43
|
protected
|
|
44
|
-
def render_content options
|
|
45
|
-
if special_format = SPECIAL_FORMAT_HANDLERS.keys.find{|f| options.include? f}
|
|
44
|
+
def render_content options
|
|
45
|
+
if special_format = SPECIAL_FORMAT_HANDLERS.keys.find{|f| options.include? f}
|
|
46
46
|
handler = SPECIAL_FORMAT_HANDLERS[special_format]
|
|
47
47
|
if special_format.to_s != params.format
|
|
48
48
|
raise "You trying responing with '#{special_format}' to the '#{params.format}' requested format!"
|
|
49
49
|
end
|
|
50
50
|
handler.call options[special_format]
|
|
51
|
-
elsif options.include? :inline
|
|
51
|
+
elsif options.include? :inline
|
|
52
52
|
options[:inline]
|
|
53
53
|
elsif options[:template] == :nothing
|
|
54
54
|
''
|
|
55
|
-
else
|
|
56
|
-
if action = options.delete(:action)
|
|
57
|
-
options[:template].must_be.blank
|
|
55
|
+
else
|
|
56
|
+
if action = options.delete(:action)
|
|
57
|
+
options[:template].must_be.blank
|
|
58
58
|
options[:template] = action
|
|
59
|
-
|
|
59
|
+
|
|
60
60
|
options.reverse_merge! \
|
|
61
61
|
prefixes: [''],
|
|
62
62
|
if_not_exist: '/rad_default_templates/blank_template'
|
|
63
63
|
end
|
|
64
64
|
options[:template].must_be.present
|
|
65
|
-
options[:template] = options[:template].to_s
|
|
66
|
-
|
|
65
|
+
options[:template] = options[:template].to_s
|
|
66
|
+
|
|
67
67
|
rad.template.render options
|
|
68
68
|
end
|
|
69
69
|
end
|
|
70
|
-
|
|
70
|
+
|
|
71
71
|
def render_layout content, options
|
|
72
72
|
layout = options.include?(:layout) ? options[:layout] : self._layout
|
|
73
|
-
|
|
74
|
-
if layout and rad.template.exist? layout, options
|
|
73
|
+
|
|
74
|
+
if layout and rad.template.exist? layout, options
|
|
75
75
|
options = options.merge template: layout
|
|
76
76
|
rad.template.render options do |*args|
|
|
77
77
|
if args.empty?
|
|
@@ -81,7 +81,7 @@ module Rad::Controller::Abstract::Render
|
|
|
81
81
|
variable_name = args.first.to_s
|
|
82
82
|
options[:context].content_variables[variable_name]
|
|
83
83
|
end
|
|
84
|
-
end
|
|
84
|
+
end
|
|
85
85
|
else
|
|
86
86
|
content
|
|
87
87
|
end
|
|
@@ -93,11 +93,11 @@ module Rad::Controller::Abstract::Render
|
|
|
93
93
|
controller._layout = layout
|
|
94
94
|
end
|
|
95
95
|
end
|
|
96
|
-
|
|
96
|
+
|
|
97
97
|
def context_class
|
|
98
98
|
unless @context_class
|
|
99
99
|
parent_context_class = nil
|
|
100
|
-
ancestors[1..-1].each do |anc|
|
|
100
|
+
ancestors[1..-1].each do |anc|
|
|
101
101
|
break if parent_context_class = anc.respond_to(:context_class)
|
|
102
102
|
end
|
|
103
103
|
parent_context_class ||= Rad::Controller::Context
|
|
@@ -110,36 +110,36 @@ module Rad::Controller::Abstract::Render
|
|
|
110
110
|
end
|
|
111
111
|
@context_class
|
|
112
112
|
end
|
|
113
|
-
|
|
113
|
+
|
|
114
114
|
def find_relative_template *args
|
|
115
115
|
return _find_relative_template *args unless rad.production?
|
|
116
|
-
|
|
116
|
+
|
|
117
117
|
# use cache
|
|
118
|
-
@relative_template ||= {}
|
|
119
|
-
unless @relative_template.include? args
|
|
118
|
+
@relative_template ||= {}
|
|
119
|
+
unless @relative_template.include? args
|
|
120
120
|
@relative_template[args] = _find_relative_template *args
|
|
121
121
|
end
|
|
122
122
|
@relative_template[args]
|
|
123
123
|
end
|
|
124
|
-
|
|
124
|
+
|
|
125
125
|
def _find_relative_template tname, prefixes, format, exact_format, current_dir
|
|
126
126
|
tname.must_be.present
|
|
127
|
-
|
|
127
|
+
|
|
128
128
|
path = nil
|
|
129
|
-
|
|
129
|
+
|
|
130
130
|
# own templates
|
|
131
|
-
["/#{controller_name.underscore}/#{tname}", "/#{controller_name.gsub('::', '/')}/#{tname}"].each do |name|
|
|
131
|
+
["/#{controller_name.underscore}/#{tname}", "/#{controller_name.gsub('::', '/')}/#{tname}"].each do |name|
|
|
132
132
|
path ||= rad.template.find_file(name, prefixes, format, exact_format, rad.template.paths)
|
|
133
133
|
end
|
|
134
|
-
|
|
135
|
-
# own :actions templates
|
|
134
|
+
|
|
135
|
+
# own :actions templates
|
|
136
136
|
["/#{controller_name.underscore}/actions", "/#{controller_name.gsub('::', '/')}/actions"].each do |name|
|
|
137
137
|
unless path
|
|
138
138
|
path = rad.template.find_file(name, prefixes, format, exact_format, rad.template.paths)
|
|
139
139
|
path = nil if path and (File.read(path) !~ /^.*when.+[^_a-zA-Z0-9]#{tname}[^_a-zA-Z0-9].*$/)
|
|
140
140
|
end
|
|
141
141
|
end
|
|
142
|
-
|
|
142
|
+
|
|
143
143
|
# superclasses templates
|
|
144
144
|
unless path
|
|
145
145
|
parent = ancestors[1..-1].find{|a| a.respond_to?(:find_relative_template)} # and a.instance_methods.include?(action)
|
|
@@ -147,12 +147,12 @@ module Rad::Controller::Abstract::Render
|
|
|
147
147
|
path = parent.find_relative_template(tname, prefixes, format, exact_format, current_dir)
|
|
148
148
|
end
|
|
149
149
|
end
|
|
150
|
-
|
|
150
|
+
|
|
151
151
|
# relative template
|
|
152
|
-
if !path and current_dir
|
|
152
|
+
if !path and current_dir
|
|
153
153
|
path = rad.template.relative_path_resolver.find_relative_template(tname, prefixes, format, exact_format, current_dir)
|
|
154
154
|
end
|
|
155
|
-
|
|
155
|
+
|
|
156
156
|
return path
|
|
157
157
|
end
|
|
158
158
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
class Rad::Controller::Context < Rad::Template::Context
|
|
2
2
|
attr_reader :controller, :controller_name, :action_name
|
|
3
3
|
delegate :params, :request, :response, to: :controller
|
|
4
|
-
|
|
4
|
+
|
|
5
5
|
def initialize instance_variables, controller
|
|
6
6
|
super instance_variables
|
|
7
7
|
@controller = controller
|
data/lib/rad/controller/_http.rb
CHANGED
|
@@ -5,7 +5,7 @@ module Rad::Controller::Http
|
|
|
5
5
|
def response; rad.workspace? ? workspace.response : nil end
|
|
6
6
|
|
|
7
7
|
def render *args
|
|
8
|
-
if args.size == 1 and (status = Rad::Http::Response.decode_status_message(args.first))
|
|
8
|
+
if args.size == 1 and (status = Rad::Http::Response.decode_status_message(args.first))
|
|
9
9
|
response.set! status: status
|
|
10
10
|
throw :halt, ""
|
|
11
11
|
else
|
|
@@ -17,36 +17,36 @@ module Rad::Controller::Http
|
|
|
17
17
|
def render_content options
|
|
18
18
|
if response
|
|
19
19
|
response.set!(
|
|
20
|
-
status: options[:status] || :ok,
|
|
20
|
+
status: options[:status] || :ok,
|
|
21
21
|
content_type: options[:content_type] || Mime[params.format]
|
|
22
22
|
)
|
|
23
23
|
end
|
|
24
|
-
|
|
24
|
+
|
|
25
25
|
if options[:location]
|
|
26
26
|
redirect_to options[:location]
|
|
27
|
-
else
|
|
27
|
+
else
|
|
28
28
|
super
|
|
29
29
|
end
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
-
module ClassMethods
|
|
32
|
+
module ClassMethods
|
|
33
33
|
inheritable_accessor :actions_allowed_for_get_request, []
|
|
34
|
-
|
|
34
|
+
|
|
35
35
|
def allow_get_for *methods
|
|
36
36
|
methods = methods.first if methods.first.is_a? Array
|
|
37
|
-
|
|
38
|
-
enable_protection_from_get_requests!
|
|
37
|
+
|
|
38
|
+
enable_protection_from_get_requests!
|
|
39
39
|
actions_allowed_for_get_request.push *(methods.collect(&:to_sym))
|
|
40
40
|
end
|
|
41
|
-
|
|
41
|
+
|
|
42
42
|
private
|
|
43
43
|
def enable_protection_from_get_requests!
|
|
44
44
|
unless respond_to? :protect_from_get_request
|
|
45
45
|
define_method :protect_from_get_request do
|
|
46
|
-
get = !(request.post? or request.put? or request.delete?)
|
|
46
|
+
get = !(request.post? or request.put? or request.delete?)
|
|
47
47
|
if get and !self.class.actions_allowed_for_get_request.include?(action_name)
|
|
48
48
|
raise "GET request not allowed for :#{action_name} action!"
|
|
49
|
-
end
|
|
49
|
+
end
|
|
50
50
|
end
|
|
51
51
|
before :protect_from_get_request
|
|
52
52
|
end
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
#
|
|
1
|
+
#
|
|
2
2
|
# Libraries
|
|
3
|
-
#
|
|
3
|
+
#
|
|
4
4
|
class Rad::Controller
|
|
5
5
|
attr_accessor :development_error_template, :production_error_template, :test_error_template
|
|
6
|
-
|
|
6
|
+
|
|
7
7
|
module Abstract
|
|
8
8
|
end
|
|
9
9
|
end
|
|
10
10
|
|
|
11
|
-
%w(
|
|
11
|
+
%w(
|
|
12
12
|
_abstract/render
|
|
13
13
|
_abstract/responder
|
|
14
|
-
_abstract/miscellaneous
|
|
14
|
+
_abstract/miscellaneous
|
|
15
15
|
_abstract
|
|
16
16
|
_context
|
|
17
|
-
|
|
17
|
+
|
|
18
18
|
_http
|
|
19
19
|
).each{|f| require "rad/controller/#{f}"}
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
rad.controller
|
|
2
2
|
|
|
3
3
|
class ControllerCaller < Rad::Conveyors::Processor
|
|
4
|
-
def call
|
|
4
|
+
def call
|
|
5
5
|
# prepare
|
|
6
6
|
response = workspace.response.must_be.defined
|
|
7
7
|
klass = workspace.class.must_be.present
|
|
8
|
-
raise "The controller class #{klass} must be a Rad::Controller::Abstract!" unless klass.is? Rad::Controller::Abstract
|
|
8
|
+
raise "The controller class #{klass} must be a Rad::Controller::Abstract!" unless klass.is? Rad::Controller::Abstract
|
|
9
9
|
action_name = workspace.action_name = workspace.method_name
|
|
10
10
|
format = workspace.params.format
|
|
11
11
|
|
|
@@ -13,6 +13,6 @@ class ControllerCaller < Rad::Conveyors::Processor
|
|
|
13
13
|
controller = workspace.controller = klass.new
|
|
14
14
|
controller.set! params: workspace.params, action_name: workspace.action_name
|
|
15
15
|
workspace.content = controller.call action_name
|
|
16
|
-
end
|
|
16
|
+
end
|
|
17
17
|
|
|
18
18
|
end
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
rad.controller
|
|
2
2
|
|
|
3
|
-
class ControllerErrorHandling < Rad::Conveyors::Processor
|
|
4
|
-
def call
|
|
3
|
+
class ControllerErrorHandling < Rad::Conveyors::Processor
|
|
4
|
+
def call
|
|
5
5
|
workspace.response.must_be.defined
|
|
6
|
-
|
|
6
|
+
|
|
7
7
|
begin
|
|
8
|
-
next_processor.call
|
|
8
|
+
next_processor.call
|
|
9
9
|
rescue StandardError => e
|
|
10
10
|
if rad.test?
|
|
11
11
|
# e.set_backtrace e.backtrace.sfilter(Exception.filters)
|
|
@@ -16,29 +16,29 @@ class ControllerErrorHandling < Rad::Conveyors::Processor
|
|
|
16
16
|
else
|
|
17
17
|
error_shown_to_user = e
|
|
18
18
|
end
|
|
19
|
-
|
|
20
|
-
workspace.response.clear if workspace.response
|
|
19
|
+
|
|
20
|
+
workspace.response.clear if workspace.response
|
|
21
21
|
format = workspace.params.format
|
|
22
22
|
handler = SPECIAL_ERROR_HANDLERS[format] || DEFAULT_ERROR_HANDLER
|
|
23
23
|
workspace.content = handler.call error_shown_to_user, format
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
|
|
25
|
+
|
|
26
26
|
logger.error e
|
|
27
27
|
logger.info "\n"
|
|
28
28
|
end
|
|
29
|
-
end
|
|
29
|
+
end
|
|
30
30
|
|
|
31
31
|
SPECIAL_ERROR_HANDLERS = {
|
|
32
|
-
'json' => lambda{|e, format|
|
|
32
|
+
'json' => lambda{|e, format|
|
|
33
33
|
{error: e.message}.to_json
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
|
|
37
|
-
DEFAULT_ERROR_HANDLER = lambda{|e, format|
|
|
36
|
+
|
|
37
|
+
DEFAULT_ERROR_HANDLER = lambda{|e, format|
|
|
38
38
|
tname = rad.controller.send("#{rad.mode}_error_template")
|
|
39
39
|
if tname and rad.template.exist?(tname, format: format, exact_format: true)
|
|
40
|
-
data = rad.template.render(tname,
|
|
41
|
-
format: format,
|
|
40
|
+
data = rad.template.render(tname,
|
|
41
|
+
format: format,
|
|
42
42
|
locals: {error: e}
|
|
43
43
|
)
|
|
44
44
|
else
|
|
@@ -4,14 +4,14 @@ class Rad::Conveyors::Conveyor
|
|
|
4
4
|
def definitions
|
|
5
5
|
@definitions ||= []
|
|
6
6
|
end
|
|
7
|
-
|
|
7
|
+
|
|
8
8
|
def use processor_class, *initialization_arguments
|
|
9
9
|
definitions << [processor_class, initialization_arguments]
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
def build!
|
|
13
|
-
@chain = lambda{}
|
|
14
|
-
definitions.reverse.collect do |klass, args|
|
|
13
|
+
@chain = lambda{}
|
|
14
|
+
definitions.reverse.collect do |klass, args|
|
|
15
15
|
klass.must_be.a Class
|
|
16
16
|
@chain = klass.new @chain, *args
|
|
17
17
|
end
|
|
@@ -19,18 +19,18 @@ class Rad::Conveyors::Conveyor
|
|
|
19
19
|
|
|
20
20
|
def call workspace_content = {}, &block
|
|
21
21
|
build! unless @chain
|
|
22
|
-
|
|
22
|
+
|
|
23
23
|
scope = (rad.custom_scopes[:cycle] || {}).clone
|
|
24
24
|
rad.activate :cycle, scope do
|
|
25
25
|
self.workspace = ::Rad::Conveyors::Workspace.new unless self.workspace?
|
|
26
|
-
workspace.merge! workspace_content
|
|
27
|
-
|
|
26
|
+
workspace.merge! workspace_content
|
|
27
|
+
|
|
28
28
|
if block
|
|
29
29
|
block.call(@chain)
|
|
30
30
|
else
|
|
31
31
|
@chain.call
|
|
32
32
|
end
|
|
33
|
-
|
|
33
|
+
|
|
34
34
|
workspace
|
|
35
35
|
end
|
|
36
36
|
end
|
|
@@ -43,7 +43,7 @@ class Rad::Conveyors::Conveyor
|
|
|
43
43
|
# start_time = Time.now
|
|
44
44
|
# block.call
|
|
45
45
|
# (workspace.trace ||= []) << [name, Time.now - start_time]
|
|
46
|
-
# end
|
|
46
|
+
# end
|
|
47
47
|
|
|
48
48
|
protected
|
|
49
49
|
# def build_chain
|
|
@@ -64,7 +64,7 @@ class Rad::Conveyors::Conveyor
|
|
|
64
64
|
# raise "Can't find Processor '#{name}'!" unless index
|
|
65
65
|
# insert index, *Array(processors)
|
|
66
66
|
# end
|
|
67
|
-
#
|
|
67
|
+
#
|
|
68
68
|
# def add_after key, *processors
|
|
69
69
|
# index = rindex{|processor| processor.name == key or processor.class == key}
|
|
70
70
|
# raise "Can't find Processor '#{name}'!" unless index
|