Class: Statistrano::Deployment::Manifest

Inherits:
Object
  • Object
show all
Defined in:
lib/statistrano/deployment/manifest.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(remote_dir, remote) ⇒ Manifest

Returns a new instance of Manifest.



7
8
9
10
11
# 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

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



5
6
7
# File 'lib/statistrano/deployment/manifest.rb', line 5

def file
  @file
end

#remoteObject (readonly)

Returns the value of attribute remote.



5
6
7
# File 'lib/statistrano/deployment/manifest.rb', line 5

def remote
  @remote
end

#remote_dirObject (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

#dataObject

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.message
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