lib/buildbox/configuration.rb in buildbox-0.6.2 vs lib/buildbox/configuration.rb in buildbox-0.7.beta1

- old
+ new

@@ -1,22 +1,23 @@ -require 'hashie/mash' require 'json' module Buildbox - class Configuration < Hashie::Mash + class Configuration + include Buildbox::Model + def agent_access_tokens env_agents = ENV['BUILDBOX_AGENTS'] if env_agents.nil? - self[:agent_access_tokens] || [] + @agent_access_tokens || [] else env_agents.to_s.split(",") end end def api_endpoint - endpoint = ENV['BUILDBOX_API_ENDPOINT'] || self[:api_endpoint] || "https://agent.buildbox.io/v1" + endpoint = ENV['BUILDBOX_API_ENDPOINT'] || @api_endpoint || "https://agent.buildbox.io/v1" # hack to update legacy endpoints if endpoint == "https://api.buildbox.io/v1" self.api_endpoint = "https://agent.buildbox.io/v1" save @@ -25,11 +26,12 @@ endpoint end end def update(attributes) - attributes.each_pair { |key, value| self[key] = value } + self.attributes = attributes + save end def save File.open(path, 'w+') { |file| file.write(pretty_json) } @@ -44,14 +46,15 @@ end private def pretty_json - JSON.pretty_generate(self) + JSON.pretty_generate(:agent_access_tokens => agent_access_tokens, + :api_endpoint => api_endpoint) end def read_and_load - merge! JSON.parse(path.read) + self.attributes = JSON.parse(path.read) end def path Buildbox.home_path.join("configuration.json") end