# Copyright (C) 2011 RightScale, Inc, All Rights Reserved Worldwide. # # THIS PROGRAM IS CONFIDENTIAL AND PROPRIETARY TO RIGHTSCALE # AND CONSTITUTES A VALUABLE TRADE SECRET. Any unauthorized use, # reproduction, modification, or disclosure of this program is # strictly prohibited. Any use of this program by an authorized # licensee is strictly subject to the terms and conditions, # including confidentiality obligations, set forth in the applicable # License Agreement between RightScale.com, Inc. and # the licensee require 'yaml' module RightConf class Profile include Singleton # Load profile from disk on instantiation def initialize if File.exist?(profile_path) @profile = YAML.load(IO.read(profile_path)) rescue {} @profile = {} unless @profile.is_a?(Hash) else @profile = {} end end # Retrieve persisted configurator signature # # === Return # signature(String):: Persisted configurator signature def configurator_signature(key) sigs = @profile[:configurator_signatures] signature = sigs && sigs[key] end # Set signature for given configurator # # === Parameters # key(String):: Configurator key # signature(String):: Persisted configurator signature # # === Return # true:: Always return true def set_configurator_signature(key, signature) @profile[:configurator_signatures] ||= {} @profile[:configurator_signatures][key] = signature persist true end # Entire profile with all settings # # === Return # profile(Hash):: Profile settings def profile @profile end protected # Retrieve profile file path # # === Return # path(String):: Profile file path def profile_path profile_path = ENV['RCONF_PROFILE'] || File.join(ENV['HOME'], '.rconf') end # Persist profile to file # # === Return # true:: Always return true def persist File.open(profile_path, 'w') { |f| f.puts YAML.dump(@profile) } unless @profile.nil? end end end