Class: Sparrow::Steward

Inherits:
Object
  • Object
show all
Defined in:
lib/sparrow/steward.rb

Overview

TODO:

this class is requested to be removed by issue #7 in the feature and

Parses the http_mesage and provides information if it should be processed, i.e. if the content type or accept header is applicable

its internal will be moved to its counterparts such as HttpMessage itself.

Version:

  • 0.0.16

Direct Known Subclasses

ResponseSteward

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_message, options = {}) ⇒ Steward

Initialize the Steward with the HTTP message to check and the specific check options.

Options Hash (options):

  • :http_message (HttpMessage)

    the message to be checked

  • :allowed_accepts (Array<String>) — default: []

    List of HTTP Accept Header options

  • :allowed_content_types (Array<String>) — default: []

    List of HTTP Content Type Header options

  • :excluded_routes (Array<String,Regexp>) — default: []

    List of routes (paths) to not process (see Sparrow::Configuration#excluded_routes)

  • ignored_response_codes (Array<Integer>) — default: []

    (see Sparrow::Configuration#ignored_response_codes)

See Also:



56
57
58
59
60
61
62
63
# File 'lib/sparrow/steward.rb', line 56

def initialize(http_message, options = {})
  @http_message           = http_message
  @allowed_accepts        = options.fetch(:allowed_accepts, [])
  @allowed_content_types  = options.fetch(:allowed_content_types, [])
  @excluded_routes        = options.fetch(:excluded_routes, [])
  @ignored_response_codes = options.fetch(:ignored_response_codes, [])
  @route_parser           = RouteParser.new(excluded_routes)
end

Instance Attribute Details

#allowed_acceptsArray<String> (readonly)



17
18
19
# File 'lib/sparrow/steward.rb', line 17

def allowed_accepts
  @allowed_accepts
end

#allowed_content_typesArray<String> (readonly)



22
23
24
# File 'lib/sparrow/steward.rb', line 22

def allowed_content_types
  @allowed_content_types
end

#excluded_routesArray<String,Regexp> (readonly)



27
28
29
# File 'lib/sparrow/steward.rb', line 27

def excluded_routes
  @excluded_routes
end

#http_messageHttpMessage (readonly)



12
13
14
# File 'lib/sparrow/steward.rb', line 12

def http_message
  @http_message
end

#ignored_response_codesArray<Integer> (readonly)



32
33
34
# File 'lib/sparrow/steward.rb', line 32

def ignored_response_codes
  @ignored_response_codes
end

#route_parserRouteParser (readonly)

Returns the route parser for the #excluded_routes.

See Also:



37
38
39
# File 'lib/sparrow/steward.rb', line 37

def route_parser
  @route_parser
end

Instance Method Details

#has_processable_http_message?Boolean

Checks the http_message against any given criteria specified by the options within the constructor



70
71
72
73
74
# File 'lib/sparrow/steward.rb', line 70

def has_processable_http_message?
  includes_route? &&
      allowed_content_type? &&
      allowed_accept_header?
end