Class: Spellr::FileList

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/spellr/file_list.rb

Instance Method Summary collapse

Constructor Details

#initialize(*patterns) ⇒ FileList

Returns a new instance of FileList.



11
12
13
# File 'lib/spellr/file_list.rb', line 11

def initialize(*patterns)
  @patterns = patterns
end

Instance Method Details

#cli_only?(file) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/spellr/file_list.rb', line 23

def cli_only?(file)
  @patterns.empty? || @patterns.any? { |p| file.fnmatch?(p) }
end

#config_only?(file) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/spellr/file_list.rb', line 19

def config_only?(file)
  Spellr.config.only.empty? || Spellr.config.only.any? { |o| file.fnmatch?(o) }
end

#eachObject



27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/spellr/file_list.rb', line 27

def each
  # TODO: handle no gitignore
  gitignore = ::File.join(Dir.pwd, '.gitignore')
  gitignore = nil unless ::File.exist?(gitignore)
  FastIgnore.new(rules: Spellr.config.ignored, gitignore: gitignore).each do |file|
    file = Spellr::File.new(file)
    next unless cli_only?(file)
    next if wordlist?(file)
    next unless config_only?(file)

    yield(file)
  end
end

#to_aObject



41
42
43
# File 'lib/spellr/file_list.rb', line 41

def to_a
  enum_for(:each).to_a
end

#wordlist?(file) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/spellr/file_list.rb', line 15

def wordlist?(file)
  Spellr.config.all_wordlist_paths.any? { |w| w == file }
end