Class: Pigeon::Configuration

Inherits:
Object
  • Object
show all
Extended by:
Dry::Configurable
Defined in:
lib/pigeon/configuration.rb

Overview

Configuration class for Pigeon using dry-configurable

Class Method Summary collapse

Class Method Details

.classify_error(error) ⇒ Symbol

Get the classification for an error

Parameters:

  • error (StandardError)

    Error instance

Returns:

  • (Symbol)

    Error classification (:transient, :permanent, :application, or :unknown)



150
151
152
153
154
155
156
157
158
# File 'lib/pigeon/configuration.rb', line 150

def classify_error(error)
  error_name = error.class.name

  config.error_classifications.each do |classification, error_classes|
    return classification if error_classes.include?(error_name)
  end

  :unknown
end

.register_error_classification(error_class, classification) ⇒ void

This method returns an undefined value.

Register an error class for a specific classification

Parameters:

  • error_class (String, Class)

    Error class name or class

  • classification (Symbol)

    Error classification (:transient, :permanent, :application)



141
142
143
144
145
# File 'lib/pigeon/configuration.rb', line 141

def register_error_classification(error_class, classification)
  error_name = error_class.is_a?(Class) ? error_class.name : error_class.to_s
  config.error_classifications[classification.to_sym] ||= []
  config.error_classifications[classification.to_sym] << error_name
end

.register_schema(name, schema) ⇒ void

This method returns an undefined value.

Register a JSON schema for validation

Parameters:

  • name (String, Symbol)

    Schema name

  • schema (Hash, String)

    JSON schema



112
113
114
# File 'lib/pigeon/configuration.rb', line 112

def register_schema(name, schema)
  config.schemas[name.to_sym] = schema
end

.register_sensitive_field(field) ⇒ void

This method returns an undefined value.

Register a sensitive field for masking

Parameters:

  • field (String, Symbol)

    Field name



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

def register_sensitive_field(field)
  config.sensitive_fields << field.to_sym unless config.sensitive_fields.include?(field.to_sym)
end

.register_sensitive_fields(fields) ⇒ void

This method returns an undefined value.

Register multiple sensitive fields for masking

Parameters:

  • fields (Array<String, Symbol>)

    Field names



133
134
135
# File 'lib/pigeon/configuration.rb', line 133

def register_sensitive_fields(fields)
  fields.each { |field| register_sensitive_field(field) }
end

.reset_configvoid

This method returns an undefined value.

Reset the configuration to default values



91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/pigeon/configuration.rb', line 91

def reset_config
  # For dry-configurable 1.x
  if respond_to?(:settings)
    settings.each_key do |key|
      config[key] = settings[key].default
    end
  # For dry-configurable 0.x
  elsif respond_to?(:config_option_definitions)
    config_option_definitions.each_key do |key|
      config[key] = config_option_definitions[key].default_value
    end
  else
    # Simplest approach - just create a new configuration
    @config = Dry::Configurable::Config.new
  end
end

.schema(name) ⇒ Hash, ...

Get a registered schema

Parameters:

  • name (String, Symbol)

    Schema name

Returns:

  • (Hash, String, nil)

    JSON schema or nil if not found



119
120
121
# File 'lib/pigeon/configuration.rb', line 119

def schema(name)
  config.schemas[name.to_sym]
end