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?)
-
#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 |
# File 'lib/botch/base.rb', line 19 def add(label, = {}, &block) raise ArgumentError unless block_given? if route = exists?(label) route[:block] = block route[:label] = label else [:block] = block [:label] = label @routes << end end |
#del(label) ⇒ Object
31 32 33 |
# File 'lib/botch/base.rb', line 31 def del(label) @routes.delete_if{ |route| route[:label] == label } end |
#exist?(label) ⇒ Boolean Also known as: exists?
35 36 37 |
# File 'lib/botch/base.rb', line 35 def exist?(label) @routes.find{ |route| route[:label] == label } end |
#inject(url) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/botch/base.rb', line 41 def inject(url) @routes.inject([]) do |result, route| result << route if map_validation(url, route[:map]) result end end |