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_class ⇒ Object
Returns the value of attribute policy_class.
-
#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
- #[](key) ⇒ Object
-
#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
8 9 10 |
# File 'lib/webmachine/describe_routes.rb', line 8 def allowed_methods @allowed_methods end |
#path ⇒ Object
Returns the value of attribute path
8 9 10 |
# File 'lib/webmachine/describe_routes.rb', line 8 def path @path end |
#path_spec ⇒ Object
Returns the value of attribute path_spec
8 9 10 |
# File 'lib/webmachine/describe_routes.rb', line 8 def path_spec @path_spec end |
#policy_class ⇒ Object
Returns the value of attribute policy_class
8 9 10 |
# File 'lib/webmachine/describe_routes.rb', line 8 def policy_class @policy_class end |
#resource_class ⇒ Object
Returns the value of attribute resource_class
8 9 10 |
# File 'lib/webmachine/describe_routes.rb', line 8 def resource_class @resource_class end |
#resource_class_location ⇒ Object
Returns the value of attribute resource_class_location
8 9 10 |
# File 'lib/webmachine/describe_routes.rb', line 8 def resource_class_location @resource_class_location end |
#resource_name ⇒ Object
Returns the value of attribute resource_name
8 9 10 |
# File 'lib/webmachine/describe_routes.rb', line 8 def resource_name @resource_name end |
#schemas ⇒ Object
Returns the value of attribute schemas
8 9 10 |
# File 'lib/webmachine/describe_routes.rb', line 8 def schemas @schemas end |
Instance Method Details
#[](key) ⇒ Object
19 20 21 22 23 24 25 |
# File 'lib/webmachine/describe_routes.rb', line 19 def [](key) if respond_to?(key) send(key) else nil end end |
#build_resource(env, application_context, path_param_values) ⇒ Webmachine::Resource
Creates a Webmachine Resource for the given route for use in tests.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/webmachine/describe_routes.rb', line 40 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) ) dummy_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 ) dummy_request.path_info = path_info resource_class.new(dummy_request, Webmachine::Response.new) end |
#path_include?(component) ⇒ Boolean
27 28 29 |
# File 'lib/webmachine/describe_routes.rb', line 27 def path_include?(component) path.include?(component) end |
#route_param_names ⇒ Object
31 32 33 |
# File 'lib/webmachine/describe_routes.rb', line 31 def route_param_names path_spec.select { | component | component.is_a?(Symbol) } end |