Class: Netlify::Deploy

Inherits:
Model
  • Object
show all
Defined in:
lib/netlify/deploy.rb

Instance Attribute Summary

Attributes inherited from Model

#attributes, #client, #prefix

Instance Method Summary collapse

Methods inherited from Model

#collection, collection, #destroy, fields, #initialize, #path, #process, #refresh, #update

Constructor Details

This class inherits a constructor from Netlify::Model

Instance Method Details

#error?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/netlify/deploy.rb', line 46

def error?
  state == "error"
end

#publishObject Also known as: restore



50
51
52
53
54
# File 'lib/netlify/deploy.rb', line 50

def publish
  response = client.request(:post, ::File.join(path, "restore"))
  process(response.parsed)
  self
end

#ready?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/netlify/deploy.rb', line 42

def ready?
  state == "ready"
end

#upload_dir(dir) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/netlify/deploy.rb', line 7

def upload_dir(dir)
  return unless state == "uploading"

  shas = Hash.new { [] }
  glob = ::File.join(dir, "**", "*")

  Dir.glob(glob) do |file|
    next unless ::File.file?(file)
    pathname = ::File.join("/", file[dir.length..-1])
    next if pathname.match(/(^\/?__MACOSX\/|\/\.)/)
    sha = Digest::SHA1.hexdigest(::File.read(file))
    shas[sha] = shas[sha] + [pathname]
  end

  (required || []).each do |sha|
    shas[sha].each do |pathname|
      client.request(:put, ::File.join(path, "files", URI.encode(pathname)), :body => ::File.read(::File.join(dir, pathname)), :headers => {"Content-Type" => "application/octet-stream"})
    end
  end

  refresh
end

#wait_for_ready(timeout = 900) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/netlify/deploy.rb', line 30

def wait_for_ready(timeout = 900)
  start = Time.now
  while !(ready?)
    sleep 5
    refresh
    raise "Error processing site: #{error_message}" if error?
    yield(self) if block_given?
    raise "Timeout while waiting for ready" if Time.now - start > timeout
  end
  self
end