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



8
9
10
# File 'lib/webmachine/describe_routes.rb', line 8

def allowed_methods
  @allowed_methods
end

#pathObject

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



8
9
10
# File 'lib/webmachine/describe_routes.rb', line 8

def path
  @path
end

#path_specObject

Returns the value of attribute path_spec

Returns:

  • (Object)

    the current value of path_spec



8
9
10
# File 'lib/webmachine/describe_routes.rb', line 8

def path_spec
  @path_spec
end

#policy_classObject

Returns the value of attribute policy_class

Returns:

  • (Object)

    the current value of policy_class



8
9
10
# File 'lib/webmachine/describe_routes.rb', line 8

def policy_class
  @policy_class
end

#resource_classObject

Returns the value of attribute resource_class

Returns:

  • (Object)

    the current value of resource_class



8
9
10
# File 'lib/webmachine/describe_routes.rb', line 8

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



8
9
10
# File 'lib/webmachine/describe_routes.rb', line 8

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



8
9
10
# File 'lib/webmachine/describe_routes.rb', line 8

def resource_name
  @resource_name
end

#schemasObject

Returns the value of attribute schemas

Returns:

  • (Object)

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

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



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

Returns:

  • (Boolean)


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

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

#route_param_namesObject



31
32
33
# File 'lib/webmachine/describe_routes.rb', line 31

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