Class: Anvil::Manifest
- Inherits:
-
Object
show all
- Includes:
- Helpers
- Defined in:
- lib/anvil/manifest.rb
Constant Summary
collapse
- PUSH_THREAD_COUNT =
40
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from Helpers
#anvil_metadata_dir, #json_decode, #json_encode, #read_anvil_metadata, #write_anvil_metadata
Constructor Details
#initialize(dir = nil, cache_url = nil) ⇒ Manifest
Returns a new instance of Manifest.
18
19
20
21
22
|
# File 'lib/anvil/manifest.rb', line 18
def initialize(dir=nil, cache_url=nil)
@dir = dir
@manifest = @dir ? directory_manifest(@dir) : {}
@cache_url = cache_url
end
|
Instance Attribute Details
#cache_url ⇒ Object
Returns the value of attribute cache_url.
14
15
16
|
# File 'lib/anvil/manifest.rb', line 14
def cache_url
@cache_url
end
|
#dir ⇒ Object
Returns the value of attribute dir.
15
16
17
|
# File 'lib/anvil/manifest.rb', line 15
def dir
@dir
end
|
#manifest ⇒ Object
Returns the value of attribute manifest.
16
17
18
|
# File 'lib/anvil/manifest.rb', line 16
def manifest
@manifest
end
|
Instance Method Details
#add(filename) ⇒ Object
99
100
101
|
# File 'lib/anvil/manifest.rb', line 99
def add(filename)
@manifest[filename] = file_manifest(filename)
end
|
#build(options = {}) ⇒ Object
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/anvil/manifest.rb', line 24
def build(options={})
uri = URI.parse("#{anvil_host}/manifest/build")
http = Net::HTTP.new(uri.host, uri.port)
if uri.scheme == "https"
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end
req = Net::HTTP::Post.new uri.request_uri
env = options[:env] || {}
req.set_form_data({
"buildpack" => options[:buildpack],
"cache" => @cache_url,
"env" => json_encode(options[:env] || {}),
"manifest" => self.to_json
})
slug_url = nil
http.request(req) do |res|
slug_url = res["x-slug-url"]
@cache_url = res["x-cache-url"]
begin
res.read_body do |chunk|
yield chunk
end
rescue EOFError
puts
raise Anvil::Builder::BuildError, "terminated unexpectedly"
end
code = if res["x-exit-code"].nil?
manifest_id = Array(res["x-manifest-id"]).first
Integer(String.new(anvil["/exit/#{manifest_id}"].get.to_s))
else
res["x-exit-code"].first.to_i
end
raise Anvil::Builder::BuildError, "exited #{code}" unless code.zero?
end
slug_url
end
|
#manifest_by_hash(manifest) ⇒ Object
77
78
79
80
81
|
# File 'lib/anvil/manifest.rb', line 77
def manifest_by_hash(manifest)
manifest.inject({}) do |ax, (name, file)|
ax.update file["hash"] => file.merge("name" => name)
end
end
|
#missing ⇒ Object
83
84
85
86
87
88
|
# File 'lib/anvil/manifest.rb', line 83
def missing
mbh = manifest_by_hash(@manifest)
json_decode(anvil["/manifest/diff"].post(:manifest => self.to_json).to_s).inject({}) do |ax, hash|
ax.update hash => mbh[hash]
end
end
|
#save ⇒ Object
72
73
74
75
|
# File 'lib/anvil/manifest.rb', line 72
def save
res = anvil["/manifest"].post(:manifest => self.to_json)
res.[:location]
end
|
#to_json ⇒ Object
95
96
97
|
# File 'lib/anvil/manifest.rb', line 95
def to_json
json_encode(@manifest)
end
|
#upload(missing, &blk) ⇒ Object
90
91
92
93
|
# File 'lib/anvil/manifest.rb', line 90
def upload(missing, &blk)
upload_hashes missing, &blk
missing.length
end
|