Class: Bundler::CLI::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/bundler/cli/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options, args, thor) ⇒ Config

Returns a new instance of Config.



8
9
10
11
12
13
14
15
16
17
# File 'lib/bundler/cli/config.rb', line 8

def initialize(options, args, thor)
  @options = options
  @args = args
  @thor = thor
  @name = peek = args.shift
  @scope = "global"
  return unless peek && peek.start_with?("--")
  @name = args.shift
  @scope = peek[2..-1]
end

Instance Attribute Details

#argsObject

Returns the value of attribute args.



6
7
8
# File 'lib/bundler/cli/config.rb', line 6

def args
  @args
end

#nameObject (readonly)

Returns the value of attribute name.



5
6
7
# File 'lib/bundler/cli/config.rb', line 5

def name
  @name
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/bundler/cli/config.rb', line 5

def options
  @options
end

#scopeObject (readonly)

Returns the value of attribute scope.



5
6
7
# File 'lib/bundler/cli/config.rb', line 5

def scope
  @scope
end

#thorObject (readonly)

Returns the value of attribute thor.



5
6
7
# File 'lib/bundler/cli/config.rb', line 5

def thor
  @thor
end

Instance Method Details

#runObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/bundler/cli/config.rb', line 19

def run
  unless name
    confirm_all
    return
  end

  unless valid_scope?(scope)
    Bundler.ui.error "Invalid scope --#{scope} given. Please use --local or --global."
    exit 1
  end

  if scope == "delete"
    Bundler.settings.set_local(name, nil)
    Bundler.settings.set_global(name, nil)
    return
  end

  if args.empty?
    if options[:parseable]
      if value = Bundler.settings[name]
        Bundler.ui.info("#{name}=#{value}")
      end
      return
    end

    confirm(name)
    return
  end

  Bundler.ui.info(message) if message
  Bundler.settings.send("set_#{scope}", name, new_value)
end