Sha256: 31dae11d83a43ce799080b14848ca16b5d250561070954ceb6f2a1a0afdc59c4

Contents?: true

Size: 1.01 KB

Versions: 36

Compression:

Stored size: 1.01 KB

Contents

# -*- encoding : utf-8 -*-
# @author Anton Mezin
module RailsConnector
  class Channel < AbstractModel
    self.primary_key = "channel_name"

    def self.table_name
      "#{table_name_prefix}" "channels"
    end

    has_many :news, :class_name => 'News', :foreign_key => 'channel_name'

    if ::Rails::VERSION::MAJOR == 4

      has_many :active_news, 
        lambda { where(['valid_from <= :now AND valid_until >= :now', {:now => Time.now.to_s(:number)}]) },
        :class_name => 'News', :foreign_key => 'channel_name'

      if ::Rails::VERSION::MINOR >= 1

        def self.scoped
          self.where(nil)
        end

      end

    elsif ::Rails::VERSION::MAJOR == 3

      has_many :active_news, :class_name => 'News', :foreign_key => 'channel_name',
        :conditions => ['valid_from <= :now AND valid_until >= :now', {:now => Time.now.to_s(:number)}]

    end

    has_many :objects, :through => :news

    def self.with_prefix(prefix)
      scoped.where(["channel_name LIKE ?", "#{prefix}%"])
    end

  end
end

Version data entries

36 entries across 36 versions & 1 rubygems

Version Path
infopark_reactor-1.26.1 app/models/rails_connector/channel.rb
infopark_reactor-1.26.0 app/models/rails_connector/channel.rb
infopark_reactor-1.25.2 app/models/rails_connector/channel.rb
infopark_reactor-1.25.1 app/models/rails_connector/channel.rb
infopark_reactor-1.25.0 app/models/rails_connector/channel.rb
infopark_reactor-1.24.1 app/models/rails_connector/channel.rb
infopark_reactor-1.24.0 app/models/rails_connector/channel.rb
infopark_reactor-1.23.1 app/models/rails_connector/channel.rb
infopark_reactor-1.23.0 app/models/rails_connector/channel.rb
infopark_reactor-1.23.0.beta2 app/models/rails_connector/channel.rb
infopark_reactor-1.22.6 app/models/rails_connector/channel.rb
infopark_reactor-1.22.5 app/models/rails_connector/channel.rb
infopark_reactor-1.22.4 app/models/rails_connector/channel.rb
infopark_reactor-1.22.3 app/models/rails_connector/channel.rb
infopark_reactor-1.22.2 app/models/rails_connector/channel.rb
infopark_reactor-1.22.1 app/models/rails_connector/channel.rb
infopark_reactor-1.22.0 app/models/rails_connector/channel.rb
infopark_reactor-1.21.0 app/models/rails_connector/channel.rb
infopark_reactor-1.20.4 app/models/rails_connector/channel.rb
infopark_reactor-1.20.3 app/models/rails_connector/channel.rb