Class: Apicraft::Config
- Inherits:
-
Object
- Object
- Apicraft::Config
- Defined in:
- lib/apicraft/config.rb
Overview
Configuration class for Apicraft.
This class provides a simple way to configure Apicraft’s behavior. It uses a hash-based configuration system, where default values can be overridden by user-provided options.
Constant Summary collapse
- DEFAULTS =
{ contracts_path: nil, headers: { response_code: "Apicraft-Response-Code", introspect: "Apicraft-Introspect", mock: "Apicraft-Mock", delay: "Apicraft-Delay", content_type: "Content-Type" }, mocks: true, introspection: true, strict_reference_validation: true, max_allowed_delay: 30, request_validation: { enabled: true, http_code: 400, response_body: proc { |ex| { message: ex. } } } }.with_indifferent_access
Instance Method Summary collapse
- #contracts_path ⇒ Object
- #contracts_path=(contracts_path) ⇒ Object
- #headers ⇒ Object
- #headers=(headers) ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #introspection ⇒ Object
- #introspection=(enabled) ⇒ Object
- #max_allowed_delay ⇒ Object
- #max_allowed_delay=(enabled) ⇒ Object
- #mocks ⇒ Object
- #mocks=(enabled) ⇒ Object
- #request_validation ⇒ Object
- #request_validation=(request_validation_opts) ⇒ Object
- #request_validation_enabled? ⇒ Boolean
- #request_validation_http_code ⇒ Object
- #request_validation_response_body ⇒ Object
- #strict_reference_validation ⇒ Object
- #strict_reference_validation=(enabled) ⇒ Object
Constructor Details
Instance Method Details
#contracts_path ⇒ Object
42 43 44 |
# File 'lib/apicraft/config.rb', line 42 def contracts_path @opts[:contracts_path] end |
#contracts_path=(contracts_path) ⇒ Object
74 75 76 |
# File 'lib/apicraft/config.rb', line 74 def contracts_path=(contracts_path) @opts[:contracts_path] = contracts_path end |
#headers ⇒ Object
34 35 36 |
# File 'lib/apicraft/config.rb', line 34 def headers @opts[:headers] end |
#headers=(headers) ⇒ Object
100 101 102 103 104 |
# File 'lib/apicraft/config.rb', line 100 def headers=(headers) @opts[:headers] = @opts[:headers].merge( headers.with_indifferent_access ) end |
#introspection ⇒ Object
50 51 52 |
# File 'lib/apicraft/config.rb', line 50 def introspection @opts[:introspection] end |
#introspection=(enabled) ⇒ Object
82 83 84 |
# File 'lib/apicraft/config.rb', line 82 def introspection=(enabled) @opts[:introspection] = enabled end |
#max_allowed_delay ⇒ Object
54 55 56 |
# File 'lib/apicraft/config.rb', line 54 def max_allowed_delay @opts[:max_allowed_delay] end |
#max_allowed_delay=(enabled) ⇒ Object
96 97 98 |
# File 'lib/apicraft/config.rb', line 96 def max_allowed_delay=(enabled) @opts[:max_allowed_delay] = enabled end |
#mocks ⇒ Object
46 47 48 |
# File 'lib/apicraft/config.rb', line 46 def mocks @opts[:mocks] end |
#mocks=(enabled) ⇒ Object
78 79 80 |
# File 'lib/apicraft/config.rb', line 78 def mocks=(enabled) @opts[:mocks] = enabled end |
#request_validation ⇒ Object
58 59 60 |
# File 'lib/apicraft/config.rb', line 58 def request_validation @opts[:request_validation] end |
#request_validation=(request_validation_opts) ⇒ Object
90 91 92 93 94 |
# File 'lib/apicraft/config.rb', line 90 def request_validation=(request_validation_opts) @opts[:request_validation] = @opts[:request_validation].merge( request_validation_opts.with_indifferent_access ) end |
#request_validation_enabled? ⇒ Boolean
62 63 64 |
# File 'lib/apicraft/config.rb', line 62 def request_validation_enabled? @opts[:request_validation][:enabled] end |
#request_validation_http_code ⇒ Object
66 67 68 |
# File 'lib/apicraft/config.rb', line 66 def request_validation_http_code @opts[:request_validation][:http_code] || DEFAULTS[:request_validation][:http_code] end |
#request_validation_response_body ⇒ Object
70 71 72 |
# File 'lib/apicraft/config.rb', line 70 def request_validation_response_body @opts[:request_validation][:response_body] end |
#strict_reference_validation ⇒ Object
38 39 40 |
# File 'lib/apicraft/config.rb', line 38 def strict_reference_validation @opts[:strict_reference_validation] end |
#strict_reference_validation=(enabled) ⇒ Object
86 87 88 |
# File 'lib/apicraft/config.rb', line 86 def strict_reference_validation=(enabled) @opts[:strict_reference_validation] = enabled end |