Sha256: 8f6a59e3b1e7be1dc8ec63a2fde23380f56ce0a404f11f913473b0aef73cbc04

Contents?: true

Size: 680 Bytes

Versions: 4

Compression:

Stored size: 680 Bytes

Contents

module Flyboy
  class TaskComment < ActiveRecord::Base
    belongs_to :task

    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

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
flyboy-1.1.0 app/models/flyboy/task_comment.rb
flyboy-1.0.7 app/models/flyboy/task_comment.rb
flyboy-1.0.6 app/models/flyboy/task_comment.rb
flyboy-1.0.5 app/models/flyboy/task_comment.rb