Class: Statistrano::Deployment::Manifest
- Inherits:
-
Object
- Object
- Statistrano::Deployment::Manifest
- Defined in:
- lib/statistrano/deployment/manifest.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
readonly
Returns the value of attribute file.
-
#remote ⇒ Object
readonly
Returns the value of attribute remote.
-
#remote_dir ⇒ Object
readonly
Returns the value of attribute remote_dir.
Instance Method Summary collapse
-
#data ⇒ Object
return an array of records from the manifest they are processed to all have symbolized keys.
-
#initialize(remote_dir, remote) ⇒ Manifest
constructor
A new instance of Manifest.
-
#push(new_data) ⇒ Object
pushes a data has into the manifest’s array.
-
#put(data, match_key) ⇒ Object
push data into the manifest array updating a record if it matches with the ‘match_key`.
-
#remove_if(&condition) ⇒ Object
pass a condition to remove records from the manifest if it returns true.
-
#save! ⇒ Object
update the manifest using the data currently stored on the object.
Constructor Details
Instance Attribute Details
#file ⇒ Object (readonly)
Returns the value of attribute file.
5 6 7 |
# File 'lib/statistrano/deployment/manifest.rb', line 5 def file @file end |
#remote ⇒ Object (readonly)
Returns the value of attribute remote.
5 6 7 |
# File 'lib/statistrano/deployment/manifest.rb', line 5 def remote @remote end |
#remote_dir ⇒ Object (readonly)
Returns the value of attribute remote_dir.
5 6 7 |
# File 'lib/statistrano/deployment/manifest.rb', line 5 def remote_dir @remote_dir end |
Instance Method Details
#data ⇒ Object
return an array of records from the manifest they are processed to all have symbolized keys
16 17 18 19 20 21 |
# 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. end |
#push(new_data) ⇒ Object
pushes a data has into the manifest’s array
36 37 38 39 40 41 42 |
# 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(data, match_key) ⇒ Object
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
29 30 31 32 |
# File 'lib/statistrano/deployment/manifest.rb', line 29 def put data, match_key remove_if { |i| i[match_key] == data[match_key] } push data end |
#remove_if(&condition) ⇒ Object
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
54 55 56 57 58 |
# File 'lib/statistrano/deployment/manifest.rb', line 54 def remove_if &condition data.delete_if do |item| condition.call item end end |
#save! ⇒ Object
update the manifest using the data currently stored on the object
63 64 65 |
# File 'lib/statistrano/deployment/manifest.rb', line 63 def save! file.update_content! serialize end |