Class: TransmissionRSS::SeenFile
- Extended by:
- Forwardable
- Defined in:
- lib/transmission-rss/seen_file.rb
Overview
Persist seen torrent URLs
Constant Summary collapse
- DEFAULT_LEGACY_PATH =
File.join(Etc.getpwuid.dir, '.config/transmission/seen-torrents.conf')
- DEFAULT_PATH =
File.join(Etc.getpwuid.dir, '.config/transmission/seen')
Instance Method Summary collapse
- #add(url) ⇒ Object
- #clear! ⇒ Object
- #include?(url) ⇒ Boolean
-
#initialize(path = nil, legacy_path = nil) ⇒ SeenFile
constructor
A new instance of SeenFile.
Constructor Details
#initialize(path = nil, legacy_path = nil) ⇒ SeenFile
Returns a new instance of SeenFile.
19 20 21 22 23 24 25 26 27 |
# File 'lib/transmission-rss/seen_file.rb', line 19 def initialize(path = nil, legacy_path = nil) @legacy_path = legacy_path || DEFAULT_LEGACY_PATH @path = path || DEFAULT_PATH initialize_path! migrate! @seen = Set.new(file_to_array(@path)) end |
Instance Method Details
#add(url) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/transmission-rss/seen_file.rb', line 29 def add(url) hash = digest(url) return if @seen.include?(hash) @seen << hash open(@path, 'a') do |f| f.write(hash + "\n") end end |
#clear! ⇒ Object
41 42 43 44 |
# File 'lib/transmission-rss/seen_file.rb', line 41 def clear! @seen.clear open(@path, 'w') {} end |
#include?(url) ⇒ Boolean
46 47 48 |
# File 'lib/transmission-rss/seen_file.rb', line 46 def include?(url) @seen.include?(digest(url)) end |