Module: Dis::Model::ClassMethods

Defined in:
lib/dis/model/class_methods.rb

Instance Method Summary collapse

Instance Method Details

#default_dis_attributesObject

Returns the default attribute names.



70
71
72
73
74
75
76
77
# File 'lib/dis/model/class_methods.rb', line 70

def default_dis_attributes
  {
    content_hash: :content_hash,
    content_length: :content_length,
    content_type: :content_type,
    filename: :filename
  }
end

#dis_attributesHash{Symbol => Symbol}

Returns the mapping of attribute names.

Returns:

  • (Hash{Symbol => Symbol})


9
10
11
# File 'lib/dis/model/class_methods.rb', line 9

def dis_attributes
  default_dis_attributes.merge(@dis_attributes ||= {})
end

#dis_attributes=(new_attributes) ⇒ Object

Sets the current mapping of attribute names. Use this if you want to override the attributes and database columns that Dis will use. Valid keys: :content_hash, :content_type, :content_length, :filename.

Examples:

class Document < ActiveRecord::Base
  include Dis::Model
  self.dis_attributes = { filename: :my_custom_filename }
end

Parameters:

  • new_attributes (Hash{Symbol => Symbol})

    attribute name overrides



26
27
28
# File 'lib/dis/model/class_methods.rb', line 26

def dis_attributes=(new_attributes)
  @dis_attributes = new_attributes
end

#dis_typeString

Returns the storage type name, which Dis will use for directory scoping. Defaults to the table name.

Examples:

class Document < ActiveRecord::Base; end
Document.dis_type # => "documents"

Returns:

  • (String)


38
39
40
# File 'lib/dis/model/class_methods.rb', line 38

def dis_type
  @dis_type ||= table_name
end

#dis_type=(new_type) ⇒ void

This method returns an undefined value.

Sets the storage type name.

Take care not to set the same name for multiple models, this will cause data loss when a record is destroyed.

Parameters:

  • new_type (String)

    the new type scope



49
50
51
# File 'lib/dis/model/class_methods.rb', line 49

def dis_type=(new_type)
  @dis_type = new_type
end

#validates_data_presencevoid

This method returns an undefined value.

Adds a presence validation on the data attribute.

This is preferred over validates :data, presence: true, which would load the data from storage on each save.

Examples:

class Document < ActiveRecord::Base
  include Dis::Model
  validates_data_presence
end


65
66
67
# File 'lib/dis/model/class_methods.rb', line 65

def validates_data_presence
  validates_with Dis::Validations::DataPresence
end