class DEIS::Storage
Constants
- BASE_PATH
- ENV_VAR_PATH
Public Class Methods
file(repo, env)
click to toggle source
# File lib/rdeis/storage.rb, line 7 def self.file(repo, env) BASE_PATH.gsub("$HOME", ENV['HOME'])+repo+"/#{env}.json" end
get(repo, env, key=nil)
click to toggle source
# File lib/rdeis/storage.rb, line 23 def self.get(repo, env, key=nil) current = DEIS::Storage.load(repo, env) # key asked for and is present if ! key.nil? && current.has_key?(key) current[key].sort_by{|k,v| k } # key asked for but not present elsif !key.nil? {} # key not asked for else current.sort_by{|k,v| k } end end
load(repo, env)
click to toggle source
# File lib/rdeis/storage.rb, line 11 def self.load(repo, env) data = {} data = JSON.parse( File.open( DEIS::Storage.file(repo, env) , "r" ) { | f | f.read } ) if File.exists? (DEIS::Storage.file(repo, env)) data end
removal_complete(repo, env, key)
click to toggle source
remove the removed flag for this key by just setting it to an empty hash
# File lib/rdeis/storage.rb, line 38 def self.removal_complete(repo, env, key) DEIS::Storage.set(repo, env, key, {}) end
save(repo, env, data)
click to toggle source
# File lib/rdeis/storage.rb, line 17 def self.save(repo, env, data) working_dir = DEIS::Storage::BASE_PATH.gsub("$HOME", ENV['HOME']) FileUtils.mkdir_p(working_dir+repo) unless Dir.exists?(working_dir+repo) File.open( DEIS::Storage.file(repo, env) , "w" ){ |f| f.write ( data.to_json ) } end
set(repo, env, key, value)
click to toggle source
only handles top level, not sub levels
# File lib/rdeis/storage.rb, line 43 def self.set(repo, env, key, value) current = DEIS::Storage.load(repo, env) # overwrite the value existing current[key] = value DEIS::Storage.save(repo, env, current) end
subset(repo, env, key, subkey, value)
click to toggle source
# File lib/rdeis/storage.rb, line 50 def self.subset(repo, env, key, subkey, value) current = DEIS::Storage.load(repo, env) current[key] = {} if ! current.has_key?(key) current[key][subkey] = value # if it exists in the unset, remove it DEIS::Storage.save(repo, env, current) # remove from items that need to be removed DEIS::Storage.subunset(repo, env, "removed_#{key}", subkey) if key.index("removed_").nil? end
subunset(repo, env, key, subkey)
click to toggle source
only have the option to remove low level, not top level
# File lib/rdeis/storage.rb, line 61 def self.subunset(repo, env, key, subkey) current = DEIS::Storage.load(repo, env) if current.has_key?(key) && current[key].has_key?(subkey) tmp = current[key] val = tmp[subkey] tmp.delete(subkey) current[key] = tmp # save DEIS::Storage.save(repo, env, current) #also need to store removals for actions to be performed on the server, if check to stop recursive loops DEIS::Storage.subset(repo, env, "removed_#{key}", subkey, val) if key.index("removed_").nil? end end