Sha256: 416e99e25ce5fb82d887a34fedb0997b12c38300d8804f797f56f1ea032b03a9

Contents?: true

Size: 938 Bytes

Versions: 2

Compression:

Stored size: 938 Bytes

Contents

module MixRailsAlbums::Concerns::Models::Album
  extend ActiveSupport::Concern

  included do

    include Mongoid::Document
    include Mongoid::Timestamps
    include Mongoid::Slug

    extend Enumerize

    field :title,         type: String
    field :description,   type: String
    field :date,          type: Date
    field :status,        type: String
    enumerize :status, in: [:published, :unpublished], default: :published, predicates: true

    validation_for_title
    validation_for_date

    slug :title, history: true do |current_object|
      current_object.title.parameterize
    end

    embeds_many :photos, cascade_callbacks: true
    
    scope :published, where(status: :published, :photos.ne => nil, :photos.exists => true)

  end

  module ClassMethods
    
    def validation_for_title
      validates_presence_of :title
    end

    def validation_for_date
      validates_presence_of :date
    end

  end

end

Version data entries

2 entries across 2 versions & 2 rubygems

Version Path
mix-rails-0.22.0 mix-rails-albums/lib/concerns/models/album.rb
mix-rails-albums-0.22.0 lib/concerns/models/album.rb