Class: Dawn::App

Inherits:
Object
  • Object
show all
Includes:
BaseApi
Defined in:
lib/dawn/api/models/app.rb,
lib/dawn/api/models/app/env.rb,
lib/dawn/api/models/app/gears.rb,
lib/dawn/api/models/app/drains.rb,
lib/dawn/api/models/app/domains.rb,
lib/dawn/api/models/app/releases.rb

Overview

:nodoc:

Defined Under Namespace

Classes: Domains, Drains, Env, Gears, Releases

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from BaseApi

included, #to_h

Methods included from BaseApi::RequestExtension

#request

Methods included from SafeExtension

#safe

Constructor Details

#initialize(data) ⇒ App

Returns a new instance of App.

Parameters:

  • data (Hash)


29
30
31
32
# File 'lib/dawn/api/models/app.rb', line 29

def initialize(data)
  @data = data
  @data["env"] = @env = Env.new(self, @data.delete("env"))
end

Instance Attribute Details

#envObject (readonly)

Returns the value of attribute env.



14
15
16
# File 'lib/dawn/api/models/app.rb', line 14

def env
  @env
end

Class Method Details

.all(options = {}) ⇒ Array<Dawn::App>

Parameters:

  • options (Hash) (defaults to: {})

Returns:



153
154
155
156
157
158
# File 'lib/dawn/api/models/app.rb', line 153

def self.all(options={})
  get(
    path: "/apps",
    query: options
  ).map { |d| new d["app"] }
end

.create(options) ⇒ Object

Parameters:

  • options (Hash)


140
141
142
143
144
145
146
147
# File 'lib/dawn/api/models/app.rb', line 140

def self.create(options)
  options.fetch(:app)

  new post(
    path: "/apps",
    body: options.to_json
  )["app"]
end

.destroy(options = {}) ⇒ Object

Parameters:

  • options (Hash) (defaults to: {})


188
189
190
191
192
193
194
195
# File 'lib/dawn/api/models/app.rb', line 188

def self.destroy(options={})
  id = id_param(options)

  delete(
    path: "/apps/#{id}",
    query: options
  )
end

.find(options) ⇒ Object

Parameters:

  • options (Hash)


163
164
165
166
167
168
169
170
# File 'lib/dawn/api/models/app.rb', line 163

def self.find(options)
  id = id_param(options)

  new get(
    path: "/apps/#{id}",
    query: options
  )["app"]
end

.id_param(options) ⇒ Object

Parameters:

  • options (Hash)


131
132
133
134
135
# File 'lib/dawn/api/models/app.rb', line 131

def self.id_param(options)
  options.delete(:id) ||
  options.delete(:name) ||
  raise
end

.logs(options = {}) ⇒ Object

Parameters:

  • options (Hash) (defaults to: {})


212
213
214
215
216
217
218
219
220
221
# File 'lib/dawn/api/models/app.rb', line 212

def self.logs(options={})
  id = id_param(options)

  url = get(
    path: "/apps/#{id}/logs",
    query: options
  )["logs"]

  "http://#{Dawn.log_host}#{url}"
end

.restart(options = {}) ⇒ Object

Parameters:

  • options (Hash) (defaults to: {})


200
201
202
203
204
205
206
207
# File 'lib/dawn/api/models/app.rb', line 200

def self.restart(options={})
  id = id_param(options)

  post(
    path: "/apps/#{id}/gears/restart",
    body: options.to_json
  )
end

.run(options = {}) ⇒ Object

Parameters:

  • options (Hash) (defaults to: {})


239
240
241
242
243
244
245
246
247
# File 'lib/dawn/api/models/app.rb', line 239

def self.run(options={})
  id = id_param(options)
  options.fetch(:command)

  post(
    path: "/apps/#{id}/run",
    body: options.to_json
  )
end

.scale(options = {}) ⇒ Object

Parameters:

  • options (Hash) (defaults to: {})


226
227
228
229
230
231
232
233
234
# File 'lib/dawn/api/models/app.rb', line 226

def self.scale(options={})
  id = id_param(options)
  options.fetch(:app).fetch(:formation)

  post(
    path: "/apps/#{id}/scale",
    body: options.to_json
  )
end

.update(options) ⇒ Object

Parameters:

  • options (Hash)


175
176
177
178
179
180
181
182
183
# File 'lib/dawn/api/models/app.rb', line 175

def self.update(options)
  id = id_param(options)
  options.fetch(:app)

  new patch(
    path: "/apps/#{id}",
    body: options.to_json
  )["app"]
end

Instance Method Details

#destroy(options = {}) ⇒ Object

Parameters:

  • options (Hash) (defaults to: {})


96
97
98
# File 'lib/dawn/api/models/app.rb', line 96

def destroy(options={})
  self.class.destroy(options.merge(id: id))
end

#domainsDawn::App::Domains

Returns:



51
52
53
# File 'lib/dawn/api/models/app.rb', line 51

def domains
  @domains ||= Domains.new self
end

#drainsDawn::App::Drains

Returns:



44
45
46
# File 'lib/dawn/api/models/app.rb', line 44

def drains
  @drains ||= Drains.new self
end

#gearsDawn::App::Gears

Returns:



37
38
39
# File 'lib/dawn/api/models/app.rb', line 37

def gears
  @gears ||= Gears.new self
end

#logs(options = {}) ⇒ Object

Parameters:

  • options (Hash) (defaults to: {})


110
111
112
# File 'lib/dawn/api/models/app.rb', line 110

def logs(options={})
  self.class.logs(options.merge(id: id))
end

#refresh(options = {}) ⇒ self

Returns:

  • (self)


65
66
67
68
69
70
71
# File 'lib/dawn/api/models/app.rb', line 65

def refresh(options={})
  @data = get(
    path: "/apps/#{id}",
    query: options
  )["app"]
  self
end

#releasesDawn::App::Releases

Returns:



58
59
60
# File 'lib/dawn/api/models/app.rb', line 58

def releases
  @releases ||= Releases.new self
end

#restart(options = {}) ⇒ Object

Parameters:

  • options (Hash) (defaults to: {})


124
125
126
# File 'lib/dawn/api/models/app.rb', line 124

def restart(options={})
  self.class.restart(options.merge(id: id))
end

#run(options = {}) ⇒ Object

Parameters:

  • options (Hash) (defaults to: {})


103
104
105
# File 'lib/dawn/api/models/app.rb', line 103

def run(options={})
  self.class.run(options.merge(id: id))
end

#saveself

Returns:

  • (self)


89
90
91
# File 'lib/dawn/api/models/app.rb', line 89

def save
  update(app: @data)
end

#scale(options = {}) ⇒ Object

Parameters:

  • options (Hash) (defaults to: {})


117
118
119
# File 'lib/dawn/api/models/app.rb', line 117

def scale(options={})
  @data["formation"] = self.class.scale(options.merge(id: id))
end

#update(options = {}) ⇒ self

Returns:

  • (self)


76
77
78
79
80
81
82
83
84
# File 'lib/dawn/api/models/app.rb', line 76

def update(options={})
  options.fetch(:app)

  @data = patch(
    path: "/apps/#{id}",
    body: options.to_json
  )["app"]
  self
end