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:



161
162
163
164
165
166
# File 'lib/dawn/api/models/app.rb', line 161

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

.create(options) ⇒ Object

Parameters:

  • options (Hash)


148
149
150
151
152
153
154
155
# File 'lib/dawn/api/models/app.rb', line 148

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: {})


196
197
198
199
200
201
202
203
# File 'lib/dawn/api/models/app.rb', line 196

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

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

.find(options) ⇒ Object

Parameters:

  • options (Hash)


171
172
173
174
175
176
177
178
# File 'lib/dawn/api/models/app.rb', line 171

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

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

.id_param(options) ⇒ Object

Parameters:

  • options (Hash)


139
140
141
142
143
# File 'lib/dawn/api/models/app.rb', line 139

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

.logs(options = {}) ⇒ Object

Parameters:

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


220
221
222
223
224
225
226
227
228
229
# File 'lib/dawn/api/models/app.rb', line 220

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: {})


208
209
210
211
212
213
214
215
# File 'lib/dawn/api/models/app.rb', line 208

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: {})


247
248
249
250
251
252
253
254
255
# File 'lib/dawn/api/models/app.rb', line 247

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: {})


234
235
236
237
238
239
240
241
242
# File 'lib/dawn/api/models/app.rb', line 234

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)


183
184
185
186
187
188
189
190
191
# File 'lib/dawn/api/models/app.rb', line 183

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: {})


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

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

#domainsDawn::App::Domains

Returns:



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

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

#drainsDawn::App::Drains

Returns:



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

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

#gearsDawn::App::Gears

Returns:



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

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

#gitString

Returns the git remote path for this App

Returns:

  • (String)


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

def git
  @git ||= "#{Dawn::Account.current.username}~#{name}.git"
end

#logs(options = {}) ⇒ Object

Parameters:

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


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

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

#refresh(options = {}) ⇒ self

Returns:

  • (self)


73
74
75
76
77
78
79
# File 'lib/dawn/api/models/app.rb', line 73

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

#releasesDawn::App::Releases

Returns:



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

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

#restart(options = {}) ⇒ Object

Parameters:

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


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

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

#run(options = {}) ⇒ Object

Parameters:

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


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

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

#saveself

Returns:

  • (self)


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

def save
  update(app: @data)
end

#scale(options = {}) ⇒ Object

Parameters:

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


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

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

#update(options = {}) ⇒ self

Returns:

  • (self)


84
85
86
87
88
89
90
91
92
# File 'lib/dawn/api/models/app.rb', line 84

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

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