class Statistrano::Deployment::Manifest
Attributes
file[R]
remote[R]
remote_dir[R]
Public Class Methods
new(remote_dir, remote)
click to toggle source
# File lib/statistrano/deployment/manifest.rb, line 7 def initialize remote_dir, remote @remote_dir = remote_dir @remote = remote @file = Remote::File.new remote_path, remote end
Public Instance Methods
data()
click to toggle source
return an array of records from the manifest they are processed to all have symbolized keys
# File lib/statistrano/deployment/manifest.rb, line 16 def data @_data ||= Array( JSON.parse(raw) ).map { |h| Util.symbolize_hash_keys(h) } rescue JSON::ParserError => e Log.error "manifest on #{remote.config.hostname} had invalid JSON\n", e.message end
push(new_data)
click to toggle source
pushes a data has into the manifest's array
# File lib/statistrano/deployment/manifest.rb, line 36 def push new_data unless new_data.respond_to? :to_json raise ArgumentError, "data must be serializable as JSON" end data << Util.symbolize_hash_keys(new_data) end
put(new_data, match_key)
click to toggle source
push data into the manifest array updating a record if it matches with the `match_key`
not that if you have used the `push` method previously all duplicates with the matching key will be removed
# File lib/statistrano/deployment/manifest.rb, line 29 def put new_data, match_key remove_if { |i| i[match_key] == new_data[match_key] } push new_data end
remove_if(&condition)
click to toggle source
pass a condition to remove records from the manifest if it returns true
example:
to remove all records with the name "name" manifest.remove_if |release| release[:name] == "name" end
# File lib/statistrano/deployment/manifest.rb, line 54 def remove_if &condition data.delete_if do |item| condition.call item end end
save!()
click to toggle source
update the manifest using the data currently stored on the object
# File lib/statistrano/deployment/manifest.rb, line 63 def save! file.update_content! serialize end
Private Instance Methods
raw()
click to toggle source
# File lib/statistrano/deployment/manifest.rb, line 69 def raw content = file.content if content.empty? return "[]" else return content end end
remote_path()
click to toggle source
# File lib/statistrano/deployment/manifest.rb, line 82 def remote_path File.join( remote_dir, 'manifest.json' ) end
serialize(data_to_serialize=data)
click to toggle source
# File lib/statistrano/deployment/manifest.rb, line 78 def serialize data_to_serialize=data data_to_serialize.to_json end