Class: HipstaScale::Heroku

Inherits:
Object
  • Object
show all
Defined in:
lib/hipsta_scale/heroku.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Heroku

Returns a new instance of Heroku.



9
10
11
# File 'lib/hipsta_scale/heroku.rb', line 9

def initialize(app)
  @app = app
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



7
8
9
# File 'lib/hipsta_scale/heroku.rb', line 7

def app
  @app
end

Instance Method Details

#expire!Object



13
14
15
# File 'lib/hipsta_scale/heroku.rb', line 13

def expire!
  @_cache = nil
end

#fetchObject



17
18
19
20
21
22
# File 'lib/hipsta_scale/heroku.rb', line 17

def fetch
  return @_cache unless @_cache.nil?
  json = RestClient.get(url, accept: 'json')
  response = JSON.parse(json)
  @_cache = response.map {|ps| OpenStruct.new(ps) }
end

#processesObject



24
25
26
# File 'lib/hipsta_scale/heroku.rb', line 24

def processes
  fetch.select {|ps| ps.process.match(app.heroku_ps) }
end

#processes_otherObject



28
29
30
# File 'lib/hipsta_scale/heroku.rb', line 28

def processes_other
  fetch - processes
end

#scale_processes(count) ⇒ Object



32
33
34
# File 'lib/hipsta_scale/heroku.rb', line 32

def scale_processes(count)
  RestClient.post("#{url}/scale?type=#{app.heroku_ps}&qty=#{count}", accept: 'json')
end