Sha256: 87e08d6abd7a7070851c30c550d5407214ce415191f2a0ab3f3138827715fa4c

Contents?: true

Size: 744 Bytes

Versions: 8

Compression:

Stored size: 744 Bytes

Contents

module Gaku
  class GradingMethodSet < ActiveRecord::Base

    has_many :grading_method_set_items, -> { order(:position) }
    has_many :grading_methods, through: :grading_method_set_items

    validates :name, presence: true, uniqueness: true

    before_save :ensure_first_is_primary, on: :create

    def make_primary
      GradingMethodSet.where.not(id: id).update_all({ primary: false })
      update_attribute(:primary, true)
    end

    def items
      grading_method_set_items
    end

    private

    def ensure_first_is_primary
      self.primary = true if GradingMethodSet.all.empty?
    end

    def update_items_positions(id, index)
      grading_method_set_items.update_all( { position: index }, { id: id } )
    end

  end
end

Version data entries

8 entries across 8 versions & 2 rubygems

Version Path
gaku-0.1.1 core/app/models/gaku/grading_method_set.rb
gaku_core-0.1.1 app/models/gaku/grading_method_set.rb
gaku-0.1.0 core/app/models/gaku/grading_method_set.rb
gaku_core-0.1.0 app/models/gaku/grading_method_set.rb
gaku_core-0.0.3 app/models/gaku/grading_method_set.rb
gaku-0.0.3 core/app/models/gaku/grading_method_set.rb
gaku-0.0.2 core/app/models/gaku/grading_method_set.rb
gaku_core-0.0.2 app/models/gaku/grading_method_set.rb