Class: Pigeon::Configuration
- Inherits:
-
Object
- Object
- Pigeon::Configuration
- Extended by:
- Dry::Configurable
- Defined in:
- lib/pigeon/configuration.rb
Overview
Configuration class for Pigeon using dry-configurable
Class Method Summary collapse
-
.classify_error(error) ⇒ Symbol
Get the classification for an error.
-
.register_error_classification(error_class, classification) ⇒ void
Register an error class for a specific classification.
-
.register_schema(name, schema) ⇒ void
Register a JSON schema for validation.
-
.register_sensitive_field(field) ⇒ void
Register a sensitive field for masking.
-
.register_sensitive_fields(fields) ⇒ void
Register multiple sensitive fields for masking.
-
.reset_config ⇒ void
Reset the configuration to default values.
-
.schema(name) ⇒ Hash, ...
Get a registered schema.
Class Method Details
.classify_error(error) ⇒ Symbol
Get the classification for an error
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
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
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
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
133 134 135 |
# File 'lib/pigeon/configuration.rb', line 133 def register_sensitive_fields(fields) fields.each { |field| register_sensitive_field(field) } end |
.reset_config ⇒ void
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
119 120 121 |
# File 'lib/pigeon/configuration.rb', line 119 def schema(name) config.schemas[name.to_sym] end |