Class: Expressr::RouteItem

Inherits:
Object
  • Object
show all
Defined in:
lib/expressr/route_item.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(proc, options) ⇒ RouteItem

Returns a new instance of RouteItem.



5
6
7
8
9
10
11
12
13
14
# File 'lib/expressr/route_item.rb', line 5

def initialize(proc, options)
  @proc = proc
  @path = options[:path]
  @method = options[:method]
  @content_type = options[:content_type]
  @param = options[:param] || []

  @additional_arguments = []
  set_path_token_and_param_names
end

Instance Attribute Details

#additional_argumentsObject (readonly)

Returns the value of attribute additional_arguments.



3
4
5
# File 'lib/expressr/route_item.rb', line 3

def additional_arguments
  @additional_arguments
end

#procObject (readonly)

Returns the value of attribute proc.



3
4
5
# File 'lib/expressr/route_item.rb', line 3

def proc
  @proc
end

Instance Method Details

#call(env, continue_method) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/expressr/route_item.rb', line 16

def call(env, continue_method)
  @env = env
  @continue = continue_method
  @env[:request].params.merge!(params)
  @proc.call(@env[:request], @env[:response], @continue, *@additional_arguments)
  continue
  @env
end

#continueObject



25
26
27
# File 'lib/expressr/route_item.rb', line 25

def continue
  @continue.call(@env)
end

#matches_env?(env) ⇒ Boolean

Returns:

  • (Boolean)


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

def matches_env?(env)
  matches_request?(env[:request])
end

#matches_request?(request) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
37
38
# File 'lib/expressr/route_item.rb', line 33

def matches_request?(request)
  content_type_matches?(request) &&
  method_matches?(request.env) &&
  path_matches?(request.env) &&
  param_matches?(request)
end

#paramsObject



40
41
42
43
44
45
46
47
48
49
# File 'lib/expressr/route_item.rb', line 40

def params
  if @param_values.empty?
    {}
  else
    if @param_names.empty?
      @param_names = (0..(@param_values.length - 1)).to_a
    end
    Hash[@param_names.zip(@param_values)]
  end
end