controll 0.2.0 → 0.3.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.
- data/README.md +253 -93
- data/Rakefile +1 -1
- data/VERSION +1 -1
- data/controll.gemspec +121 -84
- data/lib/controll/assistant/param_assistant.rb +23 -0
- data/lib/controll/assistant/session_assistant.rb +23 -0
- data/lib/controll/assistant.rb +9 -7
- data/lib/controll/commander.rb +16 -3
- data/lib/controll/enabler/macros.rb +75 -0
- data/lib/controll/enabler/maps.rb +15 -0
- data/lib/controll/enabler/notify.rb +43 -0
- data/lib/controll/enabler/path_handler.rb +49 -0
- data/lib/controll/enabler/path_resolver.rb +47 -0
- data/lib/controll/enabler.rb +49 -0
- data/lib/controll/engine.rb +9 -0
- data/lib/controll/errors.rb +4 -1
- data/lib/controll/event/helper.rb +20 -0
- data/lib/controll/{helper/event_matcher.rb → event/matcher.rb} +3 -3
- data/lib/controll/event.rb +60 -0
- data/lib/controll/events.rb +48 -0
- data/lib/controll/executor/base.rb +3 -7
- data/lib/controll/executor/controlled.rb +36 -0
- data/lib/controll/executor/delegator.rb +6 -0
- data/lib/controll/executor.rb +8 -1
- data/lib/controll/flow/action/base.rb +30 -0
- data/lib/controll/flow/action/fallback.rb +25 -0
- data/lib/controll/flow/action/path_action.rb +24 -0
- data/lib/controll/flow/action.rb +7 -0
- data/lib/controll/flow/action_mapper/base.rb +13 -0
- data/lib/controll/flow/action_mapper/complex.rb +52 -0
- data/lib/controll/flow/action_mapper/simple.rb +54 -0
- data/lib/controll/flow/action_mapper.rb +7 -0
- data/lib/controll/flow/errors.rb +16 -0
- data/lib/controll/flow/event_mapper/path_finder.rb +36 -0
- data/lib/controll/flow/event_mapper/util.rb +43 -0
- data/lib/controll/flow/event_mapper.rb +6 -0
- data/lib/controll/flow/master/executor.rb +57 -0
- data/lib/controll/flow/master/macros.rb +66 -0
- data/lib/controll/flow/master.rb +70 -0
- data/lib/controll/flow.rb +15 -0
- data/lib/controll/focused/enabler.rb +31 -0
- data/lib/controll/helper.rb +0 -94
- data/lib/controll/macros.rb +12 -0
- data/lib/controll/notify/base.rb +22 -43
- data/lib/controll/notify/flash.rb +3 -3
- data/lib/controll/notify/macros.rb +57 -0
- data/lib/controll/notify/message/handler.rb +36 -0
- data/lib/controll/notify/message/resolver.rb +28 -0
- data/lib/controll/notify/message/translator.rb +45 -0
- data/lib/controll/notify/message.rb +25 -0
- data/lib/controll/notify/typed.rb +13 -22
- data/lib/controll/notify.rb +11 -4
- data/lib/controll.rb +8 -2
- data/lib/generators/controll/assistant_generator.rb +27 -0
- data/lib/generators/controll/executor_generator.rb +23 -0
- data/lib/generators/controll/flow_handler_generator.rb +21 -0
- data/lib/generators/controll/notifier_generator.rb +21 -0
- data/lib/generators/controll/setup_generator.rb +37 -0
- data/lib/generators/controll/templates/assistant.tt +10 -0
- data/lib/generators/controll/templates/commander.tt +15 -0
- data/lib/generators/controll/templates/executor.tt +14 -0
- data/lib/generators/controll/templates/flow_handler.tt +26 -0
- data/lib/generators/controll/templates/notifier.tt +31 -0
- data/spec/acceptance/app_test.rb +1 -1
- data/spec/controll/assistant/param_assistant_spec.rb +31 -0
- data/spec/controll/assistant/session_assistant_spec.rb +31 -0
- data/spec/controll/assistant_spec.rb +26 -0
- data/spec/controll/command_spec.rb +4 -4
- data/spec/controll/enabler/macros_spec.rb +76 -0
- data/spec/controll/enabler/maps_spec.rb +31 -0
- data/spec/controll/{helper → enabler}/notify_spec.rb +7 -17
- data/spec/controll/enabler/path_handler_spec.rb +24 -0
- data/spec/controll/enabler/path_resolver_spec.rb +87 -0
- data/spec/controll/enabler_spec.rb +30 -0
- data/spec/controll/event/helper_spec.rb +33 -0
- data/spec/controll/{helper/event_matcher_spec.rb → event/matcher_spec.rb} +4 -3
- data/spec/controll/event_spec.rb +66 -0
- data/spec/controll/events_spec.rb +23 -0
- data/spec/controll/executor/controlled_spec.rb +36 -0
- data/spec/controll/executor/{notificator_spec.rb → delegator_spec.rb} +4 -4
- data/spec/controll/flow/action_mapper/complex_spec.rb +102 -0
- data/spec/controll/flow/action_mapper/fallback_spec.rb +34 -0
- data/spec/controll/{flow_handler/render_spec.rb → flow/action_mapper/simple_spec.rb} +25 -22
- data/spec/controll/{flow_handler/redirect/action_spec.rb → flow/event_mapper/path_finder_spec.rb} +10 -10
- data/spec/controll/{flow_handler/redirect/mapper_spec.rb → flow/event_mapper/util_spec.rb} +9 -9
- data/spec/controll/flow/master/executor_spec.rb +56 -0
- data/spec/{app/app/models/.gitkeep → controll/flow/master/macros_spec.rb} +0 -0
- data/spec/controll/flow/master_spec.rb +157 -0
- data/spec/controll/notify/base_spec.rb +6 -12
- data/spec/controll/notify/message/handler_spec.rb +27 -0
- data/spec/controll/notify/message/resolver_spec.rb +53 -0
- data/spec/controll/notify/message/translator_spec.rb +46 -0
- data/spec/controll/notify/message_spec.rb +4 -0
- data/spec/controll/notify/{message_handler.rb → services_notifier.rb} +3 -5
- data/spec/controll/notify/typed_spec.rb +2 -2
- data/spec/{app → controll_app}/.gitignore +0 -0
- data/spec/{app → controll_app}/Gemfile +0 -0
- data/spec/{app → controll_app}/Gemfile.lock +0 -0
- data/spec/{app → controll_app}/README.rdoc +0 -0
- data/spec/{app → controll_app}/Rakefile +0 -0
- data/spec/controll_app/app/controll/commanders/services_commander.rb +5 -0
- data/spec/controll_app/app/controll/executors/services_executor.rb +4 -0
- data/spec/controll_app/app/controll/flows/create_services.rb +9 -0
- data/spec/controll_app/app/controll/notifiers/services_notifier.rb +9 -0
- data/spec/{app → controll_app}/app/controllers/application_controller.rb +0 -1
- data/spec/controll_app/app/controllers/services_controller.rb +8 -0
- data/spec/{app/lib/assets → controll_app/app/models}/.gitkeep +0 -0
- data/spec/{app → controll_app}/app/models/post.rb +0 -0
- data/spec/{app → controll_app}/app/views/layouts/application.html.erb +0 -0
- data/spec/{app → controll_app}/app/views/posts/_form.html.erb +0 -0
- data/spec/{app → controll_app}/app/views/posts/edit.html.erb +0 -0
- data/spec/{app → controll_app}/app/views/posts/index.html.erb +0 -0
- data/spec/{app → controll_app}/app/views/posts/new.html.erb +0 -0
- data/spec/{app → controll_app}/app/views/posts/show.html.erb +0 -0
- data/spec/{app → controll_app}/config/application.rb +1 -1
- data/spec/{app → controll_app}/config/boot.rb +0 -0
- data/spec/{app → controll_app}/config/environment.rb +0 -0
- data/spec/{app → controll_app}/config/environments/development.rb +0 -0
- data/spec/{app → controll_app}/config/environments/test.rb +0 -0
- data/spec/{app → controll_app}/config/initializers/backtrace_silencers.rb +0 -0
- data/spec/{app → controll_app}/config/initializers/inflections.rb +0 -0
- data/spec/{app → controll_app}/config/initializers/mime_types.rb +0 -0
- data/spec/{app → controll_app}/config/initializers/secret_token.rb +0 -0
- data/spec/{app → controll_app}/config/initializers/session_store.rb +0 -0
- data/spec/{app → controll_app}/config/locales/en.yml +0 -0
- data/spec/controll_app/config/routes.rb +5 -0
- data/spec/{app → controll_app}/config.ru +0 -0
- data/spec/{app → controll_app}/db/seeds.rb +0 -0
- data/spec/{app/lib/tasks → controll_app/log}/.gitkeep +0 -0
- data/spec/{app → controll_app}/public/404.html +0 -0
- data/spec/{app → controll_app}/public/422.html +0 -0
- data/spec/{app → controll_app}/public/500.html +0 -0
- data/spec/{app → controll_app}/public/favicon.ico +0 -0
- data/spec/{app → controll_app}/public/index.html +0 -0
- data/spec/{app → controll_app}/public/javascripts/application.js +0 -0
- data/spec/{app → controll_app}/public/robots.txt +0 -0
- data/spec/{app → controll_app}/public/stylesheets/application.css +0 -0
- metadata +122 -85
- data/lib/controll/executor/notificator.rb +0 -12
- data/lib/controll/flow_handler/base.rb +0 -19
- data/lib/controll/flow_handler/control.rb +0 -85
- data/lib/controll/flow_handler/errors.rb +0 -5
- data/lib/controll/flow_handler/event_helper.rb +0 -18
- data/lib/controll/flow_handler/redirect/action.rb +0 -45
- data/lib/controll/flow_handler/redirect/mapper.rb +0 -41
- data/lib/controll/flow_handler/redirect.rb +0 -51
- data/lib/controll/flow_handler/render.rb +0 -51
- data/lib/controll/flow_handler.rb +0 -11
- data/lib/controll/helper/notify.rb +0 -74
- data/lib/controll/helper/path_resolver.rb +0 -45
- data/spec/app/app/controllers/posts_controller.rb +0 -52
- data/spec/app/config/routes.rb +0 -62
- data/spec/app/log/.gitkeep +0 -0
- data/spec/app/script/rails +0 -6
- data/spec/app/spec/controllers/posts_controller_spec.rb +0 -59
- data/spec/app/spec/isolated_spec_helper.rb +0 -6
- data/spec/app/spec/spec_helper.rb +0 -5
- data/spec/app/spec/unit/controllers/posts_controller_isolated_spec.rb +0 -63
- data/spec/app/spec/unit/controllers/posts_controller_spec.rb +0 -59
- data/spec/app/test/functional/.gitkeep +0 -0
- data/spec/app/test/functional/posts_controller_test.rb +0 -67
- data/spec/app/test/isolated_test_helper.rb +0 -7
- data/spec/app/test/test_helper.rb +0 -6
- data/spec/app/test/unit/.gitkeep +0 -0
- data/spec/app/test/unit/controllers/posts_controller_isolated_test.rb +0 -71
- data/spec/app/test/unit/controllers/posts_controller_test.rb +0 -67
- data/spec/app/vendor/assets/javascripts/.gitkeep +0 -0
- data/spec/app/vendor/assets/stylesheets/.gitkeep +0 -0
- data/spec/app/vendor/plugins/.gitkeep +0 -0
- data/spec/controll/asssistant_spec.rb +0 -5
- data/spec/controll/flow_handler/control_spec.rb +0 -159
- data/spec/controll/flow_handler/redirect_spec.rb +0 -93
- data/spec/controll/helper/path_resolver_spec.rb +0 -49
- data/spec/controll/helper_spec.rb +0 -108
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
module Controll::FlowHandler
|
|
2
|
-
class Base
|
|
3
|
-
attr_reader :path
|
|
4
|
-
|
|
5
|
-
def initialize path
|
|
6
|
-
@path = path.to_s
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
def perform controller
|
|
10
|
-
raise NotImplementedError, 'You must implement the #perform method'
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
class << self
|
|
14
|
-
def action event
|
|
15
|
-
raise NotImplementedError, 'You must implement the #action class method'
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
19
|
-
end
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
module Controll::FlowHandler
|
|
2
|
-
class Control
|
|
3
|
-
class ActionEventError < StandardError; end
|
|
4
|
-
|
|
5
|
-
attr_reader :controller, :action_handlers
|
|
6
|
-
|
|
7
|
-
def initialize controller, action_handlers = []
|
|
8
|
-
@controller = controller
|
|
9
|
-
@action_handlers = action_handlers unless action_handlers.blank?
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def execute
|
|
13
|
-
use_action_handlers
|
|
14
|
-
use_alternatives
|
|
15
|
-
use_fallback if !executed?
|
|
16
|
-
self
|
|
17
|
-
end
|
|
18
|
-
|
|
19
|
-
def action_handlers
|
|
20
|
-
@action_handlers ||= [:redirect, :render]
|
|
21
|
-
end
|
|
22
|
-
|
|
23
|
-
def executed?
|
|
24
|
-
@executed
|
|
25
|
-
end
|
|
26
|
-
|
|
27
|
-
protected
|
|
28
|
-
|
|
29
|
-
delegate :command!, to: :controller
|
|
30
|
-
|
|
31
|
-
# can be used to set up control logic that fall outside what can be done
|
|
32
|
-
# with the basic action_handlers but can not be considered fall-back.
|
|
33
|
-
def use_alternatives
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def use_fallback
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
def event
|
|
40
|
-
raise NotImplementedError, 'You must define an #event method that at least returns an event (Symbol). You can use an Executor for this.'
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def fallback_action
|
|
44
|
-
do_redirect root_url
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
NoEventsDefinedError = Controll::FlowHandler::Render::NoEventsDefinedError
|
|
48
|
-
NoRedirectionFoundError = Controll::FlowHandler::Redirect::NoRedirectionFoundError
|
|
49
|
-
|
|
50
|
-
def use_action_handlers
|
|
51
|
-
errors = []
|
|
52
|
-
action_handlers.each do |action_handler|
|
|
53
|
-
begin
|
|
54
|
-
action_handler_clazz = handler_class(action_handler)
|
|
55
|
-
next unless action_handler_clazz
|
|
56
|
-
action = action_handler_clazz.action(event)
|
|
57
|
-
execute_with action
|
|
58
|
-
return if executed?
|
|
59
|
-
rescue NoEventsDefinedError => e
|
|
60
|
-
errors << e
|
|
61
|
-
rescue NoRedirectionFoundError => e
|
|
62
|
-
errors << e
|
|
63
|
-
end
|
|
64
|
-
end
|
|
65
|
-
raise ActionEventError, "#{errors.join ','}" unless errors.empty?
|
|
66
|
-
end
|
|
67
|
-
|
|
68
|
-
def handler_class action_handler
|
|
69
|
-
clazz = "#{self.class}::#{action_handler.to_s.camelize}"
|
|
70
|
-
clazz.constantize
|
|
71
|
-
rescue NameError
|
|
72
|
-
nil
|
|
73
|
-
end
|
|
74
|
-
|
|
75
|
-
def execute_with action
|
|
76
|
-
return if !action
|
|
77
|
-
action.perform(controller)
|
|
78
|
-
executed!
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
def executed!
|
|
82
|
-
@executed = true
|
|
83
|
-
end
|
|
84
|
-
end
|
|
85
|
-
end
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
module Controll::FlowHandler
|
|
2
|
-
module EventHelper
|
|
3
|
-
def types
|
|
4
|
-
@types ||= [:notice, :error]
|
|
5
|
-
end
|
|
6
|
-
|
|
7
|
-
def normalize event
|
|
8
|
-
case event
|
|
9
|
-
when Symbol
|
|
10
|
-
Hashie::Mash.new name: event, type: :notice
|
|
11
|
-
when Hash, Hashie::Mash
|
|
12
|
-
event
|
|
13
|
-
else
|
|
14
|
-
raise Controll::InvalidEvent, "Event: #{event} could not be normalized, must be a Hash or Symbol"
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
end
|
|
18
|
-
end
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
module Controll::FlowHandler
|
|
2
|
-
class Redirect < Base
|
|
3
|
-
class Action
|
|
4
|
-
attr_accessor :event, :redirections, :types
|
|
5
|
-
|
|
6
|
-
# event is a Hashie::Mash or simply a Symbol (default notice event)
|
|
7
|
-
def initialize event, redirections, types = []
|
|
8
|
-
raise ArgumentError, "Must take :event option, was: #{event}" if event.blank?
|
|
9
|
-
raise ArgumentError, "Must take non-empty :redirections option, was: #{redirections}" if redirections.blank?
|
|
10
|
-
@event = normalize event
|
|
11
|
-
@types = types unless types.blank?
|
|
12
|
-
@redirections = redirections
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
def map
|
|
16
|
-
if redirect.blank?
|
|
17
|
-
raise Controll::FlowHandler::NoRedirectionFoundError, "No redirection could be found for: #{event} in: #{redirections}"
|
|
18
|
-
end
|
|
19
|
-
redirect
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
protected
|
|
23
|
-
|
|
24
|
-
include Controll::FlowHandler::EventHelper
|
|
25
|
-
|
|
26
|
-
def redirect
|
|
27
|
-
@redirect ||= mapper(redirect_map).map
|
|
28
|
-
rescue StandardError => e
|
|
29
|
-
raise Controll::FlowHandler::NoRedirectionFoundError, "No redirection could be found for: #{event} in: #{redirections}. Cause: #{e}"
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def redirect_map
|
|
33
|
-
@redirect_map ||= redirections[event.type] || {}
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def mapper redirect_map
|
|
37
|
-
@mapper ||= mapper_class.new event, redirect_map
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def mapper_class
|
|
41
|
-
Controll::FlowHandler::Redirect::Mapper
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
module Controll::FlowHandler
|
|
2
|
-
class Redirect < Base
|
|
3
|
-
class Mapper
|
|
4
|
-
attr_reader :redirect_map, :event
|
|
5
|
-
|
|
6
|
-
def initialize event, redirect_map
|
|
7
|
-
@event ||= normalize event
|
|
8
|
-
|
|
9
|
-
unless valid_map? redirect_map
|
|
10
|
-
raise ArgumentError, "Invalid redirect map: #{redirect_map}, must be a Hash"
|
|
11
|
-
end
|
|
12
|
-
@redirect_map ||= redirect_map
|
|
13
|
-
end
|
|
14
|
-
|
|
15
|
-
# An events can also be a Symbol,
|
|
16
|
-
# in which case it is a :notice event
|
|
17
|
-
def map
|
|
18
|
-
redirect_map.each do |path, events|
|
|
19
|
-
return path.to_s if valid? events
|
|
20
|
-
end
|
|
21
|
-
raise Controll::FlowHandler::NoRedirectionFoundError, "No path could be found for event: #{event} in map: #{redirect_map}"
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
protected
|
|
25
|
-
|
|
26
|
-
include Controll::FlowHandler::EventHelper
|
|
27
|
-
|
|
28
|
-
def valid_map? redirect_map
|
|
29
|
-
redirect_map.kind_of?(Hash) && !redirect_map.blank?
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
def valid? events
|
|
33
|
-
matcher(event).match?(events)
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def matcher event
|
|
37
|
-
@matcher ||= Controll::Helper::EventMatcher.new event
|
|
38
|
-
end
|
|
39
|
-
end
|
|
40
|
-
end
|
|
41
|
-
end
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
require 'controll/flow_handler/base'
|
|
2
|
-
|
|
3
|
-
module Controll::FlowHandler
|
|
4
|
-
class Redirect < Base
|
|
5
|
-
autoload :Action, 'controll/flow_handler/redirect/action'
|
|
6
|
-
autoload :Mapper, 'controll/flow_handler/redirect/mapper'
|
|
7
|
-
|
|
8
|
-
def initialize path
|
|
9
|
-
super path
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def perform controller
|
|
13
|
-
controller.do_redirect controller.send(path)
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
class << self
|
|
17
|
-
attr_accessor :redirections
|
|
18
|
-
attr_writer :redirect_maps, :action_clazz
|
|
19
|
-
|
|
20
|
-
def action event
|
|
21
|
-
path = action_clazz.new(event, redirections, types).map
|
|
22
|
-
self.new path unless path.blank?
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def types
|
|
26
|
-
@types ||= [:notice, :error]
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
def redirections_for type = :notice
|
|
30
|
-
@redirections ||= {}
|
|
31
|
-
@redirections[type.to_sym] || {}
|
|
32
|
-
end
|
|
33
|
-
|
|
34
|
-
def set_redirections *args
|
|
35
|
-
type = args.first.kind_of?(Symbol) ? args.shift : :notice
|
|
36
|
-
@redirections ||= {}
|
|
37
|
-
@redirections[type.to_sym] = args.first
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def set_types *names
|
|
41
|
-
@redirect_maps ||= names.flatten
|
|
42
|
-
end
|
|
43
|
-
|
|
44
|
-
protected
|
|
45
|
-
|
|
46
|
-
def action_clazz
|
|
47
|
-
@action_clazz ||= Controll::FlowHandler::Redirect::Action
|
|
48
|
-
end
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
end
|
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
require 'controll/flow_handler/base'
|
|
2
|
-
|
|
3
|
-
module Controll::FlowHandler
|
|
4
|
-
class Render < Base
|
|
5
|
-
class NoEventsDefinedError < StandardError; end
|
|
6
|
-
class BadPathError < StandardError; end
|
|
7
|
-
|
|
8
|
-
def initialize path #, events = []
|
|
9
|
-
super path
|
|
10
|
-
# @events = events
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
def perform controller
|
|
14
|
-
raise BadPathError, "Bad path: #{path}" if path.blank?
|
|
15
|
-
controller.render controller.send(path)
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
class << self
|
|
19
|
-
def action event, path = nil
|
|
20
|
-
raise Controll::FlowHandler::NoEventsDefinedError, "You must define a #{self}#events class method that returns a render map" unless respond_to?(:events)
|
|
21
|
-
raise Controll::FlowHandler::NoEventsDefinedError, "The #{self}#events class method must return a render map, was #{events}" if events.blank?
|
|
22
|
-
event = normalize event
|
|
23
|
-
self.new(path || default_path) if events.include? event.name
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
def default_path
|
|
27
|
-
raise NotImplementedError, "You must set a default_path or override the #{self}#action class method"
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
# http://bugs.ruby-lang.org/issues/1082
|
|
31
|
-
# hello.singleton_class
|
|
32
|
-
# Instead of always having to write:
|
|
33
|
-
# (class << hello; self; end)
|
|
34
|
-
def set_default_path str = nil, &block
|
|
35
|
-
(class << self; self; end).send :define_method, :default_path do
|
|
36
|
-
block_given? ? yield : str
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def set_events *args, &block
|
|
41
|
-
(class << self; self; end).send :define_method, :events do
|
|
42
|
-
block_given? ? yield : args.flatten
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
protected
|
|
47
|
-
|
|
48
|
-
include Controll::FlowHandler::EventHelper
|
|
49
|
-
end
|
|
50
|
-
end
|
|
51
|
-
end
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
require 'controll/flow_handler/errors'
|
|
2
|
-
|
|
3
|
-
module Controll
|
|
4
|
-
module FlowHandler
|
|
5
|
-
autoload :Base, 'controll/flow_handler/base'
|
|
6
|
-
autoload :Control, 'controll/flow_handler/control'
|
|
7
|
-
autoload :Redirect, 'controll/flow_handler/redirect'
|
|
8
|
-
autoload :Render, 'controll/flow_handler/render'
|
|
9
|
-
autoload :EventHelper, 'controll/flow_handler/event_helper'
|
|
10
|
-
end
|
|
11
|
-
end
|
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
module Controll
|
|
2
|
-
module Helper
|
|
3
|
-
module Notify
|
|
4
|
-
extend ActiveSupport::Concern
|
|
5
|
-
|
|
6
|
-
included do
|
|
7
|
-
attr_writer :notification_types
|
|
8
|
-
|
|
9
|
-
notification_types.each do |type|
|
|
10
|
-
define_method "create_#{type}" do |*args|
|
|
11
|
-
create_notification args.first, type.to_sym, args.extract_options!
|
|
12
|
-
end
|
|
13
|
-
end
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
# msg stack
|
|
17
|
-
def notifications
|
|
18
|
-
@notifications ||= []
|
|
19
|
-
end
|
|
20
|
-
|
|
21
|
-
def main_event
|
|
22
|
-
notifications.last || create_notice(:success)
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
def notify name, type = nil, options = {}
|
|
26
|
-
notifications << create_notification(name, type, options)
|
|
27
|
-
self # enable method chaining on controller
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
protected
|
|
31
|
-
|
|
32
|
-
def error name = :error, options = {}
|
|
33
|
-
notify name, :error, options
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def success name = :success, options = {}
|
|
37
|
-
notify name, :success, options
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def create_notification name, type = nil, options = {}
|
|
41
|
-
type ||= :notice
|
|
42
|
-
raise ArgumentError, "Not a valid notification type: #{type}, must be one of: #{valid_notification_types}" unless valid_notification_type?(type)
|
|
43
|
-
Hashie::Mash.new(name: name, type: type, options: options)
|
|
44
|
-
end
|
|
45
|
-
alias_method :create_event, :create_notification
|
|
46
|
-
|
|
47
|
-
def valid_notification_type? type
|
|
48
|
-
notification_types.include? type.to_sym
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def notification_types
|
|
52
|
-
return self.class.notification_types if self.class.respond_to? :notification_types
|
|
53
|
-
Controll::Notify::Flash.types
|
|
54
|
-
end
|
|
55
|
-
|
|
56
|
-
# allows customization of notification types
|
|
57
|
-
module ClassMethods
|
|
58
|
-
def notification_types
|
|
59
|
-
@notification_types ||= default_notification_types
|
|
60
|
-
end
|
|
61
|
-
|
|
62
|
-
def default_notification_types
|
|
63
|
-
Controll::Notify::Flash.types
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
def process_notifications
|
|
68
|
-
notifications.each do |message|
|
|
69
|
-
message_handler.send(message.type).notify message.name, message.options
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
end
|
|
73
|
-
end
|
|
74
|
-
end
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
module Controll
|
|
2
|
-
module Helper
|
|
3
|
-
class PathResolver
|
|
4
|
-
class PathResolverError < StandardError; end
|
|
5
|
-
|
|
6
|
-
attr_reader :caller
|
|
7
|
-
|
|
8
|
-
def initialize caller
|
|
9
|
-
@caller = caller
|
|
10
|
-
end
|
|
11
|
-
|
|
12
|
-
def extract_path type, *args
|
|
13
|
-
if args.first.kind_of?(Symbol)
|
|
14
|
-
raise "Caller must have a notice method" unless caller.respond_to? :notice
|
|
15
|
-
caller.notice args.first
|
|
16
|
-
resolve_path type
|
|
17
|
-
else
|
|
18
|
-
args.empty? ? resolve_path(type) : args.first
|
|
19
|
-
end
|
|
20
|
-
end
|
|
21
|
-
|
|
22
|
-
def resolve_path type
|
|
23
|
-
raise "Caller must have a #main_event method" unless caller.respond_to? :main_event
|
|
24
|
-
caller.send(type).each do |path, events|
|
|
25
|
-
return path.to_s if matches? events
|
|
26
|
-
end
|
|
27
|
-
raise PathResolverError, "Path could not be resolved for: #{event_name}"
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
protected
|
|
31
|
-
|
|
32
|
-
def matches? events
|
|
33
|
-
event_matcher.match?(events)
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
def event_matcher
|
|
37
|
-
@event_matcher ||= EventMatcher.new event
|
|
38
|
-
end
|
|
39
|
-
|
|
40
|
-
def event
|
|
41
|
-
@event ||= caller.main_event
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
end
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
module PostsController
|
|
2
|
-
class Action < ApplicationController
|
|
3
|
-
end
|
|
4
|
-
|
|
5
|
-
class Index < Action
|
|
6
|
-
expose(:posts) { Post.all }
|
|
7
|
-
end
|
|
8
|
-
|
|
9
|
-
class Initializer < Action
|
|
10
|
-
expose(:post) { Post.new params[:post] }
|
|
11
|
-
end
|
|
12
|
-
|
|
13
|
-
class New < Initializer
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
class Create < Initializer
|
|
17
|
-
def run
|
|
18
|
-
if post.save
|
|
19
|
-
redirect_to post, :notice => 'Post was successfully created.'
|
|
20
|
-
else
|
|
21
|
-
render :action => "new"
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
end
|
|
25
|
-
|
|
26
|
-
class Finder < Action
|
|
27
|
-
expose(:post) { Post.find params[:id] }
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
class Show < Finder
|
|
31
|
-
end
|
|
32
|
-
|
|
33
|
-
class Edit < Finder
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
class Update < Finder
|
|
37
|
-
def run
|
|
38
|
-
if post.update_attributes(params[:post])
|
|
39
|
-
redirect_to post, :notice => 'Post was successfully updated.'
|
|
40
|
-
else
|
|
41
|
-
render :action => "edit"
|
|
42
|
-
end
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
class Destroy < Finder
|
|
47
|
-
def run
|
|
48
|
-
post.destroy
|
|
49
|
-
redirect_to posts_url
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
end
|
data/spec/app/config/routes.rb
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
App::Application.routes.draw do
|
|
2
|
-
focused_controller_routes do
|
|
3
|
-
resources :posts
|
|
4
|
-
end
|
|
5
|
-
|
|
6
|
-
# The priority is based upon order of creation:
|
|
7
|
-
# first created -> highest priority.
|
|
8
|
-
|
|
9
|
-
# Sample of regular route:
|
|
10
|
-
# match 'products/:id' => 'catalog#view'
|
|
11
|
-
# Keep in mind you can assign values other than :controller and :action
|
|
12
|
-
|
|
13
|
-
# Sample of named route:
|
|
14
|
-
# match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
|
|
15
|
-
# This route can be invoked with purchase_url(:id => product.id)
|
|
16
|
-
|
|
17
|
-
# Sample resource route (maps HTTP verbs to controller actions automatically):
|
|
18
|
-
# resources :products
|
|
19
|
-
|
|
20
|
-
# Sample resource route with options:
|
|
21
|
-
# resources :products do
|
|
22
|
-
# member do
|
|
23
|
-
# get 'short'
|
|
24
|
-
# post 'toggle'
|
|
25
|
-
# end
|
|
26
|
-
#
|
|
27
|
-
# collection do
|
|
28
|
-
# get 'sold'
|
|
29
|
-
# end
|
|
30
|
-
# end
|
|
31
|
-
|
|
32
|
-
# Sample resource route with sub-resources:
|
|
33
|
-
# resources :products do
|
|
34
|
-
# resources :comments, :sales
|
|
35
|
-
# resource :seller
|
|
36
|
-
# end
|
|
37
|
-
|
|
38
|
-
# Sample resource route with more complex sub-resources
|
|
39
|
-
# resources :products do
|
|
40
|
-
# resources :comments
|
|
41
|
-
# resources :sales do
|
|
42
|
-
# get 'recent', :on => :collection
|
|
43
|
-
# end
|
|
44
|
-
# end
|
|
45
|
-
|
|
46
|
-
# Sample resource route within a namespace:
|
|
47
|
-
# namespace :admin do
|
|
48
|
-
# # Directs /admin/products/* to Admin::ProductsController
|
|
49
|
-
# # (app/controllers/admin/products_controller.rb)
|
|
50
|
-
# resources :products
|
|
51
|
-
# end
|
|
52
|
-
|
|
53
|
-
# You can have the root of your site routed with "root"
|
|
54
|
-
# just remember to delete public/index.html.
|
|
55
|
-
# root :to => 'welcome#index'
|
|
56
|
-
|
|
57
|
-
# See how all your routes lay out with "rake routes"
|
|
58
|
-
|
|
59
|
-
# This is a legacy wild controller route that's not recommended for RESTful applications.
|
|
60
|
-
# Note: This route will make all actions in every controller accessible via GET requests.
|
|
61
|
-
# match ':controller(/:action(/:id))(.:format)'
|
|
62
|
-
end
|
data/spec/app/log/.gitkeep
DELETED
|
File without changes
|
data/spec/app/script/rails
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env ruby
|
|
2
|
-
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
|
|
3
|
-
|
|
4
|
-
APP_PATH = File.expand_path('../../config/application', __FILE__)
|
|
5
|
-
require File.expand_path('../../config/boot', __FILE__)
|
|
6
|
-
require 'rails/commands'
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
describe PostsController do
|
|
4
|
-
include FocusedController::RSpecFunctionalHelper
|
|
5
|
-
|
|
6
|
-
before do
|
|
7
|
-
@post = Post.create(:title => 'Hello', :body => 'Omg')
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
describe PostsController::Index do
|
|
11
|
-
it "should get index" do
|
|
12
|
-
get
|
|
13
|
-
response.should be_success
|
|
14
|
-
subject.posts.should_not be_nil
|
|
15
|
-
end
|
|
16
|
-
end
|
|
17
|
-
|
|
18
|
-
describe PostsController::New do
|
|
19
|
-
it "should get new" do
|
|
20
|
-
get
|
|
21
|
-
response.should be_success
|
|
22
|
-
end
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
describe PostsController::Create do
|
|
26
|
-
it "should create post" do
|
|
27
|
-
expect { post :post => @post.attributes }.to change(Post, :count).by(1)
|
|
28
|
-
response.should redirect_to(post_path(subject.post))
|
|
29
|
-
end
|
|
30
|
-
end
|
|
31
|
-
|
|
32
|
-
describe PostsController::Show do
|
|
33
|
-
it "should show post" do
|
|
34
|
-
get :id => @post.id
|
|
35
|
-
response.should be_success
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
|
|
39
|
-
describe PostsController::Edit do
|
|
40
|
-
it "should get edit" do
|
|
41
|
-
get :id => @post.id
|
|
42
|
-
response.should be_success
|
|
43
|
-
end
|
|
44
|
-
end
|
|
45
|
-
|
|
46
|
-
describe PostsController::Update do
|
|
47
|
-
it "should update post" do
|
|
48
|
-
put :id => @post.id, :post => @post.attributes
|
|
49
|
-
response.should redirect_to(post_path(subject.post))
|
|
50
|
-
end
|
|
51
|
-
end
|
|
52
|
-
|
|
53
|
-
describe PostsController::Destroy do
|
|
54
|
-
it "should destroy post" do
|
|
55
|
-
expect { delete :id => @post.id }.to change(Post, :count).by(-1)
|
|
56
|
-
response.should redirect_to(posts_path)
|
|
57
|
-
end
|
|
58
|
-
end
|
|
59
|
-
end
|