Sha256: 3f1dd0b6c55d85027db8d2a30435fc223295e4c8f008d634e8521c73bcb33689

Contents?: true

Size: 1018 Bytes

Versions: 46

Compression:

Stored size: 1018 Bytes

Contents

require 'filesize'

class Document::Base < Kuppayam::ApplicationRecord

	# Constants
  UPLOAD_LIMIT = 5242880 # this is in bytes which is equivalent to 5 megabytes

  INSTRUCTIONS = [
    "<Override this instructions in your document class>"
  ]

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

  # Validations
  validates :document, :presence => true
  validates :documentable, :presence => true
  validate  :check_file_size

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

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

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

  def check_file_size
    if document && document.file && document.file.size.to_f > self.class::UPLOAD_LIMIT
      errors.add(:document, "You cannot upload a document greater than #{Filesize.from(self.class::UPLOAD_LIMIT.to_s+ " b").pretty}")
    end
  end

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

end

Version data entries

46 entries across 46 versions & 1 rubygems

Version Path
kuppayam-0.2.12.pre.materialize app/models/document/base.rb
kuppayam-0.2.11.pre.materialize app/models/document/base.rb
kuppayam-0.2.10.pre.materialize app/models/document/base.rb
kuppayam-0.2.9.pre.materialize app/models/document/base.rb
kuppayam-0.2.8.pre.materialize app/models/document/base.rb
kuppayam-0.2.7.pre.materialize app/models/document/base.rb
kuppayam-0.2.6.pre.materialize app/models/document/base.rb
kuppayam-0.2.5.pre.materialize app/models/document/base.rb
kuppayam-0.2.4.pre.materialize app/models/document/base.rb
kuppayam-0.2.3.pre.materialize app/models/document/base.rb
kuppayam-0.2.2.pre.materialize app/models/document/base.rb
kuppayam-0.2.1.pre.materialize app/models/document/base.rb
kuppayam-0.2.0.pre.materialize app/models/document/base.rb
kuppayam-0.1.39 app/models/document/base.rb
kuppayam-0.1.38 app/models/document/base.rb
kuppayam-0.1.37 app/models/document/base.rb
kuppayam-0.1.36 app/models/document/base.rb
kuppayam-0.1.35 app/models/document/base.rb
kuppayam-0.1.34 app/models/document/base.rb
kuppayam-0.1.33 app/models/document/base.rb