Sha256: e4d3a2c1b4c93fc4c8a7d949cd1d9b095595d40c6e19ed76d31b9968161d212a

Contents?: true

Size: 1.13 KB

Versions: 17

Compression:

Stored size: 1.13 KB

Contents

class Video
  include Mongoid::Document
  include Mongoid::Timestamps

  PER_PAGE = 6

  field :name, :type => String
  field :descr, :type => String

  default_scope ->{ where({ :is_public => true, :is_trash => false }).order_by({ :created_at => :desc }) }

  field :is_trash, :type => Boolean, :default => false
  field :is_public, :type => Boolean, :default => true
  field :is_feature, :type => Boolean, :default => false

  field :x, :type => Float
  field :y, :type => Float

  field :lang, :type => String, :default => 'en'

  field :youtube_id, :type => String
  validates :youtube_id, :uniqueness => true, :presence => true

  belongs_to :tag
  belongs_to :city
  belongs_to :site
  validates :site, :presence => true
  belongs_to :user
  validates :user, :presence => true
  
  accepts_nested_attributes_for :site, :tag, :city

  def self.list
    [['', nil]] + Video.all.order_by( :name => :desc ).map { |item| [ item.name, item.id ] }
  end

  set_callback( :create, :before ) do |doc|
    if doc.is_public
      doc.city.add_newsitem( doc ) unless doc.city.blank?
      doc.site.add_newsitem( doc ) unless doc.site.blank?
    end
    
  end

end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
ish_models-0.0.33.16 lib/video.rb
ish_models-0.0.33.15 lib/video.rb
ish_models-0.0.33.14 lib/video.rb
ish_models-0.0.33.13 lib/video.rb
ish_models-0.0.33.12 lib/video.rb
ish_models-0.0.33.11 lib/video.rb
ish_models-0.0.33.10 lib/video.rb
ish_models-0.0.33.8 lib/video.rb
ish_models-0.0.33.7 lib/video.rb
ish_models-0.0.33.6 lib/video.rb
ish_models-0.0.33.5 lib/video.rb
ish_models-0.0.33 lib/video.rb
ish_models-0.0.32 lib/video.rb
ish_models-0.0.31 lib/video.rb
ish_models-0.0.30 lib/video.rb
ish_models-0.0.29.10 lib/video.rb
ish_models-0.0.29.9 lib/video.rb