Class: Webmachine::DescribeRoutes::Route

Inherits:
Struct
  • Object
show all
Defined in:
lib/webmachine/describe_routes.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#allowed_methodsObject

Returns the value of attribute allowed_methods

Returns:

  • (Object)

    the current value of allowed_methods



12
13
14
# File 'lib/webmachine/describe_routes.rb', line 12

def allowed_methods
  @allowed_methods
end

#pathObject

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



12
13
14
# File 'lib/webmachine/describe_routes.rb', line 12

def path
  @path
end

#path_specObject

Returns the value of attribute path_spec

Returns:

  • (Object)

    the current value of path_spec



12
13
14
# File 'lib/webmachine/describe_routes.rb', line 12

def path_spec
  @path_spec
end

#policy_classesObject

Returns the value of attribute policy_classes

Returns:

  • (Object)

    the current value of policy_classes



12
13
14
# File 'lib/webmachine/describe_routes.rb', line 12

def policy_classes
  @policy_classes
end

#policy_namesObject

Returns the value of attribute policy_names

Returns:

  • (Object)

    the current value of policy_names



12
13
14
# File 'lib/webmachine/describe_routes.rb', line 12

def policy_names
  @policy_names
end

#resource_classObject

Returns the value of attribute resource_class

Returns:

  • (Object)

    the current value of resource_class



12
13
14
# File 'lib/webmachine/describe_routes.rb', line 12

def resource_class
  @resource_class
end

#resource_class_locationObject

Returns the value of attribute resource_class_location

Returns:

  • (Object)

    the current value of resource_class_location



12
13
14
# File 'lib/webmachine/describe_routes.rb', line 12

def resource_class_location
  @resource_class_location
end

#resource_nameObject

Returns the value of attribute resource_name

Returns:

  • (Object)

    the current value of resource_name



12
13
14
# File 'lib/webmachine/describe_routes.rb', line 12

def resource_name
  @resource_name
end

#schemasObject

Returns the value of attribute schemas

Returns:

  • (Object)

    the current value of 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.

Parameters:

  • env (Hash)

    the rack env from which to build the request

  • application_context (PactBroker::ApplicationContext)

    the application context

  • path_param_values (Hash)

    concrete parameter values from which to construct the path

Returns:

  • (Webmachine::Resource)

    the webmachine resource for the request



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

Returns:

  • (Boolean)


24
25
26
# File 'lib/webmachine/describe_routes.rb', line 24

def path_include?(component)
  path.include?(component)
end

#route_param_namesObject



28
29
30
# File 'lib/webmachine/describe_routes.rb', line 28

def route_param_names
  path_spec.select { | component | component.is_a?(Symbol) }
end