Class: SirTracksAlot::Persistable

Inherits:
Ohm::Model
  • Object
show all
Defined in:
lib/sir_tracks_alot/persistable.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_or_create(attributes) ⇒ Object


7
8
9
10
# File 'lib/sir_tracks_alot/persistable.rb', line 7

def self.find_or_create(attributes)
  models = self.find(attributes)
  models.empty? ? self.create(attributes.merge(:created_at => Clock.now)) : models.first
end

Instance Method Details

#==(comparee) ⇒ Object

Objects are equal if they have the same unique custom identifier.


23
24
25
# File 'lib/sir_tracks_alot/persistable.rb', line 23

def ==(comparee)
  self.id == comparee.id
end

#eql?(comparee) ⇒ Boolean

Simply delegate to == in this example.

Returns:

  • (Boolean)

17
18
19
# File 'lib/sir_tracks_alot/persistable.rb', line 17

def eql?(comparee)
  self == comparee
end

#hashObject


12
13
14
# File 'lib/sir_tracks_alot/persistable.rb', line 12

def hash
  self.id
end

#to_hashObject


27
28
29
# File 'lib/sir_tracks_alot/persistable.rb', line 27

def to_hash
  super
end