Class: ASeriesOfTubes::Tubes::Tube

Inherits:
Object
  • Object
show all
Defined in:
lib/a_series_of_tubes/tubes/tube.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(pattern, method, controller, action) ⇒ Tube

Returns a new instance of Tube.



6
7
8
9
10
11
# File 'lib/a_series_of_tubes/tubes/tube.rb', line 6

def initialize pattern, method, controller, action
  @pattern    = pattern
  @method     = method.to_s.upcase
  @controller = controller
  @action     = action
end

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action.



4
5
6
# File 'lib/a_series_of_tubes/tubes/tube.rb', line 4

def action
  @action
end

#controllerObject (readonly)

Returns the value of attribute controller.



4
5
6
# File 'lib/a_series_of_tubes/tubes/tube.rb', line 4

def controller
  @controller
end

#methodObject (readonly)

Returns the value of attribute method.



4
5
6
# File 'lib/a_series_of_tubes/tubes/tube.rb', line 4

def method
  @method
end

#patternObject (readonly)

Returns the value of attribute pattern.



4
5
6
# File 'lib/a_series_of_tubes/tubes/tube.rb', line 4

def pattern
  @pattern
end

Instance Method Details

#matches?(request) ⇒ Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/a_series_of_tubes/tubes/tube.rb', line 13

def matches? request
  self.pattern =~ request.path && request.request_method == self.method
end

#run(request, response) ⇒ Object



17
18
19
20
21
# File 'lib/a_series_of_tubes/tubes/tube.rb', line 17

def run request, response
  params = parse_params_from_path request.path
  controller = self.controller.new request, response, params
  controller.invoke_action action
end