Class: ATD::Route
- Inherits:
-
Object
- Object
- ATD::Route
- Defined in:
- lib/atd.rb
Overview
So called because each instance stores a route, and will be called if that route is reached. A route for the purposes of ATD is a parser that will be fed env in the rack app.
Instance Attribute Summary collapse
-
#actions ⇒ Object
Returns the value of attribute actions.
-
#app ⇒ Object
Returns the value of attribute app.
-
#args ⇒ Object
Returns the value of attribute args.
-
#block ⇒ Object
Returns the value of attribute block.
-
#method ⇒ Object
Returns the value of attribute method.
-
#output ⇒ Object
Returns the value of attribute output.
-
#path ⇒ Object
Returns the value of attribute path.
Instance Method Summary collapse
-
#delete(path = nil, *args) ⇒ Object
Sets route to receive a delete request to path and execute the block provided (if one is provided).
-
#get(path = nil, *args) ⇒ Object
Sets route to receive a get request to path and execute the block provided (if one is provided).
-
#initialize(*args, &block) ⇒ Route
constructor
The first two arguments must me the path and the output.
-
#patch(path = nil, *args) ⇒ Object
Sets route to receive a patch request to path and execute the block provided (if one is provided).
-
#post(path = nil, *args) ⇒ Object
Sets route to receive a post request to path and execute the block provided (if one is provided).
-
#put(path = nil, *args) ⇒ Object
Sets route to receive a put request to path and execute the block provided (if one is provided).
-
#to_h ⇒ Object
private
Converts an instance of Route into it’s Hash representation.
Constructor Details
#initialize(*args, &block) ⇒ Route
The first two arguments must me the path and the output.
26 27 28 29 30 31 |
# File 'lib/atd.rb', line 26 def initialize(*args, &block) @method = [:get, :post, :put, :patch, :delete] @method = [] if args.last.is_a?(Hash) && !(args.last[:respond_to].nil? || args.last[:ignore].nil?) @app = :DefaultApp parse_args(*args, &block) end |
Instance Attribute Details
#actions ⇒ Object
Returns the value of attribute actions.
23 24 25 |
# File 'lib/atd.rb', line 23 def actions @actions end |
#app ⇒ Object
Returns the value of attribute app.
23 24 25 |
# File 'lib/atd.rb', line 23 def app @app end |
#args ⇒ Object
Returns the value of attribute args.
23 24 25 |
# File 'lib/atd.rb', line 23 def args @args end |
#block ⇒ Object
Returns the value of attribute block.
23 24 25 |
# File 'lib/atd.rb', line 23 def block @block end |
#method ⇒ Object
Returns the value of attribute method.
23 24 25 |
# File 'lib/atd.rb', line 23 def method @method end |
#output ⇒ Object
Returns the value of attribute output.
23 24 25 |
# File 'lib/atd.rb', line 23 def output @output end |
#path ⇒ Object
Returns the value of attribute path.
23 24 25 |
# File 'lib/atd.rb', line 23 def path @path end |
Instance Method Details
#delete(path = nil, *args) ⇒ Object
Sets route to receive a delete request to path and execute the block provided (if one is provided)
67 68 69 70 71 72 73 74 |
# File 'lib/atd.rb', line 67 [:get, :post, :put, :delete, :patch].each do |method| define_method(method) do |*args, &block| @method = [method] if @method.length == 5 @method += [method] @method.uniq! parse_args(*args, &block) end end |
#get(path = nil, *args) ⇒ Object
Sets route to receive a get request to path and execute the block provided (if one is provided)
|
|
# File 'lib/atd.rb', line 42
|
#patch(path = nil, *args) ⇒ Object
Sets route to receive a patch request to path and execute the block provided (if one is provided)
|
|
# File 'lib/atd.rb', line 57
|
#post(path = nil, *args) ⇒ Object
Sets route to receive a post request to path and execute the block provided (if one is provided)
|
|
# File 'lib/atd.rb', line 47
|
#put(path = nil, *args) ⇒ Object
Sets route to receive a put request to path and execute the block provided (if one is provided)
|
|
# File 'lib/atd.rb', line 52
|
#to_h ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts an instance of ATD::Route into it’s Hash representation. The format for the Hash is listed here
79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/atd.rb', line 79 def to_h routes = {} routes[@path] = {} routes[@path][@method] = {} routes[@path][@method] = { output: @output, block: @block, args: @args, route: self } routes end |