Class: Tweetable::Persistable

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

Direct Known Subclasses

Authorization, Collection, Link, Message, Search, User

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.find_or_create(key, value) ⇒ Object



8
9
10
11
12
# File 'lib/tweetable/persistable.rb', line 8

def self.find_or_create(key, value)      
  attributes = {key => value} # this persistable uses an old interface
  models = self.find(attributes)
  models.empty? ? self.create(attributes.merge(:created_at => Time.now.utc.to_s)) : models.first
end

Instance Method Details

#clientObject



18
19
20
# File 'lib/tweetable/persistable.rb', line 18

def client
  Tweetable.client
end

#configObject



22
23
24
# File 'lib/tweetable/persistable.rb', line 22

def config
  Tweetable.config
end

#needs_update?(force = false) ⇒ Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/tweetable/persistable.rb', line 14

def needs_update?(force = false)
  force or self.updated_at.blank? or (Time.parse(self.updated_at) + self.config[:update_delay]) < Time.now.utc
end