Class: Relinker::Discoverer
- Inherits:
-
Object
- Object
- Relinker::Discoverer
- Defined in:
- lib/relinker/discoverer.rb
Instance Attribute Summary collapse
-
#cache_file ⇒ Object
readonly
Returns the value of attribute cache_file.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #collect(base_dir) ⇒ Object
- #discover(base_dir) ⇒ Object
-
#initialize(cache_file, options = {}) ⇒ Discoverer
constructor
A new instance of Discoverer.
- #list(base_dir) ⇒ Object
- #resort_cache ⇒ Object
Constructor Details
#initialize(cache_file, options = {}) ⇒ Discoverer
Returns a new instance of Discoverer.
9 10 11 12 |
# File 'lib/relinker/discoverer.rb', line 9 def initialize(cache_file, = {}) @cache_file = cache_file @options = end |
Instance Attribute Details
#cache_file ⇒ Object (readonly)
Returns the value of attribute cache_file.
7 8 9 |
# File 'lib/relinker/discoverer.rb', line 7 def cache_file @cache_file end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/relinker/discoverer.rb', line 7 def @options end |
Instance Method Details
#collect(base_dir) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/relinker/discoverer.rb', line 14 def collect(base_dir) File.open(cache_file, "a+") do |cache| discover(base_dir) do |file, checksum| cache.write("#{checksum}$$$\t#{file}\n") end end resort_cache end |
#discover(base_dir) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/relinker/discoverer.rb', line 28 def discover(base_dir) children = Pathname.new(base_dir).children children.each do |child| next if child.symlink? if child.directory? discover(child) { |file| yield(file, checksum(file)) } else yield(child, checksum(child)) end end end |
#list(base_dir) ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/relinker/discoverer.rb', line 40 def list(base_dir) files = [] discover(base_dir) do |file, check| files << { path: file.to_s, checksum: check } end files end |
#resort_cache ⇒ Object
23 24 25 26 |
# File 'lib/relinker/discoverer.rb', line 23 def resort_cache system("cat #{cache_file} | sort | uniq | cat > #{cache_file}.tmp \ && mv #{cache_file}.tmp #{cache_file}") end |