Class: Strobe::Deploy

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

Defined Under Namespace

Classes: Multipart

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Deploy

Returns a new instance of Deploy.



11
12
13
14
# File 'lib/strobe/deploy.rb', line 11

def initialize(path)
  @path       = path
  @connection, @method = Strobe.settings.app_connection_and_method
end

Instance Method Details

#deployObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/strobe/deploy.rb', line 16

def deploy
  Strobe::Account. unless Strobe.settings[:token]

  application, errors = HTTP.new.deploy(multipart)

  if errors
    raise Strobe::ApplicationError, "Application creation failed. Please try again.\n#{errors}"
  else
    # Update this every time for now, in case the app has changed
    # on the server. This assumes that the server returns JSON
    Strobe.settings.set_local(:application, application)
    Strobe.ui.confirm "Your app was successfully deployed on #{application["url"]}"
  end
end

#multipartObject



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/strobe/deploy.rb', line 31

def multipart
  Multipart.new do |m|
    if application = Strobe.settings[:application]
      name = application["name"]
      url  = application["url"]
    else
      name = Strobe.ui.ask "Please enter your application's name: "
      url  = Strobe.ui.ask "URL to deploy to:                     "
    end

    m.name name
    m.url  url

    Dir["#{@path}/**/*"].each do |file|
      next unless File.file?(file)

      filename = file.sub(/^#{@path}/, '')
      mime_type = MIME::Types.type_for(file).first
      m.file filename, mime_type ? mime_type.to_s : "application/octet-stream", File.read(file)
    end

    apps = []

    Dir["#{@path}/static/*"].each do |app|
      next if File.file?(app)

      dir   = File.basename(app)
      index = Dir["#{app}/*/*/index.html"].first

      next if !index || !File.file?(index)

      index = File.read(index)
      apps << index

      m.file "#{dir}/index.html", "text/html", index
    end

    m.file "index.html", "text/html", apps.first if apps.size == 1
  end
end