rad_core 0.2.6 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- 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,166 +0,0 @@
|
|
1
|
-
module Rad::Callbacks
|
2
|
-
class AbstractCallback
|
3
|
-
attr_accessor :executor, :terminator
|
4
|
-
attr_reader :conditions
|
5
|
-
def conditions= conditions
|
6
|
-
@conditions = {}
|
7
|
-
conditions.each do |k, v|
|
8
|
-
@conditions[k.to_sym] = if v.is_a? Symbol
|
9
|
-
v.to_s
|
10
|
-
elsif v.is_a? Array
|
11
|
-
v.collect{|e| e.to_s}
|
12
|
-
else
|
13
|
-
v
|
14
|
-
end
|
15
|
-
end
|
16
|
-
@conditions
|
17
|
-
end
|
18
|
-
|
19
|
-
def terminate? target, result
|
20
|
-
unless terminator.nil?
|
21
|
-
if terminator.is_a? Proc
|
22
|
-
terminator.call target, result
|
23
|
-
else
|
24
|
-
result == terminator
|
25
|
-
end
|
26
|
-
else
|
27
|
-
false
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def run? target, inf
|
32
|
-
if cond = conditions[:if]
|
33
|
-
evaluate_if(cond, target, inf)
|
34
|
-
elsif cond = conditions[:unless]
|
35
|
-
!evaluate_if(cond, target, inf)
|
36
|
-
elsif cond = conditions[:only]
|
37
|
-
evaluate_only(cond, inf)
|
38
|
-
elsif cond = conditions[:except]
|
39
|
-
!evaluate_only(cond, inf)
|
40
|
-
else
|
41
|
-
true
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def add_to_chain target, inf, &the_next
|
46
|
-
if run? target, inf
|
47
|
-
build_block target, &the_next
|
48
|
-
else
|
49
|
-
the_next
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
alias_method :deep_clone, :clone
|
54
|
-
|
55
|
-
protected
|
56
|
-
def evaluate_if cond, target, inf
|
57
|
-
if cond.is_a? String
|
58
|
-
target.send cond
|
59
|
-
elsif cond.is_a? Proc
|
60
|
-
cond.call target, inf
|
61
|
-
else
|
62
|
-
must_be.never_called
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
def evaluate_only cond, inf
|
67
|
-
method = inf[:method].to_s
|
68
|
-
if cond.is_a? String
|
69
|
-
cond == method
|
70
|
-
elsif cond.is_a? Array
|
71
|
-
cond.include? method
|
72
|
-
end
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
class BeforeCallback < AbstractCallback
|
77
|
-
def build_block target, &the_next
|
78
|
-
lambda do
|
79
|
-
result = if executor.string_or_symbol?
|
80
|
-
target.send executor
|
81
|
-
elsif executor.is_a? Proc
|
82
|
-
executor.call target
|
83
|
-
else
|
84
|
-
must_be.never_called
|
85
|
-
end
|
86
|
-
|
87
|
-
the_next.call unless terminate? target, result
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
class AroundCallback < AbstractCallback
|
93
|
-
def build_block target, &the_next
|
94
|
-
lambda do
|
95
|
-
if executor.string_or_symbol?
|
96
|
-
target.send executor, &the_next
|
97
|
-
elsif executor.is_a? Proc
|
98
|
-
executor.call target, the_next
|
99
|
-
else
|
100
|
-
must_be.never_called
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
|
106
|
-
class AfterCallback < AbstractCallback
|
107
|
-
def build_block target, &the_next
|
108
|
-
lambda do
|
109
|
-
result = if executor.string_or_symbol?
|
110
|
-
target.send executor
|
111
|
-
elsif executor.is_a? Proc
|
112
|
-
executor.call target
|
113
|
-
else
|
114
|
-
must_be.never_called
|
115
|
-
end
|
116
|
-
|
117
|
-
the_next.call unless terminate? target, result
|
118
|
-
end
|
119
|
-
end
|
120
|
-
end
|
121
|
-
|
122
|
-
def run_callbacks callback_name, additional_information = {}, &block
|
123
|
-
callback_name = callback_name.to_s
|
124
|
-
block.must_be.defined
|
125
|
-
|
126
|
-
callbacks = self.class.callbacks[callback_name]
|
127
|
-
chain_head = block
|
128
|
-
if callbacks and !callbacks.empty?
|
129
|
-
callbacks.reverse_each do |callback|
|
130
|
-
block = callback.add_to_chain self, additional_information, &chain_head
|
131
|
-
chain_head = block if block
|
132
|
-
end
|
133
|
-
end
|
134
|
-
chain_head.call
|
135
|
-
end
|
136
|
-
|
137
|
-
module ClassMethods
|
138
|
-
inheritable_accessor :callbacks, {}
|
139
|
-
|
140
|
-
def set_callback callback_name, type, *executor_or_options, &block
|
141
|
-
# parsing arguments
|
142
|
-
type, callback_name = type.to_s, callback_name.to_s
|
143
|
-
opt = executor_or_options.extract_options!
|
144
|
-
"You can't provide both method name and block for filter!" if block and !executor_or_options.empty?
|
145
|
-
executor = block || executor_or_options.first
|
146
|
-
|
147
|
-
type.must_be.in %w{before around after}
|
148
|
-
executor.must_be.defined
|
149
|
-
|
150
|
-
# creating callback
|
151
|
-
callback = case type
|
152
|
-
when 'before' then BeforeCallback.new
|
153
|
-
when 'around' then AroundCallback.new
|
154
|
-
when 'after' then AfterCallback.new
|
155
|
-
end
|
156
|
-
|
157
|
-
callback.executor = executor
|
158
|
-
callback.terminator = opt.delete :terminator
|
159
|
-
callback.conditions = opt
|
160
|
-
|
161
|
-
callbacks[callback_name] ||= []
|
162
|
-
callbacks[callback_name] << callback
|
163
|
-
end
|
164
|
-
|
165
|
-
end
|
166
|
-
end
|
@@ -1,157 +0,0 @@
|
|
1
|
-
require 'support/spec_helper'
|
2
|
-
|
3
|
-
require "rad/_support/callbacks"
|
4
|
-
|
5
|
-
describe "Callbacks" do
|
6
|
-
before :all do
|
7
|
-
class BasicCallbacksSpec
|
8
|
-
inherit Rad::Callbacks
|
9
|
-
|
10
|
-
set_callback :callback_name, :before, :before_callback
|
11
|
-
set_callback :callback_name, :after, :after_callback
|
12
|
-
set_callback :callback_name, :around, :around_callback
|
13
|
-
|
14
|
-
protected
|
15
|
-
def around_callback
|
16
|
-
around_callback_called
|
17
|
-
yield
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
it "basic" do
|
23
|
-
o = BasicCallbacksSpec.new
|
24
|
-
o.should_receive :before_callback
|
25
|
-
o.should_receive :around_callback_called
|
26
|
-
o.should_receive :after_callback
|
27
|
-
o.run_callbacks(:callback_name){"result"}.should == "result"
|
28
|
-
end
|
29
|
-
|
30
|
-
it "blocks" do
|
31
|
-
class BlockCallbacksSpec
|
32
|
-
inherit Rad::Callbacks
|
33
|
-
|
34
|
-
set_callback(:callback_name, :before){|controller| controller.result << :before}
|
35
|
-
set_callback :callback_name, :around do |controller, block|
|
36
|
-
begin
|
37
|
-
controller.result << :around_begin
|
38
|
-
block.call
|
39
|
-
ensure
|
40
|
-
controller.result << :around_end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
set_callback(:callback_name, :after){|controller| controller.result << :after}
|
44
|
-
|
45
|
-
def result
|
46
|
-
@result ||= []
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
o = BlockCallbacksSpec.new
|
51
|
-
o.run_callbacks(:callback_name){"result"}.should == "result"
|
52
|
-
o.result.should == [:before, :around_begin, :after, :around_end]
|
53
|
-
end
|
54
|
-
|
55
|
-
it "inheritance" do
|
56
|
-
class InheritedCallbacksSpec < BasicCallbacksSpec
|
57
|
-
set_callback :callback_name, :before, :before_callback2
|
58
|
-
end
|
59
|
-
|
60
|
-
o = InheritedCallbacksSpec.new
|
61
|
-
o.should_receive :before_callback
|
62
|
-
o.should_receive :before_callback2
|
63
|
-
o.should_receive :around_callback_called
|
64
|
-
o.should_receive :after_callback
|
65
|
-
o.run_callbacks(:callback_name){"result"}.should == "result"
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'terminator' do
|
69
|
-
class CallbackTerminatorSpec
|
70
|
-
inherit Rad::Callbacks
|
71
|
-
|
72
|
-
set_callback :callback_name, :before, :before_callback, terminator: false
|
73
|
-
set_callback :callback_name, :before, :before_callback2
|
74
|
-
|
75
|
-
def method
|
76
|
-
run_callbacks :callback_name do
|
77
|
-
"result"
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
protected
|
82
|
-
def before_callback
|
83
|
-
false
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
o = CallbackTerminatorSpec.new
|
88
|
-
o.should_not_receive :before_callback2
|
89
|
-
o.run_callbacks(:callback_name){"result"}.should_not == "result"
|
90
|
-
end
|
91
|
-
|
92
|
-
it 'conditions' do
|
93
|
-
class CallbackConditionsSpec
|
94
|
-
inherit Rad::Callbacks
|
95
|
-
|
96
|
-
set_callback :callback_name, :before, :before_callback, only: :another_method
|
97
|
-
end
|
98
|
-
|
99
|
-
o = CallbackConditionsSpec.new
|
100
|
-
o.should_not_receive :before_callback
|
101
|
-
o.run_callbacks(:callback_name, method: :method){"result"}.should == 'result'
|
102
|
-
|
103
|
-
o = CallbackConditionsSpec.new
|
104
|
-
o.should_receive :before_callback
|
105
|
-
o.run_callbacks(:callback_name, method: :another_method){"result"}.should == 'result'
|
106
|
-
end
|
107
|
-
|
108
|
-
it "if, unless conditions" do
|
109
|
-
c = Rad::Callbacks::AbstractCallback.new
|
110
|
-
c.conditions = {if: lambda{|target, inf| true}}
|
111
|
-
c.run?(nil, {}).should be_true
|
112
|
-
|
113
|
-
c.conditions = {if: lambda{|target, inf| false}}
|
114
|
-
c.run?(nil, {}).should be_false
|
115
|
-
|
116
|
-
c.conditions = {unless: lambda{|target, inf| true}}
|
117
|
-
c.run?(nil, {}).should be_false
|
118
|
-
|
119
|
-
c.conditions = {unless: lambda{|target, inf| false}}
|
120
|
-
c.run?(nil, {}).should be_true
|
121
|
-
end
|
122
|
-
|
123
|
-
it "only, except conditions" do
|
124
|
-
c = Rad::Callbacks::AbstractCallback.new
|
125
|
-
c.conditions = {only: :a}
|
126
|
-
c.run?(nil, {method: :a}).should be_true
|
127
|
-
|
128
|
-
c.conditions = {only: :b}
|
129
|
-
c.run?(nil, {method: :a}).should be_false
|
130
|
-
|
131
|
-
c.conditions = {except: :a}
|
132
|
-
c.run?(nil, {method: :a}).should be_false
|
133
|
-
|
134
|
-
c.conditions = {except: :b}
|
135
|
-
c.run?(nil, {method: :a}).should be_true
|
136
|
-
|
137
|
-
c.conditions = {only: :a}
|
138
|
-
c.run?(nil, {method: :a}).should be_true
|
139
|
-
end
|
140
|
-
|
141
|
-
|
142
|
-
it "around callback should be able to change result value" do
|
143
|
-
class ChangeResultValueSpec
|
144
|
-
inherit Rad::Callbacks
|
145
|
-
|
146
|
-
set_callback :callback_name, :around, :around_callback
|
147
|
-
|
148
|
-
def around_callback
|
149
|
-
yield
|
150
|
-
'another result'
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
o = ChangeResultValueSpec.new
|
155
|
-
o.run_callbacks(:callback_name){"result"}.should == 'another result'
|
156
|
-
end
|
157
|
-
end
|