Sha256: 2b39ee5df482dead63456ddf9f8131ece871afa1a121f622eece0494c0b68afe

Contents?: true

Size: 1.5 KB

Versions: 16

Compression:

Stored size: 1.5 KB

Contents

class Report
  include ::Mongoid::Document
  include ::Mongoid::Timestamps
  include Ish::PremiumItem
  include Ish::Utils

  field :name, :type => String
  validates :name, :presence => true
  index({ :name => 1, :is_trash => 1 })

  field :slug
  validates :slug, :uniqueness => true, :presence => true
  index({ :slug => 1 }, { :unique => true })
  before_validation :set_slug, :on => :create

  field :subhead

  ## Can be one of: default (nil), longscroll,
  ##   wordpress e.g. https://piousbox.com/wp-json/wp/v2/posts?slug=intro
  # ITEM_TYPES = %w| longscroll wordpress |
  field :item_type, type: String

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

  field :is_trash, :type => Boolean, :default => false
  index({ :is_trash => 1, :is_public => 1 })

  field :is_public, :type => Boolean, :default => true
  index({ :is_public => 1 })
  scope :public, ->{ where({ is_public: true }) }

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

  belongs_to :user_profile, :optional => true, :class_name => 'Ish::UserProfile'

  has_one :photo

  has_many :newsitems

  ## @TODO: trash, remove
  def self.list conditions = { :is_trash => false }
    out = self.where( conditions ).order_by( :name => :asc ).limit( 100 )
    [['', nil]] + out.map { |item| [ item.name, item.id ] }
  end

  PER_PAGE = 10
  def self.paginates_per
    self::PER_PAGE
  end

  def self.clear
    if Rails.env.test?
      self.unscoped.each { |r| r.remove }
    end
  end

  def export_fields
    %w| name descr |
  end

end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
ish_models-0.0.33.246 lib/report.rb
ish_models-0.0.33.245 lib/report.rb
ish_models-0.0.33.244 lib/report.rb
ish_models-0.0.33.243 lib/report.rb
ish_models-0.0.33.242 lib/report.rb
ish_models-0.0.33.241 lib/report.rb
ish_models-0.0.33.240 lib/report.rb
ish_models-0.0.33.239 lib/report.rb
ish_models-0.0.33.238 lib/report.rb
ish_models-0.0.33.237 lib/report.rb
ish_models-0.0.33.236 lib/report.rb
ish_models-0.0.33.235 lib/report.rb
ish_models-0.0.33.234 lib/report.rb
ish_models-0.0.33.233 lib/report.rb
ish_models-0.0.33.232 lib/report.rb
ish_models-0.0.33.231 lib/report.rb