Method: Boxen::Config.load

Defined in:
lib/boxen/config.rb

.load(&block) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/boxen/config.rb', line 14

def self.load(&block)
  new do |config|
    file = "#{config.homedir}/config/boxen/defaults.json"

    if File.file? file
      attrs = JSON.parse File.read file

      attrs.each do |key, value|
        if !value.nil? && config.respond_to?(selector = "#{key}=")
          config.send selector, value
        end
      end
    end

    keychain        = Boxen::Keychain.new config.user
    config.token    = keychain.token

    if config.enterprise?
      # configure to talk to GitHub Enterprise
      Octokit.configure do |c|
        c.api_endpoint = "#{config.ghurl}/api/v3"
        c.web_endpoint = config.ghurl
      end
    end

    yield config if block_given?
  end
end