Class: Botch::Route

Inherits:
Object
  • Object
show all
Defined in:
lib/botch/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRoute

Returns a new instance of Route.



15
16
17
# File 'lib/botch/base.rb', line 15

def initialize
  @routes = []
end

Instance Attribute Details

#routesObject

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

Raises:

  • (ArgumentError)


19
20
21
22
23
24
25
26
27
28
29
# File 'lib/botch/base.rb', line 19

def add(label, options = {}, &block)
  raise ArgumentError unless block_given?
  if route = exists?(label)
    route[:block] = block
    route[:label] = label
  else
    options[:block] = block
    options[:label] = label
    @routes << options
  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?

Returns:

  • (Boolean)


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