Sha256: 1008cd498efc257dbad567b1f8c677e3030997dda96542e70fe1b8078983824e

Contents?: true

Size: 554 Bytes

Versions: 10

Compression:

Stored size: 554 Bytes

Contents

module Spina
  class StructureItem < ApplicationRecord
    include Partable

    before_validation :ensure_position
    belongs_to :structure, optional: true
    has_many :structure_parts, dependent: :destroy

    scope :sorted_by_structure, -> { order(:position) }

    after_save -> { structure_parts.each(&:save) }

    validates_presence_of :position
    accepts_nested_attributes_for :structure_parts, allow_destroy: true

    alias_attribute :parts, :structure_parts

    def ensure_position
      self.position ||= Time.now.to_i
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
spina-1.2.0 app/models/spina/structure_item.rb
spina-1.1.4 app/models/spina/structure_item.rb
spina-1.1.3 app/models/spina/structure_item.rb
spina-1.1.2 app/models/spina/structure_item.rb
spina-1.1.1 app/models/spina/structure_item.rb
spina-1.1.0 app/models/spina/structure_item.rb
spina-1.0.3 app/models/spina/structure_item.rb
spina-1.0.2 app/models/spina/structure_item.rb
spina-1.0.1 app/models/spina/structure_item.rb
spina-1.0.0 app/models/spina/structure_item.rb