Sha256: 779e56270ff20d23ba59a5927c525d0a5cb5bef845afb61e71887d3fac88ce75

Contents?: true

Size: 781 Bytes

Versions: 10

Compression:

Stored size: 781 Bytes

Contents

module Tenon
  module TenonContent
    class Row < Tenon::ApplicationRecord
      self.table_name = 'tenon_tenon_content_rows'

      # Scopes, attachments, etc.
      include Tenon::Reorderable
      default_scope -> { order(:list_order) }

      # Validations

      # Relationships
      belongs_to :item
      has_many :pieces, -> { order 'position' }, class_name: 'TenonContent::Piece', dependent: :destroy

      # Nested
      accepts_nested_attributes_for :pieces

      def set_row_type(row_type)
        self.row_type = row_type
        build_pieces
      end

      def row_type_class
        "Tenon::TenonContent::RowTypes::#{row_type}".constantize
      end

      private

      def build_pieces
        row_type_class.add_pieces_to(self)
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
tenon-2.1.0 app/models/tenon/tenon_content/row.rb
tenon-2.0.8 app/models/tenon/tenon_content/row.rb
tenon-2.0.7 app/models/tenon/tenon_content/row.rb
tenon-2.0.6 app/models/tenon/tenon_content/row.rb
tenon-2.0.5 app/models/tenon/tenon_content/row.rb
tenon-2.0.4 app/models/tenon/tenon_content/row.rb
tenon-2.0.3 app/models/tenon/tenon_content/row.rb
tenon-2.0.2 app/models/tenon/tenon_content/row.rb
tenon-2.0.1 app/models/tenon/tenon_content/row.rb
tenon-2.0.0 app/models/tenon/tenon_content/row.rb