Skip to content

Commit

Permalink
Use lambdas, rescue the right thing
Browse files Browse the repository at this point in the history
  • Loading branch information
SeanRoberts committed Feb 25, 2012
1 parent febef3a commit 4594804
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app/models/group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def cache_path
end

def raw_xml
if !File.exist?(cache_path) || File.mtime(cache_path) < 1.hours.ago
if !File.exist?(cache_path) || File.mtime(cache_path) < lambda { 1.hours.ago }.call
remote_xml
else
local_xml
Expand Down
7 changes: 4 additions & 3 deletions app/models/player_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ class PlayerList
def initialize
@players = []
regex = /^#\s+\d+\s+\"(.+)\"\s+([_A-Za-z:0-9]+)\s/
raise "Error getting status." if raw_status.blank?
raw_status.split("\n")[8..-1].each do |line|
match = line.match(regex)
@players << Player.new(match.captures[0], match.captures[1]) if match
Expand All @@ -23,7 +24,7 @@ def players

private
def raw_status
if !File.exist?(cache_path) || File.mtime(cache_path) < 5.minutes.ago
if !File.exist?(cache_path) || File.mtime(cache_path) < lambda { 5.minutes.ago }.call
remote_status
else
local_status
Expand All @@ -38,8 +39,8 @@ def remote_status
f.puts status
f.close
status
rescue OpenURI::HTTPError
local_xml
rescue RCon::NetworkException
local_status
end
end

Expand Down

0 comments on commit 4594804

Please sign in to comment.