Sha256: 355838c73fc528d4b93f91994a555a162fac3e34ddc8e7fdf88b0f57356f4232

Contents?: true

Size: 952 Bytes

Versions: 25

Compression:

Stored size: 952 Bytes

Contents

module Writefully
  class Site < ActiveRecord::Base
    self.table_name = "writefully_sites"

    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

25 entries across 25 versions & 1 rubygems

Version Path
writefully-0.8.2 app/models/writefully/site.rb
writefully-0.8.1 app/models/writefully/site.rb
writefully-0.8.0 app/models/writefully/site.rb
writefully-0.7.1 app/models/writefully/site.rb
writefully-0.6.12 app/models/writefully/site.rb
writefully-0.6.11 app/models/writefully/site.rb
writefully-0.6.10 app/models/writefully/site.rb
writefully-0.6.9 app/models/writefully/site.rb
writefully-0.6.7 app/models/writefully/site.rb
writefully-0.6.6 app/models/writefully/site.rb
writefully-0.6.5 app/models/writefully/site.rb
writefully-0.6.4 app/models/writefully/site.rb
writefully-0.6.3 app/models/writefully/site.rb
writefully-0.6.2 app/models/writefully/site.rb
writefully-0.5.1 app/models/writefully/site.rb
writefully-0.5.0 app/models/writefully/site.rb
writefully-0.4.10 app/models/writefully/site.rb
writefully-0.4.8 app/models/writefully/site.rb
writefully-0.4.7 app/models/writefully/site.rb
writefully-0.4.6 app/models/writefully/site.rb