Sha256: 5b2e800d91272ac681b38f0905ee9207b76b3ae62e17744641c9dd530c34ae13

Contents?: true

Size: 721 Bytes

Versions: 1

Compression:

Stored size: 721 Bytes

Contents

require 'ohm'

module Tweetable
  class Persistable < Ohm::Model
    attribute :created_at
    attribute :updated_at

    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
    
    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

    def client
      Tweetable.client
    end
    
    def config
      Tweetable.config
    end
    
    protected
    
    def validate
      
    end        
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
tweetable-0.1.14 lib/tweetable/persistable.rb