Class: Rgr::Globber

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeGlobber

Returns a new instance of Globber.



5
6
7
8
# File 'lib/rgr/globber.rb', line 5

def initialize
  @paths = []
  @ignored_prefixes = []
end

Instance Attribute Details

#ignored_prefixesObject (readonly)

Returns the value of attribute ignored_prefixes.



3
4
5
# File 'lib/rgr/globber.rb', line 3

def ignored_prefixes
  @ignored_prefixes
end

#pathsObject (readonly)

Returns the value of attribute paths.



3
4
5
# File 'lib/rgr/globber.rb', line 3

def paths
  @paths
end

Instance Method Details

#add_path(path) ⇒ Object



10
11
12
# File 'lib/rgr/globber.rb', line 10

def add_path(path)
  paths << path
end

#each_fileObject



18
19
20
21
22
23
24
25
# File 'lib/rgr/globber.rb', line 18

def each_file
  return enum_for(:each_file) unless block_given?

  unfiltered_files.each do |file|
    next if ignored?(file)
    yield file
  end
end

#glob_path(path) ⇒ Object



43
44
45
46
47
48
49
# File 'lib/rgr/globber.rb', line 43

def glob_path(path)
  if File.file?(path)
    [path]
  else
    Dir["#{path}/**/*.rb"]
  end
end

#ignore_prefix(prefix) ⇒ Object



14
15
16
# File 'lib/rgr/globber.rb', line 14

def ignore_prefix(prefix)
  ignored_prefixes << prefix
end

#ignored?(file) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
31
# File 'lib/rgr/globber.rb', line 27

def ignored?(file)
  ignored_prefixes.any? { |prefix|
    file.start_with?(prefix)
  }
end

#unfiltered_filesObject



33
34
35
36
37
38
39
40
41
# File 'lib/rgr/globber.rb', line 33

def unfiltered_files
  if paths.empty?
    Dir["**/*.rb"]
  else
    paths.flat_map { |path|
      glob_path(path)
    }
  end
end