Sha256: 8f13d79ab4f4962911be13a48ffcd0032f5f4455f08766fa3d87bc5d5154440e

Contents?: true

Size: 1.42 KB

Versions: 4

Compression:

Stored size: 1.42 KB

Contents

class Sibling < ActiveRecord::Base
  has_many :deploys
  has_many :instructions, through: :deploys

  validates :uid, presence: true, uniqueness: true
  validates :name, presence: true
  validates :git_repo, presence: true
  validates :heroku_repo, presence: true
  validates :heroku_app_name, presence: true

  class << self
    def main_app_uid
      ENV["MAIN_APP_UID"]
    end

    def main_app_hcard
      Microformats2.parse(main_app_uid).card
    end

    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, "304 Not Modified"
    end

    def async_consume
      Resque.enqueue(SiblingConsumer)
    end

    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

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

  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
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
g5_sibling_deployer_engine-0.4.1 app/models/sibling.rb
g5_sibling_deployer_engine-0.4.0 app/models/sibling.rb
g5_sibling_deployer_engine-0.3.3 app/models/sibling.rb
g5_sibling_deployer_engine-0.3.2 app/models/sibling.rb