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,

  # Rebaseliner: opt-in mode that rewrites failing heredoc
  # expectations in spec files with the prettyprinted received
  # value. Read directly by Canon::Rebaseliner.enabled?; schema
  # entry exists for --env-help discoverability.
  regenerate_expected: :boolean,
}.freeze

Class Method Summary collapse

Class Method Details

.all_diff_attributesArray<Symbol>

All diff attributes declared via ConfigDSL on DiffConfig.

Returns:

  • (Array<Symbol>)


49
50
51
# File 'lib/canon/config/env_schema.rb', line 49

def all_diff_attributes
  diff_config_keys.keys
end

.all_format_attributesArray<Symbol>

Format attributes subject to ENV override.

Returns:

  • (Array<Symbol>)


65
66
67
# File 'lib/canon/config/env_schema.rb', line 65

def all_format_attributes
  i[preprocessing]
end

.all_match_attributesArray<Symbol>

Match attributes subject to ENV override.

Returns:

  • (Array<Symbol>)


56
57
58
59
60
# File 'lib/canon/config/env_schema.rb', line 56

def all_match_attributes
  i[profile
     preserve_whitespace_elements collapse_whitespace_elements
     strip_whitespace_elements]
end

.env_key(format, config_type, attribute) ⇒ Object



38
39
40
# File 'lib/canon/config/env_schema.rb', line 38

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



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

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

.type_for(attribute) ⇒ Object



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

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