Class: Canon::Config::EnvSchema

Inherits:
Object
  • Object
show all
Defined in:
lib/canon/config/env_schema.rb

Overview

Schema definition for configuration attributes.

Diff attribute types and names are derived lazily from Canon::Config::DiffConfig.config_keys (the single source of truth declared via ConfigDSL). Match and Format attribute types are declared here because those config classes do not yet use the DSL.

The lookup is intentionally lazy so that EnvSchema can be loaded before DiffConfig is defined — the methods are only called once a DiffConfig instance is being built, by which time the DSL registry is populated.

Constant Summary collapse

MATCH_ATTRIBUTE_TYPES =
{
  profile: :symbol,
}.freeze
FORMAT_ATTRIBUTE_TYPES =
{
  preprocessing: :string,
}.freeze

Class Method Summary collapse

Class Method Details

.all_diff_attributesArray<Symbol>

All diff attributes declared via ConfigDSL on DiffConfig.

Returns:

  • (Array<Symbol>)


43
44
45
# File 'lib/canon/config/env_schema.rb', line 43

def all_diff_attributes
  diff_config_keys.keys
end

.all_format_attributesArray<Symbol>

Format attributes subject to ENV override.

Returns:

  • (Array<Symbol>)


59
60
61
# File 'lib/canon/config/env_schema.rb', line 59

def all_format_attributes
  %i[preprocessing]
end

.all_match_attributesArray<Symbol>

Match attributes subject to ENV override.

Returns:

  • (Array<Symbol>)


50
51
52
53
54
# File 'lib/canon/config/env_schema.rb', line 50

def all_match_attributes
  %i[profile
     preserve_whitespace_elements collapse_whitespace_elements
     strip_whitespace_elements]
end

.env_key(format, config_type, attribute) ⇒ Object



32
33
34
# File 'lib/canon/config/env_schema.rb', line 32

def env_key(format, config_type, attribute)
  "CANON_#{format.to_s.upcase}_#{config_type.to_s.upcase}_#{attribute.to_s.upcase}"
end

.global_env_key(attribute) ⇒ Object



36
37
38
# File 'lib/canon/config/env_schema.rb', line 36

def global_env_key(attribute)
  "CANON_#{attribute.to_s.upcase}"
end

.type_for(attribute) ⇒ Object



27
28
29
30
# File 'lib/canon/config/env_schema.rb', line 27

def type_for(attribute)
  key = attribute.to_sym
  diff_type(key) || match_type(key) || format_type(key)
end