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.



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/canon/config.rb', line 42

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.



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

def html
  @html
end

#jsonObject (readonly)

Returns the value of attribute json.



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

def json
  @json
end

#stringObject (readonly)

Returns the value of attribute string.



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

def string
  @string
end

#xmlObject (readonly)

Returns the value of attribute xml.



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

def xml
  @xml
end

#yamlObject (readonly)

Returns the value of attribute yaml.



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

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
# File 'lib/canon/config.rb', line 27

def method_missing(method, ...)
  if @instance.respond_to?(method)
    @instance.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)


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

def respond_to_missing?(method, include_private = false)
  @instance.respond_to?(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



91
92
93
# File 'lib/canon/config.rb', line 91

def diff_mode
  @xml.diff.mode
end

#diff_mode=(value) ⇒ Object



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

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

#html_match_profileObject



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

def html_match_profile
  @html.match.profile
end

#html_match_profile=(value) ⇒ Object



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

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

#profileObject

Returns the current profile name or path.



62
63
64
# File 'lib/canon/config.rb', line 62

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.



68
69
70
71
72
73
74
75
76
77
78
# File 'lib/canon/config.rb', line 68

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



80
81
82
83
84
85
86
87
# File 'lib/canon/config.rb', line 80

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

#use_colorObject



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

def use_color
  @xml.diff.use_color
end

#use_color=(value) ⇒ Object



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

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

#xml_match_profileObject

Backward compatibility methods for match profile configuration



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

def xml_match_profile
  @xml.match.profile
end

#xml_match_profile=(value) ⇒ Object



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

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