Class: Expressr::RouteItem
- Inherits:
-
Object
- Object
- Expressr::RouteItem
- Defined in:
- lib/expressr/route_item.rb
Instance Attribute Summary collapse
-
#additional_arguments ⇒ Object
readonly
Returns the value of attribute additional_arguments.
-
#proc ⇒ Object
readonly
Returns the value of attribute proc.
Instance Method Summary collapse
- #call(env, continue_method) ⇒ Object
- #continue ⇒ Object
-
#initialize(proc, options) ⇒ RouteItem
constructor
A new instance of RouteItem.
- #matches_env?(env) ⇒ Boolean
- #matches_request?(request) ⇒ Boolean
- #params ⇒ Object
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, ) @proc = proc @path = [:path] @method = [:method] @content_type = [:content_type] @param = [:param] || [] @additional_arguments = [] set_path_token_and_param_names end |
Instance Attribute Details
#additional_arguments ⇒ Object (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 |
#proc ⇒ Object (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 |
#continue ⇒ Object
25 26 27 |
# File 'lib/expressr/route_item.rb', line 25 def continue @continue.call(@env) end |
#matches_env?(env) ⇒ 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
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 |
#params ⇒ Object
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 |