Sha256: 61f6190c0e0e8c0f6ebf2e8c303ad51821c0e31196f39be12c662b5435ab8770

Contents?: true

Size: 603 Bytes

Versions: 2

Compression:

Stored size: 603 Bytes

Contents

require 'active_support/concern'

module Spina
  module Part
    extend ActiveSupport::Concern

    included do
      attr_accessor :position

      validates :name, :title, :partable_type, presence: true

      scope :sorted, -> { order(:position) }
    end

    def to_s
      name
    end

    def content
      self.partable.try(:content) || self.partable
    end

    def partable_attributes=(attributes)
      if self.partable.present?
        self.partable.assign_attributes(attributes)
      else
        self.partable = self.partable_type.constantize.new(attributes)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
spina-0.10.0 app/models/concerns/spina/part.rb
spina-0.9.0 app/models/concerns/spina/part.rb