Class: Canon::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/canon/config.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

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.



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

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.



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

def html
  @html
end

#jsonObject (readonly)

Returns the value of attribute json.



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

def json
  @json
end

#stringObject (readonly)

Returns the value of attribute string.



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

def string
  @string
end

#xmlObject (readonly)

Returns the value of attribute xml.



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

def xml
  @xml
end

#yamlObject (readonly)

Returns the value of attribute yaml.



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

def yaml
  @yaml
end

Class Method Details

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

Yields:



17
18
19
20
# File 'lib/canon/config.rb', line 17

def configure
  yield instance if block_given?
  instance
end

.instanceObject



13
14
15
# File 'lib/canon/config.rb', line 13

def instance
  @instance ||= new
end

.method_missing(method) ⇒ Object

Delegate to instance



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

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



22
23
24
# File 'lib/canon/config.rb', line 22

def reset!
  @instance = new
end

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

Returns:

  • (Boolean)


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

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



95
96
97
# File 'lib/canon/config.rb', line 95

def diff_mode
  @xml.diff.mode
end

#diff_mode=(value) ⇒ Object



99
100
101
# File 'lib/canon/config.rb', line 99

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

#html_match_profileObject



120
121
122
# File 'lib/canon/config.rb', line 120

def html_match_profile
  @html.match.profile
end

#html_match_profile=(value) ⇒ Object



124
125
126
# File 'lib/canon/config.rb', line 124

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

#profileObject

Returns the current profile name or path.



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

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.



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

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



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

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

#use_colorObject



103
104
105
# File 'lib/canon/config.rb', line 103

def use_color
  @xml.diff.use_color
end

#use_color=(value) ⇒ Object



107
108
109
# File 'lib/canon/config.rb', line 107

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

#xml_match_profileObject

Backward compatibility methods for match profile configuration



112
113
114
# File 'lib/canon/config.rb', line 112

def xml_match_profile
  @xml.match.profile
end

#xml_match_profile=(value) ⇒ Object



116
117
118
# File 'lib/canon/config.rb', line 116

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