Sha256: ba8af74644b87106e8e8e65c81237e801461b6a285042cef78224835bc0e35bc

Contents?: true

Size: 868 Bytes

Versions: 11

Compression:

Stored size: 868 Bytes

Contents

module Hicube
  class Document

    include Mongoid::Document
    include Mongoid::Timestamps
    
    #
    # Relations
    #
    has_and_belongs_to_many :tags, class_name: 'Hicube::Tag'

    #
    # Uploaders
    #
    mount_uploader :file, FileUploader
    mount_uploader :image, ImageUploader

    #
    # Fields
    #
    field :n, type: String,
      as:           :name
    validates_presence_of :name
    validates_uniqueness_of :name,
      allow_blank:          :false,
      message:              'is not unique or cannot be blank'

    #
    # Scopes
    #
    scope :files, -> { where(:file.ne => nil) }
    scope :images, -> { where(:image.ne => nil) }

    def to_s
      self.name
    end

    def to_liquid
      {
        'url' => (self.image.nil? ? self.file_url : self.image_url),
        'tags' => self.tags.map(&:name)
      }
    end

  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
hicube-0.0.11 app/models/hicube/document.rb
hicube-0.0.10 app/models/hicube/document.rb
hicube-0.0.9 app/models/hicube/document.rb
hicube-0.0.8 app/models/hicube/document.rb
hicube-0.0.7 app/models/hicube/document.rb
hicube-0.0.6 app/models/hicube/document.rb
hicube-0.0.5 app/models/hicube/document.rb
hicube-0.0.4 app/models/hicube/document.rb
hicube-0.0.3 app/models/hicube/document.rb
hicube-0.0.2 app/models/hicube/document.rb
hicube-0.0.1 app/models/hicube/document.rb