Class: FilesLoader::Collector
- Inherits:
-
Object
- Object
- FilesLoader::Collector
- Defined in:
- lib/files_loader/collector.rb
Instance Method Summary collapse
- #except?(file) ⇒ Boolean
- #fetch(path) ⇒ Object
-
#initialize(path, options) ⇒ Collector
constructor
A new instance of Collector.
- #load ⇒ Object
- #run ⇒ Object
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, ) @path = path @files = [] @options = end |
Instance Method Details
#except?(file) ⇒ 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 |
#load ⇒ Object
31 32 33 |
# File 'lib/files_loader/collector.rb', line 31 def load @files.each { |file| require file } end |
#run ⇒ Object
10 11 12 13 |
# File 'lib/files_loader/collector.rb', line 10 def run fetch(@path) load end |