module Incline::Extensions::ActiveRecordBase

Public Class Methods

included(base) click to toggle source
# File lib/incline/extensions/active_record_base.rb, line 300
def self.included(base)
  base.class_eval do
    extend ClassMethods
  end
end

Public Instance Methods

<=>(other) click to toggle source

Compares by code, name, or to_s depending on if the code or name attributes are present.

# File lib/incline/extensions/active_record_base.rb, line 36
def <=>(other)
  m = self.class.default_sort_method
  my_val = send(m)

  # other can be a string or a model of the same type as this model.
  other_val =
      if other.is_a?(::String)
        other
      elsif other.class == self.class
        other.send(m)
      else
        nil
      end

  my_val <=> other_val
end
==(other) click to toggle source

Tests for equality on ID if available.

# File lib/incline/extensions/active_record_base.rb, line 20
def ==(other)
  if self.class.attribute_names.include?('id')
    if other.is_a?(::Numeric)
      id == other
    elsif other.class == self.class
      id == other.id
    else
      false
    end
  else
    self.inspect == other.inspect
  end
end