Class: DEIS::Storage
Constant Summary collapse
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
#cluster, #environment, #output, #path, #proxy, #ssh, #verbose
Class Method Summary collapse
- .file(repo, env) ⇒ Object
- .get(repo, env, key = nil) ⇒ Object
- .load(repo, env) ⇒ Object
-
.removal_complete(repo, env, key) ⇒ Object
remove the removed flag for this key by just setting it to an empty hash.
- .save(repo, env, data) ⇒ Object
-
.set(repo, env, key, value) ⇒ Object
only handles top level, not sub levels.
- .subset(repo, env, key, subkey, value) ⇒ Object
-
.subunset(repo, env, key, subkey) ⇒ Object
only have the option to remove low level, not top level.
Methods inherited from Base
#local_profile, #local_shell, #local_shell_env_include, #log, #remote_profile, #run
Class Method Details
.file(repo, env) ⇒ Object
7 8 9 |
# 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) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# 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) ⇒ Object
11 12 13 14 15 |
# 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) ⇒ Object
remove the removed flag for this key by just setting it to an empty hash
38 39 40 |
# 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) ⇒ Object
17 18 19 20 21 |
# 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) ⇒ Object
only handles top level, not sub levels
43 44 45 46 47 48 |
# 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) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# 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) ⇒ Object
only have the option to remove low level, not top level
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# 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 |