Class: Frett::Indexer
- Inherits:
-
Object
- Object
- Frett::Indexer
- Defined in:
- lib/frett/indexer.rb
Instance Method Summary collapse
- #index! ⇒ Object
-
#initialize(options = {}) ⇒ Indexer
constructor
A new instance of Indexer.
- #remove_file(filename) ⇒ Object
- #update_file(filename) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Indexer
Returns a new instance of Indexer.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/frett/indexer.rb', line 8 def initialize( = {}) @options = index! ::Listen.to(Frett::Config.working_dir) do |modified, added, removed| modified.each do |filename| update_file(filename) end added.each do |filename| update_file(filename) end removed.each do |filename| remove_file(filename) end end end |
Instance Method Details
#index! ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/frett/indexer.rb', line 27 def index! adapter.write do |index| Dir.glob(File.join(Frett::Config.working_dir, "**/*"), File::FNM_CASEFOLD) do |filename| if process?(filename) && needs_index?(filename) index_file(index, filename) end end end end |
#remove_file(filename) ⇒ Object
37 38 39 40 41 42 |
# File 'lib/frett/indexer.rb', line 37 def remove_file(filename) return if filename.include?(Frett::Config.directory) adapter.write do |index| remove_from_index(index, filename) end end |
#update_file(filename) ⇒ Object
44 45 46 47 48 49 50 |
# File 'lib/frett/indexer.rb', line 44 def update_file(filename) return unless process?(filename) adapter.write do |index| remove_from_index(index, filename) index_file(index, filename) end end |