Class: Whiskey::Server::Router

Inherits:
Object
  • Object
show all
Defined in:
lib/whiskey/server/router.rb

Instance Method Summary collapse

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

#actionObject



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

#bodyObject



17
18
19
# File 'lib/whiskey/server/router.rb', line 17

def body
  OpenStruct.new(@parameters)
end

#controlObject



25
26
27
# File 'lib/whiskey/server/router.rb', line 25

def control
  "Controls::#{@control.classify}Control"
end

#to_hashObject



21
22
23
# File 'lib/whiskey/server/router.rb', line 21

def to_hash
  @route.to_hash
end