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:



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

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

Returns:



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