class Bundler::Settings::Validator::Rule

Attributes

description[R]

Public Class Methods

new(keys, description, &validate) click to toggle source
# File lib/bundler/settings/validator.rb, line 9
def initialize(keys, description, &validate)
  @keys = keys
  @description = description
  @validate = validate
end
validate!(key, value, settings) click to toggle source
# File lib/bundler/settings/validator.rb, line 52
def self.validate!(key, value, settings)
  rules_to_validate = rules[key]
  rules_to_validate.each {|rule| rule.validate!(key, value, settings) }
end

Private Class Methods

rule(keys, description, &blk) click to toggle source
# File lib/bundler/settings/validator.rb, line 46
def self.rule(keys, description, &blk)
  rule = Rule.new(keys, description, &blk)
  keys.each {|k| rules[k] << rule }
end
rules() click to toggle source
# File lib/bundler/settings/validator.rb, line 41
def self.rules
  @rules ||= Hash.new {|h, k| h[k] = [] }
end

Public Instance Methods

fail!(key, value, *reasons) click to toggle source
# 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) click to toggle source
# File lib/bundler/settings/validator.rb, line 36
def k(key)
  Bundler.settings.key_for(key)
end
set(settings, key, value, *reasons) click to toggle source
# 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

  def k(key)
    Bundler.settings.key_for(key)
  end
end
validate!(key, value, settings) click to toggle source
# File lib/bundler/settings/validator.rb, line 15
def validate!(key, value, settings)
  instance_exec(key, value, settings, &@validate)
end