Module: Sinatra::AdvancedRoutes::Route
- Defined in:
- lib/sinatra/advanced_routes.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
Returns the value of attribute app.
-
#docstring ⇒ Object
Returns the value of attribute docstring.
-
#file ⇒ Object
Returns the value of attribute file.
-
#line ⇒ Object
Returns the value of attribute line.
-
#path ⇒ Object
Returns the value of attribute path.
-
#verb ⇒ Object
Returns the value of attribute verb.
Class Method Summary collapse
Instance Method Summary collapse
- #activate(at_top = false) ⇒ Object
- #active? ⇒ Boolean
- #also_change(*other_routes) ⇒ Object
- #block ⇒ Object (also: #to_proc)
- #block=(value) ⇒ Object
- #conditions ⇒ Object
- #conditions=(value) ⇒ Object
- #deactivate ⇒ Object
- #file? ⇒ Boolean
- #inspect ⇒ Object
- #keys ⇒ Object
- #keys=(value) ⇒ Object
- #pattern ⇒ Object
- #pattern=(value) ⇒ Object
- #promote(upwards = true) ⇒ Object
- #signature ⇒ Object
- #to_route(verb, args = {}) ⇒ Object
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app.
35 36 37 |
# File 'lib/sinatra/advanced_routes.rb', line 35 def app @app end |
#docstring ⇒ Object
Returns the value of attribute docstring.
35 36 37 |
# File 'lib/sinatra/advanced_routes.rb', line 35 def docstring @docstring end |
#file ⇒ Object
Returns the value of attribute file.
35 36 37 |
# File 'lib/sinatra/advanced_routes.rb', line 35 def file @file end |
#line ⇒ Object
Returns the value of attribute line.
35 36 37 |
# File 'lib/sinatra/advanced_routes.rb', line 35 def line @line end |
#path ⇒ Object
Returns the value of attribute path.
35 36 37 |
# File 'lib/sinatra/advanced_routes.rb', line 35 def path @path end |
#verb ⇒ Object
Returns the value of attribute verb.
35 36 37 |
# File 'lib/sinatra/advanced_routes.rb', line 35 def verb @verb end |
Class Method Details
.new(verb, args = {}) ⇒ Object
31 32 33 |
# File 'lib/sinatra/advanced_routes.rb', line 31 def self.new(verb, args = {}) [].to_route! verb, args end |
Instance Method Details
#activate(at_top = false) ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/sinatra/advanced_routes.rb', line 56 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
52 53 54 |
# File 'lib/sinatra/advanced_routes.rb', line 52 def active? app.routes.include? verb and app.routes[verb].include? self end |
#also_change(*other_routes) ⇒ Object
95 96 97 |
# File 'lib/sinatra/advanced_routes.rb', line 95 def also_change(*other_routes) (@also_change ||= []).push(*other_routes) end |
#block ⇒ Object Also known as: to_proc
40 |
# File 'lib/sinatra/advanced_routes.rb', line 40 def block; self[3]; end |
#block=(value) ⇒ Object
46 |
# File 'lib/sinatra/advanced_routes.rb', line 46 def block=(value); self[3] = value; end |
#conditions ⇒ Object
39 |
# File 'lib/sinatra/advanced_routes.rb', line 39 def conditions; self[2]; end |
#conditions=(value) ⇒ Object
45 |
# File 'lib/sinatra/advanced_routes.rb', line 45 def conditions=(value); self[2] = value; end |
#deactivate ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/sinatra/advanced_routes.rb', line 66 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
81 82 83 |
# File 'lib/sinatra/advanced_routes.rb', line 81 def file? !!@file end |
#inspect ⇒ Object
85 86 87 |
# File 'lib/sinatra/advanced_routes.rb', line 85 def inspect "#<Sinatra::AdvancedRoutes::Route #{ivar_inspect.join ", "}>" end |
#keys ⇒ Object
38 |
# File 'lib/sinatra/advanced_routes.rb', line 38 def keys; self[1]; end |
#keys=(value) ⇒ Object
44 |
# File 'lib/sinatra/advanced_routes.rb', line 44 def keys=(value); self[1] = value; end |
#pattern ⇒ Object
37 |
# File 'lib/sinatra/advanced_routes.rb', line 37 def pattern; self[0]; end |
#pattern=(value) ⇒ Object
43 |
# File 'lib/sinatra/advanced_routes.rb', line 43 def pattern=(value); self[0] = value; end |
#promote(upwards = true) ⇒ Object
75 76 77 78 79 |
# File 'lib/sinatra/advanced_routes.rb', line 75 def promote(upwards = true) also_change.each { |r| r.promote(upwards) } deactivate activate(upwards) end |
#signature ⇒ Object
48 49 50 |
# File 'lib/sinatra/advanced_routes.rb', line 48 def signature [pattern, keys, conditions, block] end |
#to_route(verb, args = {}) ⇒ Object
89 90 91 92 93 |
# File 'lib/sinatra/advanced_routes.rb', line 89 def to_route(verb, args = {}) args = args.dup [:app, :verb, :file, :line, :path].each { |key| args[key] ||= send(key) } super(verb, args) end |