Sha256: c305aa14a035a6b05957d82e01b6c302a3209637ece511d502b52a9ef381922d

Contents?: true

Size: 1.32 KB

Versions: 22

Compression:

Stored size: 1.32 KB

Contents

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

  PER_PAGE = 6

  field :name, :type => String
  field :descr, :type => String
  def description; descr; end

  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,  :optional => true
  belongs_to :city, :optional => true
  belongs_to :site, :optional => true
  has_many :newsitems

  belongs_to :user_profile, :optional => true, :class_name => 'IshModels::UserProfile', :inverse_of => :videos

  accepts_nested_attributes_for :site, :tag, :city

  def self.list
    [['', nil]] + Video.all.order_by( :created_at => :desc ).map { |item| [ "#{item.created_at.strftime('%Y%m%d')} #{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

  field :issue

end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
ish_models-0.0.33.85 lib/video.rb
ish_models-0.0.33.83 lib/video.rb
ish_models-0.0.33.79 lib/video.rb
ish_models-0.0.33.78 lib/video.rb
ish_models-0.0.33.77 lib/video.rb
ish_models-0.0.33.76 lib/video.rb
ish_models-0.0.33.75 lib/video.rb
ish_models-0.0.33.74 lib/video.rb
ish_models-0.0.33.73 lib/video.rb
ish_models-0.0.33.71 lib/video.rb
ish_models-0.0.33.70 lib/video.rb
ish_models-0.0.33.69 lib/video.rb
ish_models-0.0.33.68 lib/video.rb
ish_models-0.0.33.67 lib/video.rb
ish_models-0.0.33.66 lib/video.rb
ish_models-0.0.33.65 lib/video.rb
ish_models-0.0.33.64 lib/video.rb
ish_models-0.0.33.63 lib/video.rb
ish_models-0.0.33.62 lib/video.rb
ish_models-0.0.33.61 lib/video.rb