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.
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
6 7 8 |
# File 'lib/webmachine/describe_routes.rb', line 6 def allowed_methods @allowed_methods end |
#path ⇒ Object
Returns the value of attribute path
6 7 8 |
# File 'lib/webmachine/describe_routes.rb', line 6 def path @path end |
#path_spec ⇒ Object
Returns the value of attribute path_spec
6 7 8 |
# File 'lib/webmachine/describe_routes.rb', line 6 def path_spec @path_spec end |
#policy_class ⇒ Object
Returns the value of attribute policy_class
6 7 8 |
# File 'lib/webmachine/describe_routes.rb', line 6 def policy_class @policy_class end |
#resource_class ⇒ Object
Returns the value of attribute resource_class
6 7 8 |
# File 'lib/webmachine/describe_routes.rb', line 6 def resource_class @resource_class end |
#resource_class_location ⇒ Object
Returns the value of attribute resource_class_location
6 7 8 |
# File 'lib/webmachine/describe_routes.rb', line 6 def resource_class_location @resource_class_location end |
#resource_name ⇒ Object
Returns the value of attribute resource_name
6 7 8 |
# File 'lib/webmachine/describe_routes.rb', line 6 def resource_name @resource_name end |
Instance Method Details
#[](key) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/webmachine/describe_routes.rb', line 16 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.
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) ) 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
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 |