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



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

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



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

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

#api_keyObject



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

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

#checkObject



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

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



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

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

#saveObject



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

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

#update(attributes) ⇒ Object



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

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