Class: Bundler::Settings::Validator::Rule
- Inherits:
-
Object
- Object
- Bundler::Settings::Validator::Rule
- Defined in:
- lib/bundler/settings/validator.rb
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
Instance Method Summary collapse
- #fail!(key, value, *reasons) ⇒ Object
-
#initialize(keys, description, &validate) ⇒ Rule
constructor
A new instance of Rule.
- #k(key) ⇒ Object
- #set(settings, key, value, *reasons) ⇒ Object
- #validate!(key, value, settings) ⇒ Object
Constructor Details
#initialize(keys, description, &validate) ⇒ Rule
Returns a new instance of Rule.
9 10 11 12 13 |
# File 'lib/bundler/settings/validator.rb', line 9 def initialize(keys, description, &validate) @keys = keys @description = description @validate = validate end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
7 8 9 |
# File 'lib/bundler/settings/validator.rb', line 7 def description @description end |
Instance Method Details
#fail!(key, value, *reasons) ⇒ Object
19 20 21 22 |
# File 'lib/bundler/settings/validator.rb', line 19 def fail!(key, value, *reasons) reasons.unshift @description raise InvalidOption, "Setting `#{key}` to #{value.inspect} failed:\n#{reasons.map {|r| " - #{r}" }.join("\n")}" end |
#k(key) ⇒ Object
36 37 38 |
# File 'lib/bundler/settings/validator.rb', line 36 def k(key) Bundler.settings.key_for(key) end |
#set(settings, key, value, *reasons) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/bundler/settings/validator.rb', line 24 def set(settings, key, value, *reasons) hash_key = k(key) return if settings[hash_key] == value reasons.unshift @description Bundler.ui.info "Setting `#{key}` to #{value.inspect}, since #{reasons.join(", ")}" if value.nil? settings.delete(hash_key) else settings[hash_key] = value end end |
#validate!(key, value, settings) ⇒ Object
15 16 17 |
# File 'lib/bundler/settings/validator.rb', line 15 def validate!(key, value, settings) instance_exec(key, value, settings, &@validate) end |