Sha256: 33befc1da6b9e52153883789076eaf43ef3c78cdfad11c400fa4886c8eb51669

Contents?: true

Size: 910 Bytes

Versions: 1

Compression:

Stored size: 910 Bytes

Contents

module Writefully
  class Site < ActiveRecord::Base
    extend FriendlyId

    HOOK_EVENTS = %w(push collaborator)

    friendly_id :name, use: :slugged

    after_save :setup_repository, if: -> { repository.nil? }
    after_save :clear_errors,     if: -> { healthy_changed? and healthy? }

    belongs_to :owner, class_name: "Writefully::Authorship"

    has_many :posts, -> { order(:position) }

    def setup_repository
      Writefully.add_job :handyman, { task: :build, auth_token: owner.data["auth_token"], 
                                                    user_name: owner.data["user_name"],
                                                    site_id: id, site_slug: slug   }
    end

    def processing_errors
      Writefully.redis.with { |c| c.smembers "site:#{self.id}:errors" }
    end

    def clear_errors
      Writefully.redis.with { |c| c.del("site:#{self.id}:errors") }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
writefully-0.3.6 app/models/writefully/site.rb