Sha256: 052fc75b115857c05fafe795421b8c8c4ef303e24b969bdc026b7156987ef28f

Contents?: true

Size: 1.32 KB

Versions: 17

Compression:

Stored size: 1.32 KB

Contents

class Sprint < ActiveRecord::Base

  has_many :sprint_tasks
  has_many :tasks, through: :sprint_tasks, extend: UniqueAdd
  has_many :tickets, through: :tasks

  before_validation :set_default_end_date, on: :create

  def self.current
    find_by_date Date.today
  end

  def self.find_by_date(date)
    date = date.to_date if date.respond_to?(:to_date)
    find_by_end_date end_date_for(date)
  end

  def self.find_by_date!(date)
    date = date.to_date if date.respond_to?(:to_date)
    find_or_create_by(end_date: end_date_for(date))
  end

  def self.end_date_for(date)
    days_until_friday = 5 - date.wday
    days_until_friday += 7 if days_until_friday < 0
    date + days_until_friday
  end

  def previous
    Sprint.find_or_create_by(end_date: end_date - 7)
  end

  def next
    Sprint.find_or_create_by(end_date: end_date + 7)
  end

  def start_date
    end_date.beginning_of_week
  end

  def starts_at
    start_date.beginning_of_day
  end

  def ends_at
    end_date.end_of_day
  end

  def to_range
    starts_at..ends_at
  end

  def completed?
    Date.today > end_date
  end

  def lock!
    update_column :locked, true
  end

  def unlock!
    update_column :locked, false
  end

  def range
    starts_at..ends_at
  end

private

  def set_default_end_date
    self.end_date ||= self.class.end_date_for(Date.today)
  end

end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
houston-core-0.8.0.pre app/models/sprint.rb
houston-core-0.7.0 app/models/sprint.rb
houston-core-0.7.0.beta4 app/models/sprint.rb
houston-core-0.7.0.beta3 app/models/sprint.rb
houston-core-0.7.0.beta2 app/models/sprint.rb
houston-core-0.7.0.beta app/models/sprint.rb
houston-core-0.6.3 app/models/sprint.rb
houston-core-0.6.2 app/models/sprint.rb
houston-core-0.6.1 app/models/sprint.rb
houston-core-0.6.0 app/models/sprint.rb
houston-core-0.5.6 app/models/sprint.rb
houston-core-0.5.5 app/models/sprint.rb
houston-core-0.5.4 app/models/sprint.rb
houston-core-0.5.3 app/models/sprint.rb
houston-core-0.5.2 app/models/sprint.rb
houston-core-0.5.1 app/models/sprint.rb
houston-core-0.5.0 app/models/sprint.rb