Class: Whiskey::Server::Router
- Inherits:
-
Object
- Object
- Whiskey::Server::Router
- Defined in:
- lib/whiskey/server/router.rb
Instance Method Summary collapse
- #action ⇒ Object
- #body ⇒ Object
- #control ⇒ Object
-
#initialize(resource, verb, parameters = {}) ⇒ Router
constructor
A new instance of Router.
- #to_hash ⇒ Object
Constructor Details
#initialize(resource, verb, parameters = {}) ⇒ Router
Returns a new instance of Router.
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/whiskey/server/router.rb', line 4 def initialize(resource, verb, parameters = {}) @control = resource @action = verb.upcase @body = parameters @route = if control.safe_constantize && control_action.safe_constantize Whiskey.logger.info("#{@action} /#{@control} #{@body.inspect}") control_action.safe_constantize.new(body) else Error.new(:not_found) end end |
Instance Method Details
#action ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/whiskey/server/router.rb', line 29 def action case when @action == "PULL" then "ListAction" when @action == "PUSH" then "CreateAction" when @action == "PULL" && parameters.id then "ShowAction" when @action == "PUSH" && parameters.id then "UpdateAction" end end |
#body ⇒ Object
17 18 19 |
# File 'lib/whiskey/server/router.rb', line 17 def body OpenStruct.new(@parameters) end |
#control ⇒ Object
25 26 27 |
# File 'lib/whiskey/server/router.rb', line 25 def control "Controls::#{@control.classify}Control" end |
#to_hash ⇒ Object
21 22 23 |
# File 'lib/whiskey/server/router.rb', line 21 def to_hash @route.to_hash end |