Class: PoolLint::AllowedSettings

Inherits:
Object
  • Object
show all
Defined in:
lib/poollint/allowed_settings.rb

Constant Summary collapse

UNCONFIGURED =
Object.new.freeze

Instance Method Summary collapse

Constructor Details

#initialize(rules) ⇒ AllowedSettings

Returns a new instance of AllowedSettings.



7
8
9
# File 'lib/poollint/allowed_settings.rb', line 7

def initialize(rules)
  @rules = normalize(rules)
end

Instance Method Details

#allow?(name, value) ⇒ Boolean

Returns:

  • (Boolean)


11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/poollint/allowed_settings.rb', line 11

def allow?(name, value)
  rule = @rules.fetch(name) { @rules.fetch(name.to_sym, UNCONFIGURED) }

  case rule
  when UNCONFIGURED then false
  when nil, true then true
  when Proc then rule.call(value)
  when Regexp then rule.match?(value.to_s)
  when Array then rule.include?(value)
  else rule == value
  end
end