Class: Canon::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/canon/config.rb,
lib/canon/config/config_dsl.rb,
lib/canon/config/env_schema.rb,
lib/canon/config/env_provider.rb,
lib/canon/config/profile_loader.rb,
lib/canon/config/type_converter.rb,
lib/canon/config/override_resolver.rb

Overview

Global configuration for Canon Provides unified configuration across CLI, Ruby API, and RSpec interfaces

Defined Under Namespace

Modules: ConfigDSL Classes: DiffConfig, EnvProvider, EnvSchema, FormatConfig, MatchConfig, OverrideResolver, PrettyPrinterConfig, ProfileLoader, TypeConverter

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/canon/config.rb', line 48

def initialize
  @xml = FormatConfig.new(:xml)
  @html = FormatConfig.new(:html)
  @json = FormatConfig.new(:json)
  @yaml = FormatConfig.new(:yaml)
  @string = FormatConfig.new(:string)
  @profile = nil

  env_profile = ENV.fetch("CANON_CONFIG_PROFILE", nil)
  if env_profile
    # Convert to symbol if it matches a built-in profile name
    self.profile = if ProfileLoader.available_profiles.include?(env_profile.to_sym)
                     env_profile.to_sym
                   else
                     env_profile
                   end
  end
end

Instance Attribute Details

#htmlObject (readonly)

Returns the value of attribute html.



46
47
48
# File 'lib/canon/config.rb', line 46

def html
  @html
end

#jsonObject (readonly)

Returns the value of attribute json.



46
47
48
# File 'lib/canon/config.rb', line 46

def json
  @json
end

#stringObject (readonly)

Returns the value of attribute string.



46
47
48
# File 'lib/canon/config.rb', line 46

def string
  @string
end

#xmlObject (readonly)

Returns the value of attribute xml.



46
47
48
# File 'lib/canon/config.rb', line 46

def xml
  @xml
end

#yamlObject (readonly)

Returns the value of attribute yaml.



46
47
48
# File 'lib/canon/config.rb', line 46

def yaml
  @yaml
end

Class Method Details

.configure {|instance| ... } ⇒ Object

Yields:



19
20
21
22
# File 'lib/canon/config.rb', line 19

def configure
  yield instance if block_given?
  instance
end

.instanceObject



15
16
17
# File 'lib/canon/config.rb', line 15

def instance
  @instance ||= new
end

.method_missing(method) ⇒ Object

Delegate to instance



29
30
31
32
33
34
35
36
37
# File 'lib/canon/config.rb', line 29

def method_missing(method, ...)
  if %i[xml html json yaml string profile profile= diff_mode diff_mode=
        use_color use_color= xml_match_profile xml_match_profile=
        html_match_profile html_match_profile= reset!].include?(method)
    @instance.public_send(method, ...)
  else
    super
  end
end

.reset!Object



24
25
26
# File 'lib/canon/config.rb', line 24

def reset!
  @instance = new
end

.respond_to_missing?(method, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
42
43
# File 'lib/canon/config.rb', line 39

def respond_to_missing?(method, include_private = false)
  %i[xml html json yaml string profile profile= diff_mode diff_mode=
     use_color use_color= xml_match_profile xml_match_profile=
     html_match_profile html_match_profile= reset!].include?(method) || super
end

Instance Method Details

#diff_modeObject

Backward compatibility methods for top-level diff configuration These delegate to XML diff config for backward compatibility



97
98
99
# File 'lib/canon/config.rb', line 97

def diff_mode
  @xml.diff.mode
end

#diff_mode=(value) ⇒ Object



101
102
103
# File 'lib/canon/config.rb', line 101

def diff_mode=(value)
  @xml.diff.mode = value
end

#html_match_profileObject



122
123
124
# File 'lib/canon/config.rb', line 122

def html_match_profile
  @html.match.profile
end

#html_match_profile=(value) ⇒ Object



126
127
128
# File 'lib/canon/config.rb', line 126

def html_match_profile=(value)
  @html.match.profile = value
end

#profileObject

Returns the current profile name or path.



68
69
70
# File 'lib/canon/config.rb', line 68

def profile
  @profile
end

#profile=(name_or_path) ⇒ Object

Apply a configuration profile by name (Symbol for built-in) or file path (String). Set to nil to clear the profile layer.



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/canon/config.rb', line 74

def profile=(name_or_path)
  clear_profile_values!

  if name_or_path.nil?
    @profile = nil
    return
  end

  @profile = name_or_path.is_a?(Symbol) ? name_or_path : name_or_path.to_s
  apply_profile(@profile)
end

#reset!Object



86
87
88
89
90
91
92
93
# File 'lib/canon/config.rb', line 86

def reset!
  @xml.reset!
  @html.reset!
  @json.reset!
  @yaml.reset!
  @string.reset!
  @profile = nil
end

#use_colorObject



105
106
107
# File 'lib/canon/config.rb', line 105

def use_color
  @xml.diff.use_color
end

#use_color=(value) ⇒ Object



109
110
111
# File 'lib/canon/config.rb', line 109

def use_color=(value)
  @xml.diff.use_color = value
end

#xml_match_profileObject

Backward compatibility methods for match profile configuration



114
115
116
# File 'lib/canon/config.rb', line 114

def xml_match_profile
  @xml.match.profile
end

#xml_match_profile=(value) ⇒ Object



118
119
120
# File 'lib/canon/config.rb', line 118

def xml_match_profile=(value)
  @xml.match.profile = value
end