Module: Incline::Extensions::ActiveRecordBase
- Defined in:
- lib/incline/extensions/active_record_base.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#<=>(other) ⇒ Object
Compares by code, name, or to_s depending on if the code or name attributes are present.
-
#==(other) ⇒ Object
Tests for equality on ID if available.
-
#inspect ⇒ Object
:nodoc:.
-
#to_s ⇒ Object
:nodoc:.
Class Method Details
.included(base) ⇒ Object
300 301 302 303 304 |
# File 'lib/incline/extensions/active_record_base.rb', line 300 def self.included(base) base.class_eval do extend ClassMethods end end |
Instance Method Details
#<=>(other) ⇒ Object
Compares by code, name, or to_s depending on if the code or name attributes are present.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# 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) ⇒ Object
Tests for equality on ID if available.
20 21 22 23 24 25 26 27 28 29 30 31 32 |
# 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 |
#inspect ⇒ Object
:nodoc:
14 15 16 |
# File 'lib/incline/extensions/active_record_base.rb', line 14 def inspect # :nodoc: "#<#{self.class}:#{self.object_pointer} #{to_s}>" end |
#to_s ⇒ Object
:nodoc:
6 7 8 9 10 11 12 |
# File 'lib/incline/extensions/active_record_base.rb', line 6 def to_s # :nodoc: if respond_to?(:name) send :name else "ID = #{id}" end end |