Sha256: 8ee7c470135cbbf7511c0fa2bd948960df1f4c1bd258bea9686a45b1d952ff48

Contents?: true

Size: 1.16 KB

Versions: 10

Compression:

Stored size: 1.16 KB

Contents

class Document::Base < Kuppayam::ApplicationRecord

	# Constants
  UPLOAD_LIMIT = 10

  self.table_name = "documents"
  self.inheritance_column = :image_type

  # Validations
  validates :document, :presence => true
  validate :file_size

  # Associations
  belongs_to :documentable, :polymorphic => true, optional: true

  # ------------------
  # Class Methods
  # ------------------

  # return an published record relation object with the search query in its where clause
  # Return the ActiveRecord::Relation object
  # == Examples
  #   >>> document.search(query)
  #   => ActiveRecord::Relation object
  scope :search, lambda { |query| where("LOWER(imageable_type) LIKE LOWER('%#{query}%') OR\
                                        LOWER(imageable_id) LIKE LOWER('%#{query}%')")
                        }

  # ------------------
  # Instance Methods
  # ------------------

  def file_size
    if document && document.file && document.file.size.to_f > UPLOAD_LIMIT.megabytes.to_f
      errors.add(:document, "You cannot upload a document greater than #{UPLOAD_LIMIT.to_f} MB")
    end
  end

  def display_name
    "#{id} - #{self.class.name.split('::').last.titleize}"
  end

end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
kuppayam-0.1.5dev4 app/models/document/base.rb
kuppayam-0.1.5dev3 app/models/document/base.rb
kuppayam-0.1.5dev2 app/models/document/base.rb
kuppayam-0.1.5dev app/models/document/base.rb
kuppayam-0.1.5 app/models/document/base.rb
kuppayam-0.1.4dev app/models/document/base.rb
kuppayam-0.1.4 app/models/document/base.rb
kuppayam-0.1.3 app/models/document/base.rb
kuppayam-0.1.2 app/models/document/base.rb
kuppayam-0.1.1 app/models/document/base.rb