Sha256: 44ef31f4b8872ce6a4c9feb160a37e704b0d75a8a0bf2f09f78f4b3bfffd7e40
Contents?: true
Size: 1.05 KB
Versions: 2
Compression:
Stored size: 1.05 KB
Contents
module StaleFish class FixtureDefinition attr_accessor :tag, :file_path, :source_url, :last_updated_at, :response attr_accessor :update_frequency def is_stale? StaleFish.force_flag || last_updated_at.nil? || ((DateTime.now + eval(update_frequency)) < last_updated_at) end def update! begin self.response = StaleFish.http.resource(source_url).get File.open(eval(file_path), 'w') { |file| file.write(response.body.to_s) } self.last_updated_at = DateTime.now rescue Resourceful::UnsuccessfulHttpRequestError raise StaleFish::FixtureUpdateFailure, "#{key}'s source: #{value['source']} returned unsuccessfully." rescue ArgumentError raise StaleFish::MalformedSourceURL, "#{key}'s source: #{value['source']} is not a valid URL path. Most likely it's missing a trailing slash." end end def output_hash <<-EOF #{tag}: file_path: #{file_path} source_url: #{source_url} update_frequency: #{update_frequency} last_updated_at: #{last_updated_at} EOF end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
stale_fish-1.2.4 | lib/stale_fish/fixture_definition.rb |
stale_fish-1.2.3 | lib/stale_fish/fixture_definition.rb |