Class: ASeriesOfTubes::Tubes::Tuber

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

Constant Summary collapse

METHODS =
[:get, :post, :put, :delete]

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTuber

Returns a new instance of Tuber.



8
9
10
# File 'lib/a_series_of_tubes/tubes/tuber.rb', line 8

def initialize
  @tubes = []
end

Instance Attribute Details

#tubesObject (readonly)

Returns the value of attribute tubes.



6
7
8
# File 'lib/a_series_of_tubes/tubes/tuber.rb', line 6

def tubes
  @tubes
end

Instance Method Details

#add_tube(pattern, method, controller, action) ⇒ Object



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

def add_tube pattern, method, controller, action
  tube = Tubes::Tube.new pattern, method, controller, action
  self.tubes << tube
end

#draw(&tubes) ⇒ Object



23
24
25
# File 'lib/a_series_of_tubes/tubes/tuber.rb', line 23

def draw &tubes
  self.instance_eval &tubes
end

#match(request) ⇒ Object



27
28
29
# File 'lib/a_series_of_tubes/tubes/tuber.rb', line 27

def match request
  self.tubes.find { |tube| tube.matches? request }
end

#run(request, response) ⇒ Object



31
32
33
34
# File 'lib/a_series_of_tubes/tubes/tuber.rb', line 31

def run request, response
  tube = match request
  tube ? tube.run(request, response) : not_found(response)
end