Class: Apicraft::Config

Inherits:
Object
  • Object
show all
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.message } }
  }
}.with_indifferent_access

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



30
31
32
# File 'lib/apicraft/config.rb', line 30

def initialize
  @opts = DEFAULTS
end

Instance Method Details

#contracts_pathObject



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

#headersObject



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

#introspectionObject



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_delayObject



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

#mocksObject



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_validationObject



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

Returns:

  • (Boolean)


62
63
64
# File 'lib/apicraft/config.rb', line 62

def request_validation_enabled?
  @opts[:request_validation][:enabled]
end

#request_validation_http_codeObject



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_bodyObject



70
71
72
# File 'lib/apicraft/config.rb', line 70

def request_validation_response_body
  @opts[:request_validation][:response_body]
end

#strict_reference_validationObject



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