Class: ATD::Route
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.
-
#filename ⇒ Object
Returns the value of attribute filename.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#method ⇒ Object
Returns the value of attribute method.
-
#output ⇒ Object
Returns the value of attribute output.
-
#path ⇒ Object
Returns the value of attribute path.
-
#status_code ⇒ Object
Returns the value of attribute status_code.
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).
Methods included from InternalHelpers
Constructor Details
#initialize(*args, &block) ⇒ Route
The first two arguments must me the path and the output.
33 34 35 36 37 38 39 40 41 |
# File 'lib/atd.rb', line 33 def initialize(*args, &block) @args, @block, @path, @output, @actions, @status_code, @filename = nil @status_code = 200 @headers = {} @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.
30 31 32 |
# File 'lib/atd.rb', line 30 def actions @actions end |
#app ⇒ Object
Returns the value of attribute app.
29 30 31 |
# File 'lib/atd.rb', line 29 def app @app end |
#args ⇒ Object
Returns the value of attribute args.
30 31 32 |
# File 'lib/atd.rb', line 30 def args @args end |
#block ⇒ Object
Returns the value of attribute block.
30 31 32 |
# File 'lib/atd.rb', line 30 def block @block end |
#filename ⇒ Object
Returns the value of attribute filename.
30 31 32 |
# File 'lib/atd.rb', line 30 def filename @filename end |
#headers ⇒ Object
Returns the value of attribute headers.
30 31 32 |
# File 'lib/atd.rb', line 30 def headers @headers end |
#method ⇒ Object
Returns the value of attribute method.
30 31 32 |
# File 'lib/atd.rb', line 30 def method @method end |
#output ⇒ Object
Returns the value of attribute output.
30 31 32 |
# File 'lib/atd.rb', line 30 def output @output end |
#path ⇒ Object
Returns the value of attribute path.
30 31 32 |
# File 'lib/atd.rb', line 30 def path @path end |
#status_code ⇒ Object
Returns the value of attribute status_code.
30 31 32 |
# File 'lib/atd.rb', line 30 def status_code @status_code 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)
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/atd.rb', line 77 [:get, :post, :put, :delete, :patch].each do |method| define_method(method) do |*args, &block| # This conditional allows the syntax get post put "/", "Hello" because it passes # the variables up through the different method calls. if args.first.is_a?(ATD::Route) @method = args.first.method @filename = args.first.filename @output = args.first.output @path = args.first.path @args = args.first.args @block = args.first.block @app = args.first.app @actions = args.first.actions end @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 52
|
#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 67
|
#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 57
|
#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 62
|