class Bundler::Settings::Validator::Rule
Attributes
description[R]
Public Class Methods
# File lib/bundler/settings/validator.rb, line 9 def initialize(keys, description, &validate) @keys = keys @description = description @validate = validate end
Public Instance Methods
# 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 # File lib/bundler/settings/validator.rb, line 36 def k(key) Bundler.settings.key_for(key) end
# 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 # File lib/bundler/settings/validator.rb, line 15 def validate!(key, value, settings) instance_exec(key, value, settings, &@validate) end
Ruby Core © 1993–2017 Yukihiro Matsumoto
Licensed under the Ruby License.
Ruby Standard Library © contributors
Licensed under their own licenses.