Class: Botch::Route
- Inherits:
-
Object
- Object
- Botch::Route
- Defined in:
- lib/botch/base.rb
Instance Attribute Summary collapse
-
#routes ⇒ Object
Returns the value of attribute routes.
Instance Method Summary collapse
- #add(label, options = {}, &block) ⇒ Object
- #del(label) ⇒ Object
- #exist?(label) ⇒ Boolean (also: #exists?)
- #index(label) ⇒ Object
-
#initialize ⇒ Route
constructor
A new instance of Route.
- #inject(url) ⇒ Object
Constructor Details
#initialize ⇒ Route
Returns a new instance of Route.
15 16 17 18 |
# File 'lib/botch/base.rb', line 15 def initialize @routes = [] self end |
Instance Attribute Details
#routes ⇒ Object
Returns the value of attribute routes.
13 14 15 |
# File 'lib/botch/base.rb', line 13 def routes @routes end |
Instance Method Details
#add(label, options = {}, &block) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/botch/base.rb', line 20 def add(label, = {}, &block) raise ArgumentError unless block_given? if position = index(label) route = @routes[position] route[:block] = block route[:label] = label else [:block] = block [:label] = label @routes << end end |
#del(label) ⇒ Object
33 34 35 |
# File 'lib/botch/base.rb', line 33 def del(label) @routes.delete_if{ |route| route[:label] == label } end |
#exist?(label) ⇒ Boolean Also known as: exists?
37 38 39 |
# File 'lib/botch/base.rb', line 37 def exist?(label) !!index(label) end |
#index(label) ⇒ Object
43 44 45 |
# File 'lib/botch/base.rb', line 43 def index(label) @routes.index{ |route| route[:label] === label } end |
#inject(url) ⇒ Object
47 48 49 50 51 52 |
# File 'lib/botch/base.rb', line 47 def inject(url) @routes.inject([]) do |result, route| result << route if map_validation(url, route[:map]) result end end |