Class: Buildbox::Configuration

Inherits:
Hashie::Mash
  • Object
show all
Defined in:
lib/buildbox/configuration.rb

Instance Method Summary collapse

Instance Method Details

#agent_access_tokensObject



6
7
8
9
10
11
12
13
14
# File 'lib/buildbox/configuration.rb', line 6

def agent_access_tokens
  env_agents = ENV['BUILDBOX_AGENTS']

  if env_agents.nil?
    self[:agent_access_tokens] || []
  else
    env_agents.to_s.split(",")
  end
end

#api_endpointObject



20
21
22
# File 'lib/buildbox/configuration.rb', line 20

def api_endpoint
  ENV['BUILDBOX_API_ENDPOINT'] || self[:api_endpoint] || "https://api.buildbox.io/v1"
end

#api_keyObject



16
17
18
# File 'lib/buildbox/configuration.rb', line 16

def api_key
  ENV['BUILDBOX_API_KEY'] || self[:api_key]
end

#checkObject



24
25
26
27
28
29
# File 'lib/buildbox/configuration.rb', line 24

def check
  unless api_key
    puts "No api_key set. You can set it with\nbuildbox auth:login [api_key]"
    exit 1
  end
end

#reloadObject



40
41
42
43
44
45
46
# File 'lib/buildbox/configuration.rb', line 40

def reload
  if path.exist?
    read_and_load
  else
    save && read_and_load
  end
end

#saveObject



36
37
38
# File 'lib/buildbox/configuration.rb', line 36

def save
  File.open(path, 'w+') { |file| file.write(pretty_json) }
end

#update(attributes) ⇒ Object



31
32
33
34
# File 'lib/buildbox/configuration.rb', line 31

def update(attributes)
  attributes.each_pair { |key, value| self[key] = value }
  save
end