Class: TddiumStatus::Feed
- Inherits:
-
Object
- Object
- TddiumStatus::Feed
- Defined in:
- lib/tddium_status/feed.rb
Instance Attribute Summary collapse
-
#patterns ⇒ Object
this madness is here because macruby cannot deserialize regexes from yaml.
Instance Method Summary collapse
- #add_pattern(pattern) ⇒ Object
- #document ⇒ Object
- #expire ⇒ Object
-
#initialize(url, patterns = nil) ⇒ Feed
constructor
A new instance of Feed.
- #matches_pattern?(project) ⇒ Boolean
- #needs_refresh? ⇒ Boolean
- #projects ⇒ Object
- #save ⇒ Object
- #to_yaml_properties ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(url, patterns = nil) ⇒ Feed
Returns a new instance of Feed.
9 10 11 12 13 |
# File 'lib/tddium_status/feed.rb', line 9 def initialize(url, patterns = nil) @url_string = URI.parse(url.to_s).to_s @patterns = patterns @updated_at = nil end |
Instance Attribute Details
#patterns ⇒ Object
this madness is here because macruby cannot deserialize regexes from yaml
31 32 33 |
# File 'lib/tddium_status/feed.rb', line 31 def patterns @patterns end |
Instance Method Details
#add_pattern(pattern) ⇒ Object
23 24 25 26 27 28 |
# File 'lib/tddium_status/feed.rb', line 23 def add_pattern(pattern) return if patterns && patterns.include?(pattern) @patterns ||= [] @patterns << pattern expire end |
#document ⇒ Object
49 50 51 52 53 |
# File 'lib/tddium_status/feed.rb', line 49 def document @document = nil if needs_refresh? @document ||= REXML::Document.new(url.read) end |
#expire ⇒ Object
88 89 90 |
# File 'lib/tddium_status/feed.rb', line 88 def expire @updated_at = nil end |
#matches_pattern?(project) ⇒ Boolean
80 81 82 83 84 85 86 |
# File 'lib/tddium_status/feed.rb', line 80 def matches_pattern?(project) return true if patterns.nil? patterns.any? do |pattern| project.name =~ pattern end end |
#needs_refresh? ⇒ Boolean
45 46 47 |
# File 'lib/tddium_status/feed.rb', line 45 def needs_refresh? (@updated_at.to_i + TddiumStatus.refresh_every) < Time.now.to_i end |
#projects ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/tddium_status/feed.rb', line 55 def projects @projects = nil if needs_refresh? return @projects if @projects @projects = document.root.elements.map do |project_element| project_name = project_element.attributes['name'] project_url = project_element.attributes['webUrl'] = { :status => project_element.attributes['lastBuildStatus'], :build_time => project_element.attributes['lastBuildTime'], :activity => project_element.attributes['activity'] } project = Project.new(project_name, project_url, ) matches_pattern?(project) ? project : nil end.compact @updated_at = Time.now save @projects end |
#save ⇒ Object
92 93 94 |
# File 'lib/tddium_status/feed.rb', line 92 def save TddiumStatus.configuration.save_feed(self) end |
#to_yaml_properties ⇒ Object
15 16 17 |
# File 'lib/tddium_status/feed.rb', line 15 def to_yaml_properties [:@url_string, :@patterns, :@updated_at, :@projects] end |
#url ⇒ Object
19 20 21 |
# File 'lib/tddium_status/feed.rb', line 19 def url @url = URI.parse(@url_string) if @url_string.is_a?(String) end |