Class: NetResource

Inherits:
Object
  • Object
show all
Includes:
DataMapper::Resource
Defined in:
lib/octopus/models/net_resource.rb

Overview

Some kind of resource which we’re watching for changes out on the interweb. Could be an RSS feed, a web page, etc.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.expiredObject

Returns an array of all resources which have a next_update time which is less than or equal to Time.now.



45
46
47
# File 'lib/octopus/models/net_resource.rb', line 45

def self.expired
  all(:next_update.lte => Time.now)
end

Instance Method Details

#set_next_updateObject

Sets the next_update time equal to the current time plus the update_period for this resource.



52
53
54
55
# File 'lib/octopus/models/net_resource.rb', line 52

def set_next_update
  self.next_update = Time.now + update_period
  self.save
end

#validate_update_periodObject

Ensures that the update_period is not less than 20 seconds.



59
60
61
62
63
64
65
# File 'lib/octopus/models/net_resource.rb', line 59

def validate_update_period
  unless self.update_period.nil? || self.update_period < 20
    return true
  else
    [false, "Update period must be more than 20 seconds"]
  end
end

#validate_urlObject

Checks that the url property is formatted correctly.



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/octopus/models/net_resource.rb', line 30

def validate_url
  begin
    uri = ::URI.parse(self.url)
    if uri && uri.scheme == "http" || uri.scheme == "https"
      return true
    else
      return [false, "Url must be properly formatted"]
    end
  end
  rescue ::URI::InvalidURIError
end