Class: DirectoryRunner

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

Constant Summary collapse

EXCLUDE_FILES =
%w{. .. .sass-cache}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(root_dir) ⇒ DirectoryRunner

Returns a new instance of DirectoryRunner.



4
5
6
7
# File 'lib/directory_runner.rb', line 4

def initialize root_dir
  @root_dir = root_dir
  raise "FileNotFound" if @root_dir.nil?
end

Instance Method Details

#process(dir = nil, &block) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/directory_runner.rb', line 9

def process(dir = nil, &block)
  dir ||= @root_dir

  Dir.foreach(dir) do |filename|
    unless EXCLUDE_FILES.include? filename
      act_path = File.join(dir, filename)
      block.call act_path
      self.process act_path, &block if File.directory? act_path
    end
  end
end