Class: Hap::App

Inherits:
Object
  • Object
show all
Defined in:
lib/hap/app.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ App

Returns a new instance of App.



11
12
13
14
15
# File 'lib/hap/app.rb', line 11

def initialize name
  @name = name
  @file = "#{Hap.app_root}/#{Hap::DEPLOYMENT_DIR}/#{name}/#{Hap::APP_DATA_FILE}"
  @data = Oj.load(File.read(@file)) if exists?
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



9
10
11
# File 'lib/hap/app.rb', line 9

def data
  @data
end

#fileObject

Returns the value of attribute file.



9
10
11
# File 'lib/hap/app.rb', line 9

def file
  @file
end

#nameObject

Returns the value of attribute name.



9
10
11
# File 'lib/hap/app.rb', line 9

def name
  @name
end

Instance Method Details

#api_key=(api_key) ⇒ Object



44
45
46
# File 'lib/hap/app.rb', line 44

def api_key= api_key
  @api_key = api_key unless api_key.nil?
end

#create!(api_key = nil) ⇒ Object



30
31
32
33
34
35
36
# File 'lib/hap/app.rb', line 30

def create!(api_key = nil)
  return self if exists?
  self.api_key = api_key
  @data = heroku.post_app(name: nil).body 
  add_buildpack if frontend?
  self
end

#destroy!(api_key = nil) ⇒ Object



38
39
40
41
42
# File 'lib/hap/app.rb', line 38

def destroy!(api_key = nil)
  return unless exists?
  self.api_key = api_key
  heroku.delete_app @data["name"] rescue nil
end

#exists?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/hap/app.rb', line 17

def exists?
  @exists ||= File.exists?(@file)
end

#frontend?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/hap/app.rb', line 21

def frontend?
  @name == Hap::FRONT_END
end

#missing_method(method, *args, &block) ⇒ Object



48
49
50
51
# File 'lib/hap/app.rb', line 48

def missing_method(method,*args,&block)
  return @data.send(method, *args, &block) if @data.respond_to?(method)
  super(method,*args,&block)    
end