Class: Sparrow::Configuration

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

Overview

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Initializes a new Configuration with default parameters



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/sparrow/configuration.rb', line 19

def initialize
  @enable_logging                                    = false
  @json_request_format_header                        = 'request-json-format'
  @json_response_format_header                       = 'response-json-format'
  @excluded_routes                                   = []
  @default_json_request_key_transformation_strategy  = :underscore
  @default_json_response_key_transformation_strategy = :camelize
  @camelize_ignore_uppercase_keys                    = true
  @allowed_content_types                             = %w[
    application/json
    application/x-www-form-urlencoded
    text/x-json
  ]

  @allowed_accepts        = @allowed_content_types + [nil]
  @ignored_response_codes = [404] + (500..511).to_a
  @camelize_strategy      = :lower
end

Instance Attribute Details

#allowed_acceptsObject

Returns the value of attribute allowed_accepts.



5
6
7
# File 'lib/sparrow/configuration.rb', line 5

def allowed_accepts
  @allowed_accepts
end

#allowed_content_typesObject

Returns the value of attribute allowed_content_types.



5
6
7
# File 'lib/sparrow/configuration.rb', line 5

def allowed_content_types
  @allowed_content_types
end

#camelize_ignore_uppercase_keysObject

Returns the value of attribute camelize_ignore_uppercase_keys.



5
6
7
# File 'lib/sparrow/configuration.rb', line 5

def camelize_ignore_uppercase_keys
  @camelize_ignore_uppercase_keys
end

#camelize_strategyObject

Returns the value of attribute camelize_strategy.



5
6
7
# File 'lib/sparrow/configuration.rb', line 5

def camelize_strategy
  @camelize_strategy
end

#default_json_request_key_transformation_strategyObject

Returns the value of attribute default_json_request_key_transformation_strategy.



5
6
7
# File 'lib/sparrow/configuration.rb', line 5

def default_json_request_key_transformation_strategy
  @default_json_request_key_transformation_strategy
end

#default_json_response_key_transformation_strategyObject

Returns the value of attribute default_json_response_key_transformation_strategy.



5
6
7
# File 'lib/sparrow/configuration.rb', line 5

def default_json_response_key_transformation_strategy
  @default_json_response_key_transformation_strategy
end

#enable_loggingObject

Returns the value of attribute enable_logging.



5
6
7
# File 'lib/sparrow/configuration.rb', line 5

def enable_logging
  @enable_logging
end

#excluded_routesObject

Returns the value of attribute excluded_routes.



5
6
7
# File 'lib/sparrow/configuration.rb', line 5

def excluded_routes
  @excluded_routes
end

#ignored_response_codesObject

Returns the value of attribute ignored_response_codes.



5
6
7
# File 'lib/sparrow/configuration.rb', line 5

def ignored_response_codes
  @ignored_response_codes
end

#json_request_format_headerObject

Returns the value of attribute json_request_format_header.



5
6
7
# File 'lib/sparrow/configuration.rb', line 5

def json_request_format_header
  @json_request_format_header
end

#json_response_format_headerObject

Returns the value of attribute json_response_format_header.



5
6
7
# File 'lib/sparrow/configuration.rb', line 5

def json_response_format_header
  @json_response_format_header
end

Instance Method Details

#active_support_legacy_versionObject



38
39
40
# File 'lib/sparrow/configuration.rb', line 38

def active_support_legacy_version
  /3\.\d+\.\d+/
end

#default_json_key_transformation_strategy(type) ⇒ String

the default json_key_transformation_strategy option for the given http message type

Parameters:

  • type (String)

    http message type. Must be either ‘request’ or ‘response’

Returns:

  • (String)

    the configuration option value



57
58
59
# File 'lib/sparrow/configuration.rb', line 57

def default_json_key_transformation_strategy(type)
  public_send("default_json_#{type}_key_transformation_strategy")
end

#json_format_header(type) ⇒ String

Returns the configuration value for the json_format_header for the given http message type.

Parameters:

  • type (String)

    the http message type. Must be either ‘request’ or ‘response’.

Returns:

  • (String)

    the configuration value for the json_format_header for the given http message type



47
48
49
# File 'lib/sparrow/configuration.rb', line 47

def json_format_header(type)
  public_send("json_#{type}_format_header")
end