Class: Sibling

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/sibling.rb

Defined Under Namespace

Classes: Deploy, Instruction

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.async_consumeObject



28
29
30
# File 'app/models/sibling.rb', line 28

def async_consume
  Resque.enqueue(SiblingConsumer)
end

.consume_main_app_hcardObject



20
21
22
23
24
25
26
# File 'app/models/sibling.rb', line 20

def consume_main_app_hcard
  main_app_hcard.g5_siblings.map do |sibling|
    find_or_create_from_hcard(sibling.format)
  end.compact if main_app_hcard
rescue OpenURI::HTTPError => e
  raise e unless /304 Not Modified/ =~ e.message
end

.deploy_all(manual = true, instruction_id = nil) ⇒ Object



41
42
43
# File 'app/models/sibling.rb', line 41

def deploy_all(manual=true, instruction_id=nil)
  all.each { |sibling| sibling.deploy(instruction_id) }
end

.deploy_some(kinds = [], instruction_id = nil) ⇒ Object



45
46
47
48
# File 'app/models/sibling.rb', line 45

def deploy_some(kinds=[], instruction_id=nil)
  apps = kinds.flat_map { |k| Sibling.where('name LIKE ?', "%-#{k}-%") }
  apps.each { |sibling| sibling.deploy(instruction_id) }
end

.find_or_create_from_hcard(hcard) ⇒ Object



32
33
34
35
36
37
38
39
# File 'app/models/sibling.rb', line 32

def find_or_create_from_hcard(hcard)
  find_or_create_by(uid: hcard.uid.to_s) do |sibling|
    sibling.name = hcard.name.to_s
    sibling.git_repo = hcard.g5_git_repo.to_s
    sibling.heroku_repo = hcard.g5_heroku_repo.to_s
    sibling.heroku_app_name = hcard.g5_heroku_app_name.to_s
  end
end

.main_app_hcardObject



16
17
18
# File 'app/models/sibling.rb', line 16

def main_app_hcard
  Microformats2.parse(main_app_uid).card
end

.main_app_uidObject



12
13
14
# File 'app/models/sibling.rb', line 12

def main_app_uid
  ENV["MAIN_APP_UID"]
end

Instance Method Details

#deploy(instruction_id = nil) ⇒ Object



51
52
53
54
55
56
57
58
59
# File 'app/models/sibling.rb', line 51

def deploy(instruction_id=nil)
  self.deploys.create!(
    instruction_id: instruction_id,
    manual: !instruction_id,
    git_repo: git_repo,
    heroku_repo: heroku_repo,
    heroku_app_name: heroku_app_name
  )
end