class Bundler::Settings::Validator::Rule - bundler: Ruby Standard Library Documentation

# class Bundler::Settings::Validator::Rule

### Attributes

description[R]

### Public Class Methods

new(keys, description, &validate) click to toggle source

    # File bundler/settings/validator.rb, line 9
    def initialize(keys, description, &validate)
      @keys = keys
      @description = description
      @validate = validate
    end

### Public Instance Methods

fail!(key, value, *reasons) click to toggle source

    # File 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 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 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) click to toggle source

    # File bundler/settings/validator.rb, line 15
    def validate!(key, value, settings)
      instance_exec(key, value, settings, &@validate)
    end