summaryrefslogtreecommitdiff
path: root/lib/bundler/settings.rb
blob: 7bd421e1e11e39220cefa6f6c54865d71fb09889 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
module Bundler
  class Settings
    def initialize(app_config_path)
      @dir    = app_config_path.to_s
      @config = File.exist?(config_file) ? YAML.load_file(config_file) : {}
    end

    def [](key)
      key = "BUNDLE_#{key.to_s.upcase}"
      @config[key] || ENV[key]
    end

    def []=(key, value)
      key = "BUNDLE_#{key.to_s.upcase}"
      @config[key] = value
      FileUtils.mkdir_p(config_file.dirname)
      File.open(config_file, 'w') do |f|
        f.puts @config.to_yaml
      end
      value
    end

    def without=(array)
      self[:without] = array.join(":")
    end

    def without
      self[:without] ? self[:without].split(":").map { |w| w.to_sym } : []
    end

  private

    def config_file
      Pathname.new("#{@dir}/config")
    end
  end
end