Sha256: 043de763aabc063a76efddf0715378dd8be650f79f01c054fa34be1151322ccd

Contents?: true

Size: 1.14 KB

Versions: 7

Compression:

Stored size: 1.14 KB

Contents

class Vacancy < ActiveRecord::Base
  include StateMachines::Vacancy
  
  belongs_to :project
  belongs_to :offeror, class_name: 'User'
  belongs_to :author, class_name: 'User'
  belongs_to :resource, polymorphic: true
  belongs_to :project_user
  
  has_many :candidatures, dependent: :destroy
  has_many :comments, as: :commentable, dependent: :destroy
  
  accepts_nested_attributes_for :candidatures, allow_destroy: true, reject_if: ->(t) { t['name'].blank? }
  scope :open, -> { where(state: 'open') }
  
  
  validates :project_id, presence: true
  validates :offeror_id, presence: true
  validates :name, presence: true, uniqueness: { scope: :project_id }
  validates :text, presence: true
  validates :limit, presence: true
  
  attr_accessible :project_id, :name, :text, :limit, :candidatures_attributes
  
  extend FriendlyId
  
  friendly_id :name, use: :slugged
  
  before_validation :set_defaults
  
  def candidatures_left
    limit - candidatures.accepted.count
  end
  
  protected
  
  def set_defaults
    if project
      self.offeror_id = project.user_id
      self.author_id = project.user_id unless self.author_id.present?
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
voluntary_recruiting-0.0.1 app/models/vacancy.rb
voluntary-0.3.0 app/models/vacancy.rb
voluntary-0.2.4 app/models/vacancy.rb
voluntary-0.2.3 app/models/vacancy.rb
voluntary-0.2.2 app/models/vacancy.rb
voluntary-0.2.1 app/models/vacancy.rb
voluntary-0.2.0 app/models/vacancy.rb