Class: Webmachine::DescribeRoutes::Route
- Inherits:
-
Struct
- Object
- Struct
- Webmachine::DescribeRoutes::Route
- Defined in:
- lib/webmachine/describe_routes.rb
Instance Attribute Summary collapse
-
#allowed_methods ⇒ Object
Returns the value of attribute allowed_methods.
-
#path ⇒ Object
Returns the value of attribute path.
-
#path_spec ⇒ Object
Returns the value of attribute path_spec.
-
#policy_classes ⇒ Object
Returns the value of attribute policy_classes.
-
#policy_names ⇒ Object
Returns the value of attribute policy_names.
-
#resource_class ⇒ Object
Returns the value of attribute resource_class.
-
#resource_class_location ⇒ Object
Returns the value of attribute resource_class_location.
-
#resource_name ⇒ Object
Returns the value of attribute resource_name.
-
#schemas ⇒ Object
Returns the value of attribute schemas.
Instance Method Summary collapse
-
#build_resource(env, application_context, path_param_values) ⇒ Webmachine::Resource
Creates a Webmachine Resource for the given route for use in tests.
- #path_include?(component) ⇒ Boolean
- #route_param_names ⇒ Object
Instance Attribute Details
#allowed_methods ⇒ Object
Returns the value of attribute allowed_methods
12 13 14 |
# File 'lib/webmachine/describe_routes.rb', line 12 def allowed_methods @allowed_methods end |
#path ⇒ Object
Returns the value of attribute path
12 13 14 |
# File 'lib/webmachine/describe_routes.rb', line 12 def path @path end |
#path_spec ⇒ Object
Returns the value of attribute path_spec
12 13 14 |
# File 'lib/webmachine/describe_routes.rb', line 12 def path_spec @path_spec end |
#policy_classes ⇒ Object
Returns the value of attribute policy_classes
12 13 14 |
# File 'lib/webmachine/describe_routes.rb', line 12 def policy_classes @policy_classes end |
#policy_names ⇒ Object
Returns the value of attribute policy_names
12 13 14 |
# File 'lib/webmachine/describe_routes.rb', line 12 def policy_names @policy_names end |
#resource_class ⇒ Object
Returns the value of attribute resource_class
12 13 14 |
# File 'lib/webmachine/describe_routes.rb', line 12 def resource_class @resource_class end |
#resource_class_location ⇒ Object
Returns the value of attribute resource_class_location
12 13 14 |
# File 'lib/webmachine/describe_routes.rb', line 12 def resource_class_location @resource_class_location end |
#resource_name ⇒ Object
Returns the value of attribute resource_name
12 13 14 |
# File 'lib/webmachine/describe_routes.rb', line 12 def resource_name @resource_name end |
#schemas ⇒ Object
Returns the value of attribute schemas
12 13 14 |
# File 'lib/webmachine/describe_routes.rb', line 12 def schemas @schemas end |
Instance Method Details
#build_resource(env, application_context, path_param_values) ⇒ Webmachine::Resource
Creates a Webmachine Resource for the given route for use in tests.
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/webmachine/describe_routes.rb', line 37 def build_resource(env, application_context, path_param_values) path = "/" + path_spec.collect{ | part | part.is_a?(Symbol) ? (path_param_values[part] || "missing-param") : part }.join("/") path_params = route_param_names.each_with_object({}){ | name, new_params | new_params[name] = path_param_values[name] } path_info = { application_context: application_context, resource_name: resource_name }.merge(path_params) rack_req = ::Rack::Request.new({ "REQUEST_METHOD" => "GET", "rack.input" => StringIO.new("") }.merge(env) ) request = Webmachine::Adapters::Rack::RackRequest.new( rack_req.env["REQUEST_METHOD"], path, Webmachine::Headers.from_cgi({"HTTP_HOST" => "example.org"}.merge(env)), Webmachine::Adapters::Rack::RequestBody.new(rack_req), {}, {}, rack_req.env ) request.path_info = path_info resource_class.new(request, Webmachine::Response.new) end |
#path_include?(component) ⇒ Boolean
24 25 26 |
# File 'lib/webmachine/describe_routes.rb', line 24 def path_include?(component) path.include?(component) end |
#route_param_names ⇒ Object
28 29 30 |
# File 'lib/webmachine/describe_routes.rb', line 28 def route_param_names path_spec.select { | component | component.is_a?(Symbol) } end |