Class: Interpol::Configuration

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

Overview

Public: Defines interpol configuration.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|_self| ... } ⇒ Configuration

Returns a new instance of Configuration.

Yields:

  • (_self)

Yield Parameters:



42
43
44
45
46
47
48
49
50
51
# File 'lib/interpol/configuration.rb', line 42

def initialize
  self.endpoint_definition_files = []
  self.endpoint_definition_merge_key_files = []
  self.documentation_title = "API Documentation Provided by Interpol"
  register_default_callbacks
  register_built_in_param_parsers
  @filter_example_data_blocks = []

  yield self if block_given?
end

Instance Attribute Details

#documentation_titleObject

Returns the value of attribute documentation_title.



40
41
42
# File 'lib/interpol/configuration.rb', line 40

def documentation_title
  @documentation_title
end

#endpoint_definition_filesObject

Returns the value of attribute endpoint_definition_files.



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

def endpoint_definition_files
  @endpoint_definition_files
end

#endpoint_definition_merge_key_filesObject

Returns the value of attribute endpoint_definition_merge_key_files.



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

def endpoint_definition_merge_key_files
  @endpoint_definition_merge_key_files
end

#endpointsObject

Returns the value of attribute endpoints.



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

def endpoints
  @endpoints
end

#filter_example_data_blocksObject (readonly)

Returns the value of attribute filter_example_data_blocks.



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

def filter_example_data_blocks
  @filter_example_data_blocks
end

#validation_modeObject

Returns the value of attribute validation_mode.



40
41
42
# File 'lib/interpol/configuration.rb', line 40

def validation_mode
  @validation_mode
end

Class Method Details

.defaultObject



180
181
182
# File 'lib/interpol/configuration.rb', line 180

def self.default
  @default ||= Configuration.new
end

Instance Method Details

#api_version(version = nil, &block) ⇒ Object



90
91
92
93
94
95
96
97
# File 'lib/interpol/configuration.rb', line 90

def api_version(version=nil, &block)
  warn "WARNING: Interpol's #api_version config option is deprecated. " +
       "Instead, use separate #request_version and #response_version " +
       "config options."

  request_version(version, &block)
  response_version(version, &block)
end

#customized_duplicate(&block) ⇒ Object



184
185
186
187
188
189
190
191
192
# File 'lib/interpol/configuration.rb', line 184

def customized_duplicate(&block)
  # ensure our endpoints our loaded; if they are not, they could be loaded
  # a separate time by each interpol tool (when it uses this method) and
  # that would be slow.
  endpoints

  block ||= lambda { |c| }
  dup.tap(&block)
end

#define_request_param_parser(type, options = {}, &block) ⇒ Object



194
195
196
197
198
199
# File 'lib/interpol/configuration.rb', line 194

def define_request_param_parser(type, options = {}, &block)
  ParamParser.new(type, options, &block).tap do |parser|
    # Use unshift so that new parsers take precedence over older ones.
    param_parsers[type].unshift parser
  end
end

#example_response_for(endpoint_def, env) ⇒ Object



166
167
168
169
# File 'lib/interpol/configuration.rb', line 166

def example_response_for(endpoint_def, env)
  selector = named_example_selectors[endpoint_def.endpoint_name]
  selector.call(endpoint_def, env)
end

#filter_example_data(&block) ⇒ Object



154
155
156
# File 'lib/interpol/configuration.rb', line 154

def filter_example_data(&block)
  filter_example_data_blocks << block
end

#on_invalid_request_body(&block) ⇒ Object



146
147
148
# File 'lib/interpol/configuration.rb', line 146

def on_invalid_request_body(&block)
  @invalid_request_body_block = block
end

#on_invalid_sinatra_request_params(&block) ⇒ Object



138
139
140
# File 'lib/interpol/configuration.rb', line 138

def on_invalid_sinatra_request_params(&block)
  @invalid_sinatra_request_params_block = block
end

#on_unavailable_request_version(&block) ⇒ Object



130
131
132
# File 'lib/interpol/configuration.rb', line 130

def on_unavailable_request_version(&block)
  @unavailable_request_version_block = block
end

#on_unavailable_sinatra_request_version(&block) ⇒ Object



122
123
124
# File 'lib/interpol/configuration.rb', line 122

def on_unavailable_sinatra_request_version(&block)
  @unavailable_sinatra_request_version_block = block
end

#param_parser_for(type, options) ⇒ Object



201
202
203
204
205
206
207
208
209
# File 'lib/interpol/configuration.rb', line 201

def param_parser_for(type, options)
  match = param_parsers[type].find do |parser|
    parser.matches_options?(options)
  end

  return match if match

  raise UnsupportedTypeError.new(type, options)
end

#request_body_invalid(*args) ⇒ Object



150
151
152
# File 'lib/interpol/configuration.rb', line 150

def request_body_invalid(*args)
  @invalid_request_body_block.call(*args)
end

#request_version_unavailable(*args) ⇒ Object



134
135
136
# File 'lib/interpol/configuration.rb', line 134

def request_version_unavailable(*args)
  @unavailable_request_version_block.call(*args)
end

#scalars_nullable_by_default=(value) ⇒ Object



171
172
173
174
# File 'lib/interpol/configuration.rb', line 171

def scalars_nullable_by_default=(value)
  @endpoints = nil
  @scalars_nullable_by_default = value
end

#scalars_nullable_by_default?Boolean

Returns:

  • (Boolean)


176
177
178
# File 'lib/interpol/configuration.rb', line 176

def scalars_nullable_by_default?
  @scalars_nullable_by_default
end

#select_example_response(endpoint_name = nil, &block) ⇒ Object



158
159
160
161
162
163
164
# File 'lib/interpol/configuration.rb', line 158

def select_example_response(endpoint_name = nil, &block)
  if endpoint_name
    named_example_selectors[endpoint_name] = block
  else
    named_example_selectors.default = block
  end
end

#sinatra_request_params_invalid(execution_context, *args) ⇒ Object



142
143
144
# File 'lib/interpol/configuration.rb', line 142

def sinatra_request_params_invalid(execution_context, *args)
  execution_context.instance_exec(*args, &@invalid_sinatra_request_params_block)
end

#sinatra_request_version_unavailable(execution_context, *args) ⇒ Object



126
127
128
# File 'lib/interpol/configuration.rb', line 126

def sinatra_request_version_unavailable(execution_context, *args)
  execution_context.instance_exec(*args, &@unavailable_sinatra_request_version_block)
end

#validate_if(&block) ⇒ Object



107
108
109
110
111
112
# File 'lib/interpol/configuration.rb', line 107

def validate_if(&block)
  warn "WARNING: Interpol's #validate_if config option is deprecated. " +
       "Instead, use #validate_response_if."

  validate_response_if(&block)
end

#validate_request?(env) ⇒ Boolean

Returns:

  • (Boolean)


114
115
116
# File 'lib/interpol/configuration.rb', line 114

def validate_request?(env)
  @validate_request_if_block.call(env)
end

#validate_request_if(&block) ⇒ Object



118
119
120
# File 'lib/interpol/configuration.rb', line 118

def validate_request_if(&block)
  @validate_request_if_block = block
end

#validate_response?(*args) ⇒ Boolean

Returns:

  • (Boolean)


103
104
105
# File 'lib/interpol/configuration.rb', line 103

def validate_response?(*args)
  @validate_response_if_block.call(*args)
end

#validate_response_if(&block) ⇒ Object



99
100
101
# File 'lib/interpol/configuration.rb', line 99

def validate_response_if(&block)
  @validate_response_if_block = block
end