Class: ATD::Route

Inherits:
Object show all
Includes:
InternalHelpers
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

Instance Method Summary collapse

Methods included from InternalHelpers

#asset

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

#actionsObject

Returns the value of attribute actions.



30
31
32
# File 'lib/atd.rb', line 30

def actions
  @actions
end

#appObject

Returns the value of attribute app.



29
30
31
# File 'lib/atd.rb', line 29

def app
  @app
end

#argsObject

Returns the value of attribute args.



30
31
32
# File 'lib/atd.rb', line 30

def args
  @args
end

#blockObject

Returns the value of attribute block.



30
31
32
# File 'lib/atd.rb', line 30

def block
  @block
end

#filenameObject

Returns the value of attribute filename.



30
31
32
# File 'lib/atd.rb', line 30

def filename
  @filename
end

#headersObject

Returns the value of attribute headers.



30
31
32
# File 'lib/atd.rb', line 30

def headers
  @headers
end

#methodObject

Returns the value of attribute method.



30
31
32
# File 'lib/atd.rb', line 30

def method
  @method
end

#outputObject

Returns the value of attribute output.



30
31
32
# File 'lib/atd.rb', line 30

def output
  @output
end

#pathObject

Returns the value of attribute path.



30
31
32
# File 'lib/atd.rb', line 30

def path
  @path
end

#status_codeObject

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)

Parameters:

  • path (String) (defaults to: nil)

    The path at which the route should receive from.

Returns:

  • ATD::Route



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)

Parameters:

  • path (String) (defaults to: nil)

    The path at which the route should receive from.

Returns:

  • ATD::Route



# 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)

Parameters:

  • path (String) (defaults to: nil)

    The path at which the route should receive from.

Returns:

  • ATD::Route



# 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)

Parameters:

  • path (String) (defaults to: nil)

    The path at which the route should receive from.

Returns:

  • ATD::Route



# 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)

Parameters:

  • path (String) (defaults to: nil)

    The path at which the route should receive from.

Returns:

  • ATD::Route



# File 'lib/atd.rb', line 62