Module: Sinatra::AdvancedRoutes::Route

Defined in:
lib/sinatra/advanced_routes.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#appObject

Returns the value of attribute app.



38
39
40
# File 'lib/sinatra/advanced_routes.rb', line 38

def app
  @app
end

#docstringObject

Returns the value of attribute docstring.



38
39
40
# File 'lib/sinatra/advanced_routes.rb', line 38

def docstring
  @docstring
end

#fileObject

Returns the value of attribute file.



38
39
40
# File 'lib/sinatra/advanced_routes.rb', line 38

def file
  @file
end

#lineObject

Returns the value of attribute line.



38
39
40
# File 'lib/sinatra/advanced_routes.rb', line 38

def line
  @line
end

#pathObject

Returns the value of attribute path.



38
39
40
# File 'lib/sinatra/advanced_routes.rb', line 38

def path
  @path
end

#verbObject

Returns the value of attribute verb.



38
39
40
# File 'lib/sinatra/advanced_routes.rb', line 38

def verb
  @verb
end

Class Method Details

.new(verb, args = {}) ⇒ Object



34
35
36
# File 'lib/sinatra/advanced_routes.rb', line 34

def self.new(verb, args = {})
  [].to_route! verb, args
end

Instance Method Details

#activate(at_top = false) ⇒ Object



59
60
61
62
63
64
65
66
67
# File 'lib/sinatra/advanced_routes.rb', line 59

def activate(at_top = false)
  also_change.each { |r| r.activate }
  return if active?
  meth = at_top ? :unshift : :push
  (app.routes[verb] ||= []).send(meth, self)
  invoke_hook :route_added, verb, path, block
  invoke_hook :advanced_route_activated, self
  self
end

#active?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/sinatra/advanced_routes.rb', line 55

def active?
  app.routes[verb].include? self
end

#also_change(*other_routes) ⇒ Object



98
99
100
# File 'lib/sinatra/advanced_routes.rb', line 98

def also_change(*other_routes)
  (@also_change ||= []).push(*other_routes)
end

#blockObject Also known as: to_proc



43
# File 'lib/sinatra/advanced_routes.rb', line 43

def block;      self[3]; end

#block=(value) ⇒ Object



49
# File 'lib/sinatra/advanced_routes.rb', line 49

def block=(value);      self[3] = value; end

#conditionsObject



42
# File 'lib/sinatra/advanced_routes.rb', line 42

def conditions; self[2]; end

#conditions=(value) ⇒ Object



48
# File 'lib/sinatra/advanced_routes.rb', line 48

def conditions=(value); self[2] = value; end

#deactivateObject



69
70
71
72
73
74
75
76
# File 'lib/sinatra/advanced_routes.rb', line 69

def deactivate
  also_change.each { |r| r.deactivate }
  return unless active?
  (app.routes[verb] ||= []).delete(signature)
  invoke_hook :route_removed, verb, path, block
  invoke_hook :advanced_route_deactivated, self
  self
end

#file?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/sinatra/advanced_routes.rb', line 84

def file?
  !!@file
end

#inspectObject



88
89
90
# File 'lib/sinatra/advanced_routes.rb', line 88

def inspect
  "#<Sinatra::AdvancedRoutes::Route #{ivar_inspect.join ", "}>"
end

#keysObject



41
# File 'lib/sinatra/advanced_routes.rb', line 41

def keys;       self[1]; end

#keys=(value) ⇒ Object



47
# File 'lib/sinatra/advanced_routes.rb', line 47

def keys=(value);       self[1] = value; end

#patternObject



40
# File 'lib/sinatra/advanced_routes.rb', line 40

def pattern;    self[0]; end

#pattern=(value) ⇒ Object



46
# File 'lib/sinatra/advanced_routes.rb', line 46

def pattern=(value);    self[0] = value; end

#promote(upwards = true) ⇒ Object



78
79
80
81
82
# File 'lib/sinatra/advanced_routes.rb', line 78

def promote(upwards = true)
  also_change.each { |r| r.promote(upwards) }
  deactivate
  activate(upwards)
end

#signatureObject



51
52
53
# File 'lib/sinatra/advanced_routes.rb', line 51

def signature
  [pattern, keys, conditions, block]
end

#to_route(verb, args = {}) ⇒ Object



92
93
94
95
96
# File 'lib/sinatra/advanced_routes.rb', line 92

def to_route(verb, args = {})
  args = args.dup
  [:app, :verb, :file, :line, :path].each { |key| args[key] ||= send(key) }
  super(verb, args)
end