rad_core 0.0.25 → 0.0.26
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 +3 -1
- data/bin/rad +33 -0
- data/lib/components/configurators.rb +5 -0
- data/lib/components/environment.production.yml +1 -0
- data/lib/components/environment.yml +30 -1
- data/lib/components/http.yml +12 -1
- data/lib/components/web.rb +2 -2
- data/lib/rad/_support/active_support/{micelaneous.rb → miscellaneous.rb} +0 -0
- data/lib/rad/_support/active_support.rb +1 -1
- data/lib/rad/_support/exception.rb +9 -40
- data/lib/rad/_support/string.rb +7 -1
- data/lib/rad/cli/helper.rb +34 -0
- data/lib/rad/configurators/_require.rb +13 -0
- data/lib/rad/configurators/abstract.rb +24 -0
- data/lib/rad/configurators/runtime.rb +4 -0
- data/lib/rad/configurators/web.rb +34 -0
- data/lib/rad/controller/_abstract/{micelaneous.rb → miscellaneous.rb} +1 -1
- data/lib/rad/controller/_abstract/render.rb +54 -53
- data/lib/rad/controller/_abstract.rb +16 -8
- data/lib/rad/controller/_context.rb +3 -9
- data/lib/rad/controller/_http.rb +22 -17
- data/lib/rad/controller/_require.rb +1 -1
- data/lib/rad/controller/processors/controller_caller.rb +5 -13
- data/lib/rad/controller/processors/controller_error_handling.rb +2 -2
- data/lib/rad/environment/_environment.rb +4 -0
- data/lib/rad/environment/_logger.rb +5 -5
- data/lib/rad/html/_require.rb +1 -1
- data/lib/rad/http/_http.rb +8 -4
- data/lib/rad/http/_http_adapter.rb +1 -21
- data/lib/rad/http/_request.rb +48 -7
- data/lib/rad/http/_require.rb +1 -1
- data/lib/rad/http/_response.rb +1 -1
- data/lib/rad/http/_support/rack/fixes.rb +6 -0
- data/lib/rad/http/processors/prepare_params.rb +1 -1
- data/lib/rad/mailer/processors/letter_builder.rb +3 -9
- data/lib/rad/profiles/web.rb +35 -10
- data/lib/rad/router/_router.rb +1 -1
- data/lib/rad/router/{micelaneous_router.rb → miscellaneous_router.rb} +0 -0
- data/lib/rad/spec/http_controller.rb +15 -11
- data/lib/rad/spec/web.rb +7 -0
- data/lib/rad/spec.rb +1 -0
- data/lib/rad/tasks.rb +15 -0
- data/lib/rad/template/_context.rb +0 -4
- data/lib/rad/template/_template.rb +1 -1
- data/lib/rad/web/_ajax_helper.rb +16 -0
- data/lib/rad/{core_web/_controller_micelaneous_helper.rb → web/_controller_miscellaneous_helper.rb} +2 -2
- data/lib/rad/web/_ensure_no_www.rb +30 -0
- data/lib/rad/web/_protect_from_forgery.rb +71 -0
- data/lib/rad/{core_web → web}/_require.rb +13 -4
- data/lib/rad/{core_web → web}/_router/abstract_routing_helper.rb +0 -0
- data/lib/rad/{core_web → web}/_router/controller_routing_helper.rb +0 -0
- data/lib/rad/{core_web → web}/_router/view_routing_helper.rb +0 -0
- data/lib/rad.rb +1 -1
- data/readme.md +14 -7
- data/spec/controller/abstract_spec.rb +2 -2
- data/spec/controller/error_handling_spec.rb +1 -1
- data/spec/controller/http_spec/views/ViewVariablesSpec/action.erb +2 -0
- data/spec/controller/http_spec.rb +18 -1
- data/spec/controller/render_spec.rb +13 -13
- data/spec/http/http_spec.rb +1 -1
- data/spec/http/{micelaneous_spec.rb → miscellaneous_spec.rb} +0 -0
- data/spec/router/integration_spec.rb +4 -1
- data/spec/router/object_router_spec.rb +1 -1
- data/spec/router/persistent_params_spec.rb +1 -1
- data/spec/router/restful_router_spec.rb +1 -1
- data/spec/web/basic_spec.rb +8 -4
- data/spec/web/controller_routing_helper_spec.rb +4 -3
- data/spec/web/flash_spec.rb +2 -3
- data/spec/web/protect_from_forgery_spec.rb +187 -0
- data/spec/web/spec_helper_spec.rb +9 -5
- data/spec/web/view_routing_helper_spec.rb +1 -1
- metadata +27 -12
data/Rakefile
CHANGED
@@ -3,8 +3,10 @@ require 'rake_ext'
|
|
3
3
|
project(
|
4
4
|
name: 'rad',
|
5
5
|
official_name: 'rad_core',
|
6
|
+
bin: 'bin',
|
7
|
+
dirs: 'bin',
|
6
8
|
gem: true,
|
7
|
-
summary: '
|
9
|
+
summary: 'Simple and highly customizable Web Framework encouraging to build an app as a set of low-coupled components instead of monolith',
|
8
10
|
|
9
11
|
author: 'Alexey Petrushin',
|
10
12
|
homepage: 'http://github.com/alexeypetrushin/rad_core'
|
data/bin/rad
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# sadly it's impossible to pass '-Ku' argument to ruby via shebang, use RUBYOPT to set it, something like:
|
3
|
+
# $ export RUBYOPT="-Ku -rrubygems"
|
4
|
+
|
5
|
+
require 'rad'
|
6
|
+
require 'rad/cli/helper'
|
7
|
+
|
8
|
+
# version
|
9
|
+
if ARGV.first =~ /-v|version|-version/
|
10
|
+
puts "Rad #{Rad::VERSION}"
|
11
|
+
exit
|
12
|
+
end
|
13
|
+
|
14
|
+
# mode and environment
|
15
|
+
mode = (%w(server console).include? ARGV.first) ? ARGV.shift : 'server'
|
16
|
+
environment = (%w(production development test).include? ARGV.first) ? ARGV.shift : :development
|
17
|
+
rad.mode = environment
|
18
|
+
|
19
|
+
# config options
|
20
|
+
ARGV.each do |expression|
|
21
|
+
name, value = expression.split('=')
|
22
|
+
name.sub!(/^-+/, '')
|
23
|
+
if name =~ /\./
|
24
|
+
component_name, key = name.split('.').collect{|s| s.to_sym}
|
25
|
+
rad.config[component_name] ||= {}
|
26
|
+
rad.config[component_name][key] = value
|
27
|
+
else
|
28
|
+
rad.config[name.to_sym] = value
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# running
|
33
|
+
Rad::Cli::Helper.send "run_#{mode}"
|
@@ -0,0 +1 @@
|
|
1
|
+
backtrace_filters: []
|
@@ -1,3 +1,32 @@
|
|
1
1
|
available_languages:
|
2
2
|
- :en
|
3
|
-
language: :en
|
3
|
+
language: :en
|
4
|
+
|
5
|
+
backtrace_filters:
|
6
|
+
- /timeout.rb
|
7
|
+
- rubygems/custom_require
|
8
|
+
- /bin/spec
|
9
|
+
- /monitor
|
10
|
+
- /synchronize
|
11
|
+
- internal:lib/
|
12
|
+
|
13
|
+
- /gems/haml
|
14
|
+
- /gems/tilt
|
15
|
+
- /gems/rack
|
16
|
+
- /gems/rspec
|
17
|
+
- /gems/thin
|
18
|
+
- /gems/eventmachine
|
19
|
+
- /gems/mongoid
|
20
|
+
|
21
|
+
- lib/fake_gem
|
22
|
+
- /class_loader
|
23
|
+
- /micon
|
24
|
+
|
25
|
+
- /kit/
|
26
|
+
- /rad/
|
27
|
+
- /face/
|
28
|
+
|
29
|
+
# - /rad/template
|
30
|
+
# - /rad/_support
|
31
|
+
# - /face/view_builder
|
32
|
+
# - /face/view_helper
|
data/lib/components/http.yml
CHANGED
@@ -2,7 +2,18 @@ host: 'localhost'
|
|
2
2
|
port: 4000
|
3
3
|
static: true
|
4
4
|
url_root: '/'
|
5
|
-
default_format: 'html'
|
5
|
+
default_format: 'html'
|
6
|
+
|
7
|
+
# used in forgery protection and captcha
|
8
|
+
browser_generated_types:
|
9
|
+
- text/html
|
10
|
+
- text/plain
|
11
|
+
- text/javascript
|
12
|
+
- application/x-www-form-urlencoded
|
13
|
+
- multipart/form-data
|
14
|
+
browser_generated_formats:
|
15
|
+
- html
|
16
|
+
- js
|
6
17
|
|
7
18
|
# session sample
|
8
19
|
# session:
|
data/lib/components/web.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
rad.register :web, depends_on: [:html, :router, :controller, :http] do
|
2
|
-
require 'rad/
|
1
|
+
rad.register :web, depends_on: [:html, :router, :controller, :http, :configurators] do
|
2
|
+
require 'rad/web/_require'
|
3
3
|
|
4
4
|
load 'rad/profiles/web.rb'
|
5
5
|
load 'rad/profiles/mailer.rb'
|
File without changes
|
@@ -1,45 +1,14 @@
|
|
1
|
-
Exception.metaclass_eval do
|
2
|
-
attr_accessor :filters
|
3
|
-
end
|
4
|
-
|
5
|
-
Exception.filters = []
|
6
|
-
Exception.filters = %w(
|
7
|
-
/gems/haml
|
8
|
-
/gems/tilt
|
9
|
-
/gems/facets
|
10
|
-
/gems/rack
|
11
|
-
/gems/mongrel
|
12
|
-
/gems/rspec
|
13
|
-
/gems/thin
|
14
|
-
|
15
|
-
/timeout.rb
|
16
|
-
/bin/spec
|
17
|
-
|
18
|
-
lib/fake_gem
|
19
|
-
rubygems/custom_require
|
20
|
-
|
21
|
-
/rad/template
|
22
|
-
/rad/template
|
23
|
-
|
24
|
-
/face/view_builder
|
25
|
-
/face/view_helper
|
26
|
-
|
27
|
-
/rad/_support
|
28
|
-
|
29
|
-
/monitor
|
30
|
-
/synchronize
|
31
|
-
/class_loader
|
32
|
-
/micon
|
33
|
-
|
34
|
-
internal:lib/
|
35
|
-
)
|
36
|
-
|
37
|
-
# Uncomment this line to disable filtering
|
38
|
-
# Exception.filters = []
|
39
|
-
|
40
1
|
Exception.class_eval do
|
41
2
|
alias_method :set_backtrace_without_filter, :set_backtrace
|
42
3
|
def set_backtrace array
|
43
|
-
|
4
|
+
begin
|
5
|
+
if environment = rad.environment? && rad.environment
|
6
|
+
set_backtrace_without_filter array.sfilter(environment.backtrace_filters)
|
7
|
+
else
|
8
|
+
set_backtrace_without_filter array
|
9
|
+
end
|
10
|
+
rescue
|
11
|
+
set_backtrace_without_filter array
|
12
|
+
end
|
44
13
|
end
|
45
14
|
end
|
data/lib/rad/_support/string.rb
CHANGED
@@ -12,10 +12,16 @@ class String
|
|
12
12
|
gsub(/[&"><]/){|special| HTML_ESCAPE_MAP[special]}
|
13
13
|
end
|
14
14
|
|
15
|
-
def url_escape
|
15
|
+
def url_escape
|
16
|
+
# TODO2 change to Rack::Utils.escape
|
16
17
|
CGI.escape self
|
17
18
|
end
|
18
19
|
|
20
|
+
def url_unescape
|
21
|
+
# TODO2 change to Rack::Utils.unescape
|
22
|
+
CGI.unescape self
|
23
|
+
end
|
24
|
+
|
19
25
|
JS_ESCAPE_MAP = {
|
20
26
|
'\\' => '\\\\',
|
21
27
|
'</' => '<\/',
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Helper
|
2
|
+
RUNTIME_DIR = 'runtime'
|
3
|
+
|
4
|
+
class << self
|
5
|
+
inject logger: :logger
|
6
|
+
|
7
|
+
def run_console
|
8
|
+
prepare_running_environment
|
9
|
+
|
10
|
+
require 'irb'
|
11
|
+
IRB.start
|
12
|
+
end
|
13
|
+
|
14
|
+
def run_server
|
15
|
+
app = prepare_running_environment
|
16
|
+
|
17
|
+
rad.http.run app, rad.http.host, rad.http.port
|
18
|
+
end
|
19
|
+
|
20
|
+
def use_runtime_path!
|
21
|
+
runtime_path = "./#{RUNTIME_DIR}"
|
22
|
+
Dir.chdir runtime_path if Dir.exist? runtime_path
|
23
|
+
end
|
24
|
+
|
25
|
+
protected
|
26
|
+
def prepare_running_environment
|
27
|
+
use_runtime_path!
|
28
|
+
|
29
|
+
require 'rack'
|
30
|
+
app, options = Rack::Builder.parse_file 'config.ru'
|
31
|
+
app
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# %w(
|
2
|
+
# abstract
|
3
|
+
# runtime
|
4
|
+
# web
|
5
|
+
# ).each{|f| require "rad/configurators/#{f}"}
|
6
|
+
|
7
|
+
class Micon::Core
|
8
|
+
def configure configurator_name, dir, &block
|
9
|
+
configurator_class = "Rad::Configurators::#{configurator_name.to_s.classify}".constantize
|
10
|
+
configurator = configurator_class.new dir
|
11
|
+
block.call configurator if block
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
rad.configurators
|
2
|
+
|
3
|
+
class Abstract
|
4
|
+
def initialize dir
|
5
|
+
@dir = File.expand_path(dir)
|
6
|
+
end
|
7
|
+
|
8
|
+
# def config options = {}
|
9
|
+
# rad.config.merge_config! "#{dir}/config/config.yml", options
|
10
|
+
# end
|
11
|
+
|
12
|
+
def routes
|
13
|
+
routes_file = "#{dir}/config/routes.rb"
|
14
|
+
load routes_file if File.exist? routes_file
|
15
|
+
end
|
16
|
+
|
17
|
+
def locales
|
18
|
+
I18n.load_path += Dir["#{dir}/config/locales/**/*.{rb,yml}"]
|
19
|
+
I18n.load_path += Dir["#{dir}/config/locales/*.{rb,yml}"]
|
20
|
+
end
|
21
|
+
|
22
|
+
protected
|
23
|
+
attr_reader :dir #, :after_config, :after_environment
|
24
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
rad.configurators
|
2
|
+
|
3
|
+
class Web < Abstract
|
4
|
+
def asset_paths *relative_paths
|
5
|
+
relative_paths = relative_paths.first if relative_paths.first.is_a? Array
|
6
|
+
relative_paths.each do |relative_path|
|
7
|
+
path = "#{dir}/#{relative_path}"
|
8
|
+
rad.assets.paths << path unless rad.assets.paths.include? path
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def load_paths *relative_paths
|
13
|
+
relative_paths = relative_paths.first if relative_paths.first.is_a? Array
|
14
|
+
relative_paths.each do |relative_path|
|
15
|
+
path = "#{dir}/#{relative_path}"
|
16
|
+
$LOAD_PATH << path unless $LOAD_PATH.include? path
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def template_paths *relative_paths
|
21
|
+
rad.template
|
22
|
+
|
23
|
+
relative_paths = relative_paths.first if relative_paths.first.is_a? Array
|
24
|
+
relative_paths.each do |relative_path|
|
25
|
+
path = "#{dir}/#{relative_path}"
|
26
|
+
rad.template.paths << path unless rad.template.paths.include? path
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def autoload_paths *relative_paths
|
31
|
+
relative_paths = relative_paths.first if relative_paths.first.is_a? Array
|
32
|
+
relative_paths.each{|d| autoload_dir "#{dir}/#{d}", true}
|
33
|
+
end
|
34
|
+
end
|
@@ -13,46 +13,67 @@ module Rad::Controller::Abstract::Render
|
|
13
13
|
@_layout = layout
|
14
14
|
end
|
15
15
|
|
16
|
-
def render *args
|
17
|
-
options = rad.template.parse_arguments *args
|
18
|
-
|
16
|
+
def render *args
|
17
|
+
options = rad.template.parse_arguments *args
|
18
|
+
|
19
|
+
instance_variables = {
|
20
|
+
controller_name: self.class.controller_name
|
21
|
+
}
|
22
|
+
|
23
|
+
instance_variable_names.each do |name|
|
24
|
+
instance_variables[name[1..-1]] = instance_variable_get name unless name =~ /^@_/
|
25
|
+
end
|
26
|
+
|
27
|
+
instance_variables[:action_name] = options[:action] if options[:action]
|
28
|
+
|
29
|
+
context = self.class.context_class.new(instance_variables, self)
|
30
|
+
|
31
|
+
options.reverse_merge! \
|
32
|
+
context: context,
|
33
|
+
format: params.format,
|
34
|
+
exact_format: true,
|
35
|
+
relative_path_resolver: self.class
|
36
|
+
|
37
|
+
content = render_content options
|
38
|
+
content = render_layout content, options
|
39
|
+
|
19
40
|
throw :halt, content
|
20
41
|
end
|
21
42
|
|
22
43
|
protected
|
23
|
-
def
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
44
|
+
def render_content options
|
45
|
+
if special_format = SPECIAL_FORMAT_HANDLERS.keys.find{|f| options.include? f}
|
46
|
+
handler = SPECIAL_FORMAT_HANDLERS[special_format]
|
47
|
+
if special_format.to_s != params.format
|
48
|
+
raise "You trying responing with '#{special_format}' to the '#{params.format}' requested format!"
|
49
|
+
end
|
50
|
+
handler.call options[special_format]
|
51
|
+
elsif options.include? :inline
|
52
|
+
options[:inline]
|
53
|
+
elsif options[:template] == :nothing
|
54
|
+
''
|
55
|
+
else
|
56
|
+
if action = options.delete(:action)
|
57
|
+
options[:template].must_be.blank
|
58
|
+
options[:template] = action
|
59
|
+
|
60
|
+
options.reverse_merge! \
|
61
|
+
prefixes: [''],
|
62
|
+
if_not_exist: '/rad_default_templates/blank_template'
|
63
|
+
end
|
64
|
+
options[:template].must_be.present
|
65
|
+
options[:template] = options[:template].to_s
|
66
|
+
|
67
|
+
rad.template.render options
|
30
68
|
end
|
31
|
-
context = self.class.context_class.new(instance_variables, self)
|
32
|
-
|
33
|
-
options[:template] ||= options.delete(:action)
|
34
|
-
options[:template].must_be.present
|
35
|
-
options[:template] = options[:template].to_s
|
36
|
-
|
37
|
-
options.reverse_merge!(
|
38
|
-
context: context,
|
39
|
-
format: params.format,
|
40
|
-
exact_format: true,
|
41
|
-
prefixes: ['']
|
42
|
-
)
|
43
|
-
|
44
|
-
# rendering content
|
45
|
-
content, context = render_content options
|
46
|
-
|
47
|
-
# rendering layout
|
48
|
-
options[:content] = context
|
49
|
-
render_layout options, content
|
50
69
|
end
|
51
|
-
|
52
|
-
def render_layout
|
70
|
+
|
71
|
+
def render_layout content, options
|
53
72
|
layout = options.include?(:layout) ? options[:layout] : self._layout
|
54
|
-
|
55
|
-
|
73
|
+
|
74
|
+
if layout and rad.template.exist? layout, options
|
75
|
+
options = options.merge template: layout
|
76
|
+
rad.template.render options do |*args|
|
56
77
|
if args.empty?
|
57
78
|
content
|
58
79
|
else
|
@@ -66,26 +87,6 @@ module Rad::Controller::Abstract::Render
|
|
66
87
|
end
|
67
88
|
end
|
68
89
|
|
69
|
-
def render_content options
|
70
|
-
rad.template.basic_render options.merge(relative_path_resolver: self.class, if_not_exist: '/rad_default_templates/blank_template')
|
71
|
-
end
|
72
|
-
|
73
|
-
def render_with_parsed_arguments options, original_args
|
74
|
-
if special_format = SPECIAL_FORMAT_HANDLERS.keys.find{|f| options.include? f}
|
75
|
-
handler = SPECIAL_FORMAT_HANDLERS[special_format]
|
76
|
-
if special_format.to_s != params.format
|
77
|
-
raise "You trying responing with '#{special_format}' to the '#{params.format}' requested format!"
|
78
|
-
end
|
79
|
-
handler.call options[special_format]
|
80
|
-
elsif options.include? :inline
|
81
|
-
options[:inline]
|
82
|
-
elsif options[:template] == :nothing
|
83
|
-
''
|
84
|
-
else
|
85
|
-
render_action options
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
90
|
module ClassMethods
|
90
91
|
def layout layout, options = {}
|
91
92
|
before options do |controller|
|
@@ -1,16 +1,24 @@
|
|
1
1
|
module Rad::Controller::Abstract
|
2
|
+
inherit OpenConstructor
|
2
3
|
inherit Rad::Filters
|
3
|
-
inherit Rad::Controller::Abstract::Render, Rad::Controller::Abstract::
|
4
|
+
inherit Rad::Controller::Abstract::Render, Rad::Controller::Abstract::Miscellaneous
|
4
5
|
|
5
6
|
inject workspace: :workspace, logger: :logger
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
8
|
+
attr_accessor :action_name
|
9
|
+
attr_required :action_name
|
10
|
+
|
11
|
+
attr_writer :params
|
12
|
+
def params; @params ||= Rad::Conveyors::Params.new end
|
13
|
+
|
14
|
+
def call action, *args
|
15
|
+
catch :halt do
|
16
|
+
run_callbacks :action, method: action do
|
17
|
+
send action, *args
|
18
|
+
render action: action
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
14
22
|
|
15
23
|
module ClassMethods
|
16
24
|
inject workspace: :workspace, logger: :logger
|
@@ -1,15 +1,9 @@
|
|
1
1
|
class Rad::Controller::Context < Rad::Template::Context
|
2
|
-
attr_reader :controller
|
2
|
+
attr_reader :controller, :controller_name, :action_name
|
3
|
+
delegate :params, :request, :response, to: :controller
|
4
|
+
|
3
5
|
def initialize instance_variables, controller
|
4
6
|
super instance_variables
|
5
7
|
@controller = controller
|
6
8
|
end
|
7
|
-
|
8
|
-
def controller_name
|
9
|
-
@controller_name #workspace.controller.class.controller_name
|
10
|
-
end
|
11
|
-
|
12
|
-
def action_name
|
13
|
-
@action_name #workspace.action.to_sym
|
14
|
-
end
|
15
9
|
end
|
data/lib/rad/controller/_http.rb
CHANGED
@@ -1,22 +1,28 @@
|
|
1
1
|
module Rad::Controller::Http
|
2
2
|
inherit Rad::Controller::Abstract
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
def request; rad.workspace? ? workspace.request : nil end
|
5
|
+
def response; rad.workspace? ? workspace.response : nil end
|
6
|
+
|
7
|
+
def render *args
|
8
|
+
if args.size == 1 and (status = Rad::Http::Response.decode_status_message(args.first))
|
9
|
+
response.set! status: status
|
10
|
+
throw :halt, ""
|
11
|
+
else
|
12
|
+
super
|
13
|
+
end
|
14
|
+
end
|
7
15
|
|
8
16
|
protected
|
9
|
-
def
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
17
|
+
def render_content options
|
18
|
+
if response
|
19
|
+
response.set!(
|
20
|
+
status: options[:status] || :ok,
|
21
|
+
content_type: options[:content_type] || Mime[params.format]
|
22
|
+
)
|
23
|
+
end
|
15
24
|
|
16
|
-
if
|
17
|
-
response.set! status: status
|
18
|
-
throw :halt, ""
|
19
|
-
elsif options[:location]
|
25
|
+
if options[:location]
|
20
26
|
redirect_to options[:location]
|
21
27
|
else
|
22
28
|
super
|
@@ -36,11 +42,10 @@ module Rad::Controller::Http
|
|
36
42
|
private
|
37
43
|
def enable_protection_from_get_requests!
|
38
44
|
unless respond_to? :protect_from_get_request
|
39
|
-
define_method :protect_from_get_request do
|
40
|
-
request = workspace.request
|
45
|
+
define_method :protect_from_get_request do
|
41
46
|
get = !(request.post? or request.put? or request.delete?)
|
42
|
-
if get and !self.class.actions_allowed_for_get_request.include?(
|
43
|
-
raise "GET request not allowed for :#{
|
47
|
+
if get and !self.class.actions_allowed_for_get_request.include?(action_name)
|
48
|
+
raise "GET request not allowed for :#{action_name} action!"
|
44
49
|
end
|
45
50
|
end
|
46
51
|
before :protect_from_get_request
|
@@ -5,22 +5,14 @@ class ControllerCaller < Rad::Conveyors::Processor
|
|
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
|
9
|
-
|
10
|
-
action = workspace.action = workspace.method_name
|
8
|
+
raise "The controller class #{klass} must be a Rad::Controller::Abstract!" unless klass.is? Rad::Controller::Abstract
|
9
|
+
action_name = workspace.action_name = workspace.method_name
|
11
10
|
format = workspace.params.format
|
12
11
|
|
13
12
|
# call
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
# call controller
|
18
|
-
controller.send action
|
19
|
-
|
20
|
-
# render view
|
21
|
-
controller.render action: action
|
22
|
-
end
|
23
|
-
end
|
13
|
+
controller = workspace.controller = klass.new
|
14
|
+
controller.set! params: workspace.params, action_name: workspace.action_name
|
15
|
+
workspace.content = controller.call action_name
|
24
16
|
end
|
25
17
|
|
26
18
|
end
|
@@ -8,7 +8,7 @@ class ControllerErrorHandling < Rad::Conveyors::Processor
|
|
8
8
|
next_processor.call
|
9
9
|
rescue StandardError => e
|
10
10
|
if rad.test?
|
11
|
-
e.set_backtrace e.backtrace.sfilter(Exception.filters)
|
11
|
+
# e.set_backtrace e.backtrace.sfilter(Exception.filters)
|
12
12
|
raise e
|
13
13
|
elsif rad.production?
|
14
14
|
error_shown_to_user = StandardError.new "Internal error!"
|
@@ -17,7 +17,7 @@ class ControllerErrorHandling < Rad::Conveyors::Processor
|
|
17
17
|
error_shown_to_user = e
|
18
18
|
end
|
19
19
|
|
20
|
-
workspace.response.clear if workspace.response
|
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
|
@@ -13,19 +13,19 @@ class Rad::Logger
|
|
13
13
|
end
|
14
14
|
|
15
15
|
def info obj
|
16
|
-
write obj_to_string(obj)
|
16
|
+
write obj_to_string(obj)
|
17
17
|
end
|
18
18
|
|
19
19
|
def warn obj
|
20
|
-
write "WARN: " + obj_to_string(obj)
|
20
|
+
write "WARN: " + obj_to_string(obj)
|
21
21
|
end
|
22
22
|
|
23
23
|
def error obj
|
24
|
-
write "ERROR: " + obj_to_string(obj)
|
24
|
+
write "ERROR: " + obj_to_string(obj)
|
25
25
|
end
|
26
26
|
|
27
27
|
def debug obj
|
28
|
-
write obj_to_string(obj).gsub(/BSON::ObjectId\(([a-z0-9'"]+)\)/, "\\1")
|
28
|
+
write obj_to_string(obj).gsub(/BSON::ObjectId\(([a-z0-9'"]+)\)/, "\\1")
|
29
29
|
end
|
30
30
|
|
31
31
|
protected
|
@@ -45,7 +45,7 @@ class Rad::Logger
|
|
45
45
|
|
46
46
|
def obj_to_string obj
|
47
47
|
if obj.is_a? Exception
|
48
|
-
backtrace =
|
48
|
+
backtrace = obj.backtrace || []
|
49
49
|
%{\
|
50
50
|
#{obj.message}
|
51
51
|
#{backtrace.join("\n ")}
|