123456789_123456789_123456789_123456789_123456789_

Class: Bundler::Settings::Validator::Rule

Relationships & Source Files
Inherits: Object
Defined in: lib/bundler/settings/validator.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(keys, description, &validate) ⇒ Rule

[ GitHub ]

  
# File 'lib/bundler/settings/validator.rb', line 9

def initialize(keys, description, &validate)
  @keys = keys
  @description = description
  @validate = validate
end

Instance Attribute Details

#description (readonly)

[ GitHub ]

  
# File 'lib/bundler/settings/validator.rb', line 7

attr_reader :description

Instance Method Details

#fail!(key, value, *reasons)

Raises:

[ GitHub ]

  
# 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)

[ GitHub ]

  
# File 'lib/bundler/settings/validator.rb', line 36

def k(key)
  Bundler.settings.key_for(key)
end

#set(settings, key, value, *reasons)

[ GitHub ]

  
# 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)

[ GitHub ]

  
# File 'lib/bundler/settings/validator.rb', line 15

def validate!(key, value, settings)
  instance_exec(key, value, settings, &@validate)
end