Sha256: 871293e518e94ff185e0b1b5281ceef357d37744230d12153f91774e3539c87d

Contents?: true

Size: 661 Bytes

Versions: 3

Compression:

Stored size: 661 Bytes

Contents

module BitPlayer
  class ContentModule < ActiveRecord::Base
    has_many :content_providers,
      class_name: "BitPlayer::ContentProvider",
      foreign_key: :bit_player_content_module_id,
      inverse_of: :content_module

    validates :title, :context, :position, presence: true
    validates_numericality_of :position, greater_than_or_equal_to: 1
    validates_uniqueness_of :position, scope: :context

    def provider(position)
      content_providers.where(position: position).first ||
        BitPlayer::ContentProviders::Null.new(self)
    end

    def provider_exists?(position)
      content_providers.exists?(position: position)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
bit_player-0.1.3 app/models/bit_player/content_module.rb
bit_player-0.1.2 app/models/bit_player/content_module.rb
bit_player-0.1.1 app/models/bit_player/content_module.rb