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 |
# File 'lib/botch/base.rb', line 15 def initialize @routes = [] 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
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/botch/base.rb', line 19 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
32 33 34 |
# File 'lib/botch/base.rb', line 32 def del(label) @routes.delete_if{ |route| route[:label] == label } end |
#exist?(label) ⇒ Boolean Also known as: exists?
36 37 38 |
# File 'lib/botch/base.rb', line 36 def exist?(label) !!index(label) end |
#index(label) ⇒ Object
42 43 44 |
# File 'lib/botch/base.rb', line 42 def index(label) @routes.index{ |route| route[:label] === label } end |
#inject(url) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/botch/base.rb', line 46 def inject(url) @routes.inject([]) do |result, route| result << route if map_validation(url, route[:map]) result end end |