Class: PgCanary::RuleConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/pg_canary/configuration.rb

Overview

Per-rule settings. enabled / severity default to nil, meaning "use the rule class's default". Accessors for rule-specific options (e.g. config.rules.deep_offset.threshold = 2000) are generated from the rule class's declared options, so a typo raises NoMethodError instead of silently creating a setting nobody reads.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(option_defaults = {}) ⇒ RuleConfig

Returns a new instance of RuleConfig.



55
56
57
58
59
60
61
# File 'lib/pg_canary/configuration.rb', line 55

def initialize(option_defaults = {})
  @options = option_defaults.dup
  @options.each_key do |name|
    define_singleton_method(name) { @options[name] }
    define_singleton_method(:"#{name}=") { |value| @options[name] = value }
  end
end

Instance Attribute Details

#enabledObject

Returns the value of attribute enabled.



53
54
55
# File 'lib/pg_canary/configuration.rb', line 53

def enabled
  @enabled
end

#severityObject

Returns the value of attribute severity.



53
54
55
# File 'lib/pg_canary/configuration.rb', line 53

def severity
  @severity
end

Instance Method Details

#[](key) ⇒ Object



63
64
65
# File 'lib/pg_canary/configuration.rb', line 63

def [](key)
  @options.fetch(key.to_sym)
end