Sha256: 00979abf51a87ff924e91ecd06b510481c6ef36a58ffd73d3b021c07c0de7ce6

Contents?: true

Size: 941 Bytes

Versions: 5

Compression:

Stored size: 941 Bytes

Contents

class Ecm::Staff::Position < Ecm::Staff::Base
  # associations
  has_many :person_positions, dependent: :restrict_with_error
  has_many :people, through: :person_positions,
                    class_name: Ecm::Staff::Configuration.person_class_name

  # callbacks
  after_initialize :set_defaults, if: :new_record?

  # friendly id support
  extend FriendlyId
  friendly_id :name, use: [:slugged]

  translates :description, :name, :slug if ActiveRecord::Base.connection.table_exists?(:ecm_staff_position_translations)

  # markup support
  acts_as_markup language: :variable,
                 columns: [:description]

  # nested set support
  acts_as_nested_set

  # validations
  validates :name, presence: true,
                   uniqueness: true

  def people_count
    people.count
  end

  def to_s
    name
  end

  private

  def set_defaults
    self.markup_language ||= Ecm::Staff::Configuration.default_markup_language
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
ecm_staff2-3.1.1 app/models/ecm/staff/position.rb
ecm_staff2-3.1.0 app/models/ecm/staff/position.rb
ecm_staff2-3.0.2 app/models/ecm/staff/position.rb
ecm_staff2-3.0.1 app/models/ecm/staff/position.rb
ecm_staff2-3.0.0 app/models/ecm/staff/position.rb