2009-02-25 01:25:21 +00:00
|
|
|
module AbstractController
|
|
|
|
class Base
|
|
|
|
|
|
|
|
attr_internal :response_body
|
|
|
|
attr_internal :response_obj
|
2009-02-27 19:42:13 +00:00
|
|
|
attr_internal :action_name
|
|
|
|
|
2009-02-25 01:25:21 +00:00
|
|
|
def self.process(action)
|
|
|
|
new.process(action)
|
|
|
|
end
|
|
|
|
|
2009-03-04 00:42:20 +00:00
|
|
|
def self.inherited(klass)
|
|
|
|
end
|
|
|
|
|
2009-02-25 01:25:21 +00:00
|
|
|
def initialize
|
|
|
|
self.response_obj = {}
|
|
|
|
end
|
|
|
|
|
2009-02-27 19:42:13 +00:00
|
|
|
def process(action_name)
|
2009-03-18 01:04:22 +00:00
|
|
|
unless respond_to_action?(action_name)
|
|
|
|
raise ActionNotFound, "The action '#{action_name}' could not be found"
|
|
|
|
end
|
|
|
|
|
2009-02-27 19:42:13 +00:00
|
|
|
@_action_name = action_name
|
2009-02-28 03:25:45 +00:00
|
|
|
process_action
|
2009-02-25 01:25:21 +00:00
|
|
|
self.response_obj[:body] = self.response_body
|
|
|
|
self
|
|
|
|
end
|
|
|
|
|
2009-03-18 01:04:22 +00:00
|
|
|
private
|
|
|
|
|
2009-02-28 03:25:45 +00:00
|
|
|
def process_action
|
2009-03-18 01:04:22 +00:00
|
|
|
respond_to?(action_name) ? send(action_name) : send(:action_missing, action_name)
|
|
|
|
end
|
|
|
|
|
|
|
|
def respond_to_action?(action_name)
|
|
|
|
respond_to?(action_name) || respond_to?(:action_missing, true)
|
2009-02-28 03:25:45 +00:00
|
|
|
end
|
|
|
|
|
2009-02-25 01:25:21 +00:00
|
|
|
end
|
|
|
|
end
|