Class: FilesLoader::Collector

Inherits:
Object
  • Object
show all
Defined in:
lib/files_loader/collector.rb

Instance Method Summary collapse

Constructor Details

#initialize(path, options) ⇒ Collector

Returns a new instance of Collector.



4
5
6
7
8
# File 'lib/files_loader/collector.rb', line 4

def initialize(path, options)
  @path = path
  @files = []
  @options = options
end

Instance Method Details

#except?(file) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
29
# File 'lib/files_loader/collector.rb', line 25

def except?(file)
  (@options[:except]||[]).find do|reg|
    Regexp.new(reg) =~ file
  end
end

#fetch(path) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/files_loader/collector.rb', line 15

def fetch(path)
  Dir[ path + '/*' ].sort.each do|file|
    if File.directory?(file)
      fetch(file)
    elsif file =~ /.rb$/
      @files << file unless except?(file)
    end
  end
end

#loadObject



31
32
33
# File 'lib/files_loader/collector.rb', line 31

def load
  @files.each { |file| require file }
end

#runObject



10
11
12
13
# File 'lib/files_loader/collector.rb', line 10

def run
  fetch(@path)
  load
end