Class: Rake::Pipeline::Manifest

Inherits:
Object
  • Object
show all
Defined in:
lib/rake-pipeline/manifest.rb

Overview

A Manifest is a container for storing dynamic dependency information. A DynamicFileTask will use a Manifest to keep track of its dynamic dependencies. This allows us to avoid scanning a file for dynamic dependencies if its contents have not changed.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(manifest_file = "manifest.json") ⇒ Manifest

Returns a new instance of Manifest.



13
14
15
16
# File 'lib/rake-pipeline/manifest.rb', line 13

def initialize(manifest_file="manifest.json")
  @manifest_file ||= manifest_file
  @entries = {}
end

Instance Attribute Details

#entriesObject

Returns the value of attribute entries.



10
11
12
# File 'lib/rake-pipeline/manifest.rb', line 10

def entries
  @entries
end

#manifest_fileObject

Returns the value of attribute manifest_file.



11
12
13
# File 'lib/rake-pipeline/manifest.rb', line 11

def manifest_file
  @manifest_file
end

Instance Method Details

#[](key) ⇒ Object

Look up an entry by filename.



53
54
55
# File 'lib/rake-pipeline/manifest.rb', line 53

def [](key)
  @entries[key]
end

#[]=(key, value) ⇒ Object

Set an entry



58
59
60
# File 'lib/rake-pipeline/manifest.rb', line 58

def []=(key, value)
  @entries[key] = value
end

#as_jsonObject

Convert this Manifest into a hash suitable for converting to JSON.



42
43
44
45
46
47
48
49
50
# File 'lib/rake-pipeline/manifest.rb', line 42

def as_json
  hash = {}

  @entries.each do |name, entry|
    hash[name] = entry.as_json
  end

  hash
end

#clearObject



62
63
64
# File 'lib/rake-pipeline/manifest.rb', line 62

def clear
  entries.clear
end

#empty?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/rake-pipeline/manifest.rb', line 66

def empty?
  entries.empty?
end

#filesObject



70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/rake-pipeline/manifest.rb', line 70

def files
  entries.inject({}) do |hash, pair| 
    file = pair.first
    entry = pair.last

    hash.merge!(file => entry.mtime)

    entry.deps.each_pair do |name, time| 
      hash.merge!(name => time)
    end

    hash
  end
end

#read_manifestObject

Get the manifest off the file system, if it exists.



19
20
21
22
23
24
25
26
27
28
# File 'lib/rake-pipeline/manifest.rb', line 19

def read_manifest
  @entries = File.file?(manifest_file) ? JSON.parse(File.read(manifest_file)) : {}

  # convert the manifest JSON into a Hash of ManifestEntry objects
  @entries.each do |file, raw|
    @entries[file] = Rake::Pipeline::ManifestEntry.from_hash(raw)
  end

  self
end

#write_manifestObject

Write a JSON representation of this manifest out to disk if we have entries to save.



32
33
34
35
36
37
38
# File 'lib/rake-pipeline/manifest.rb', line 32

def write_manifest
  unless @entries.empty?
    File.open(manifest_file, "w") do |file|
      file.puts JSON.generate(as_json)
    end
  end
end