Permalink
Browse files

split into actions and action_mappers

  • Loading branch information...
1 parent 08347f0 commit 4281db0943e64ca1a076b4a4e3b57579437e3904 @kristianmandrup committed Aug 22, 2012
View
@@ -3,6 +3,7 @@
module Controll
module Flow
autoload :Master, 'controll/flow/master'
+ autoload :Action, 'controll/flow/action'
autoload :EventMapper, 'controll/flow/event_mapper'
autoload :ActionMapper, 'controll/flow/action_mapper'
end
@@ -0,0 +1,7 @@
+module Controll::Flow
+ module Action
+ autoload :Base, 'controll/flow/action/base'
+ autoload :PathAction, 'controll/flow/action/path_action'
+ autoload :Fallback, 'controll/flow/action/fallback'
+ end
+end
@@ -1,18 +1,12 @@
-module Controll::Flow::ActionMapper
- class Action
+module Controll::Flow::Action
+ class Base
attr_reader :path, :controller, :errors
def initialize controller, path
@controller = controller
@path = path.to_s
end
- class << self
- def action controller, event
- raise NotImplementedError, 'You must implement the #action class method'
- end
- end
-
def set_errors *errors
@errors = errors.flatten
end
@@ -1,5 +1,5 @@
-module Controll::Flow::ActionMapper
- class Fallback < Action
+module Controll::Flow::Action
+ class Fallback < Base
attr_reader :controller, :event
def initialize controller, event = nil
@@ -1,5 +1,5 @@
-module Controll::Flow::ActionMapper
- class PathAction < Action
+module Controll::Flow::Action
+ class PathAction < Base
def perform
raise BadPathError, "Bad path: #{path}" if path.blank?
error_check!
@@ -19,12 +19,6 @@ def method_missing(method_name, *args, &block)
else
super
end
- end
-
- class << self
- # do sth useful here?
- def inherited base
- end
end
end
end
@@ -1,10 +1,7 @@
module Controll::Flow
module ActionMapper
- autoload :Action, 'controll/flow/action_mapper/action'
- autoload :PathAction, 'controll/flow/action_mapper/path_action'
- autoload :Fallback, 'controll/flow/action_mapper/fallback'
-
- autoload :Simple, 'controll/flow/action_mapper/simple'
- autoload :Complex, 'controll/flow/action_mapper/complex'
+ autoload :Base, 'controll/flow/action_mapper/base'
+ autoload :Simple, 'controll/flow/action_mapper/simple'
+ autoload :Complex, 'controll/flow/action_mapper/complex'
end
end
@@ -0,0 +1,13 @@
+module Controll::Flow::ActionMapper
+ class Base
+ class << self
+ def path_action_class
+ Controll::Flow::PathAction
+ end
+
+ def action controller, event
+ raise NotImplementedError, 'You must implement the #action class method'
+ end
+ end
+ end
+end
@@ -1,6 +1,6 @@
module Controll::Flow::ActionMapper
- class Complex < PathAction
- attr_reader :maps
+ class Complex < Base
+ attr_reader :event_maps
class << self
attr_writer :action_clazz
@@ -16,7 +16,7 @@ def inherited base
def action controller, event
action_types ||= types
path = path_finder(event).map
- self.new controller, path unless path.blank?
+ path_action_class.new controller, path unless path.blank?
end
# reader
@@ -1,5 +1,5 @@
module Controll::Flow::ActionMapper
- class Simple < PathAction
+ class Simple < Base
NoEventsDefinedError = Controll::Flow::NoEventsDefinedError
NoDefaultPathDefinedError = Controll::Flow::NoDefaultPathDefinedError
@@ -15,7 +15,7 @@ def inherited base
def action controller, event, path = nil
check!
event = normalize event
- self.new(controller, path || default_path) if events.include? event.name
+ path_action_class.new(controller, path || default_path) if events.include? event.name
end
# http://bugs.ruby-lang.org/issues/1082
@@ -43,7 +43,7 @@ def fallback
end
def fallback_class
- Flow::ActionMapper::Fallback
+ Flow::Action::Fallback
end
def handler_class action_handler
@@ -28,7 +28,7 @@ def default
{event: event, action_handlers: action_handlers}
end
- describe '.initialize controller, fallback_event' do
+ describe '.initialize with fallback_event' do
let(:event) { fallback_event }
subject { executor.new controller, options }
@@ -41,7 +41,7 @@ def default
end
end
- describe '.initialize controller, render_event' do
+ describe '.initialize with render_event' do
let(:event) { render_event }
subject { executor.new controller, options }
@@ -49,18 +49,19 @@ def event
end
ActionMapper = Controll::Flow::ActionMapper
+Action = Controll::Flow::Action
+
+PathAction = Action::PathAction
+Fallback = Action::Fallback
-Action = ActionMapper::Action
-PathAction = ActionMapper::PathAction
-Fallback = ActionMapper::Fallback
Simple = ActionMapper::Simple
Complex = ActionMapper::Complex
describe Controll::Flow::Master do
context 'use directly without sublclassing' do
- subject { flow.new controller }
+ subject { flow.new controller }
- let(:flow) { Controll::Flow::Master }
+ let(:flow) { Controll::Flow::Master }
let(:controller) { MyController::Update.new }
describe '.initialize' do
@@ -77,10 +78,10 @@ def event
end
context 'A Control Flow with empty #event method' do
- subject { flow.new controller }
+ subject { flow.new controller }
- let(:flow) { Flows::EmptyEvent }
- let(:controller) { MyController::Update.new }
+ let(:flow) { Flows::EmptyEvent }
+ let(:controller) { MyController::Update.new }
describe '.initialize' do
specify do
@@ -89,21 +90,17 @@ def event
end
describe '.execute' do
+ # since event is nil
specify do
- expect { subject.execute }.to_not raise_error
- end
-
- # since event returns nil
- specify do
- subject.execute.should_not be_nil
+ expect { subject.execute }.to raise_error(ArgumentError)
end
end
end
context 'A Control Flow where #event returns :update notice event' do
- subject { flow.new controller }
+ subject { flow.new controller }
- let(:flow) { Flows::UpdateEventWithoutHandler }
+ let(:flow) { Flows::UpdateEventWithoutHandler }
let(:controller) { MyController::Update.new }
describe '.initialize' do

0 comments on commit 4281db0

Please sign in to comment.