Sha256: 7a364c3ef401a7ce65da350a36026ffca63b9c24d3677b84edae02aa266a7b2e

Contents?: true

Size: 895 Bytes

Versions: 27

Compression:

Stored size: 895 Bytes

Contents

module Dorsale
  module Flyboy
    class TaskComment < ActiveRecord::Base
      self.table_name = "dorsale_flyboy_task_comments"

      belongs_to :task
      belongs_to :author, polymorphic: true

      validates :author,      presence: true
      validates :task,        presence: true
      validates :date,        presence: true
      validates :description, presence: true
      validates :progress,    inclusion: {in: 0..100}

      default_scope -> { order("created_at DESC") }

      def initialize(*args)
        super

        self.date     = Time.now if date.nil?

        if progress.nil?
          self.progress = task ? task.progress : 0
        end
      end

      after_create :update_task_progress

      def update_task_progress
        task.update_attributes(
          :progress => progress,
          :done     => progress.equal?(100)
        )
      end
    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
dorsale-2.1.6 app/models/dorsale/flyboy/task_comment.rb
dorsale-2.1.5 app/models/dorsale/flyboy/task_comment.rb
dorsale-2.1.4 app/models/dorsale/flyboy/task_comment.rb
dorsale-2.1.3 app/models/dorsale/flyboy/task_comment.rb
dorsale-2.1.2 app/models/dorsale/flyboy/task_comment.rb
dorsale-2.1.1 app/models/dorsale/flyboy/task_comment.rb
dorsale-2.1.0 app/models/dorsale/flyboy/task_comment.rb