lib/buildbox/configuration.rb in buildbox-0.0.1 vs lib/buildbox/configuration.rb in buildbox-0.0.2

- old
+ new

@@ -4,26 +4,32 @@ new(*args).tap &:reload end require 'json' + attr_accessor :worker_uuid + attr_accessor :api_key attr_accessor :endpoint attr_accessor :use_ssl attr_accessor :api_version - attr_accessor :repositories def initialize - @use_ssl = true - @endpoint = 'api.buildboxci.com' + @use_ssl = false + @endpoint = 'api.buildbox.io' @api_version = 1 - @repositories = [] end + def update(key, value) + self.public_send("#{key}=", value) + save + end + def save File.open(path, 'w+') do |file| file.write(to_json) end + Buildbox.logger.debug "Configuration saved to `#{path}`" end def reload json = if path.exist? read @@ -37,16 +43,19 @@ end private def to_json - JSON.generate(:endpoint => endpoint, - :use_ssl => use_ssl, - :api_version => api_version, - :repositories => repositories) + JSON.pretty_generate(:endpoint => endpoint, + :use_ssl => use_ssl, + :api_version => api_version, + :api_key => api_key, + :worker_uuid => worker_uuid) end def read + Buildbox.logger.debug "Reading configuration `#{path}`" + JSON.parse(path.read) end def path Buildbox.root_path.join("configuration.json")