class Coco::SourceLister

I retrieve the .rb files from a list of directories.

Public Class Methods

new(config) click to toggle source

config - Hash.

# File lib/coco/lister/source_lister.rb, line 7
def initialize(config)
  @exclude_files = config[:exclude]
  dirs = config[:include]
  @folders = [*dirs]
  @folders.each do |folder|
    unless File.directory?(folder)
      raise ArgumentError, "Not a folder: #{folder}"
    end
  end
  @list = []
end

Public Instance Methods

list() click to toggle source

Returns Array of String, that is a list of all `.rb` files from the directories found in configuration.

# File lib/coco/lister/source_lister.rb, line 21
def list
  look_for_sources
  @list.map! { |file| File.expand_path(file) }
  exclude_files_user_dont_want if @exclude_files
  @list
end

Private Instance Methods

exclude_all_from_dir(full_path) click to toggle source
# File lib/coco/lister/source_lister.rb, line 50
def exclude_all_from_dir(full_path)
  Helpers.rb_files_from(full_path).each do |file|
    @list.delete File.expand_path(file)
  end
end
exclude_files_user_dont_want() click to toggle source
# File lib/coco/lister/source_lister.rb, line 36
def exclude_files_user_dont_want
  @exclude_files.each do |filename|
    exclude_path(File.expand_path(filename))
  end
end
exclude_path(full_path) click to toggle source
# File lib/coco/lister/source_lister.rb, line 42
def exclude_path(full_path)
  if File.file?(full_path)
    @list.delete full_path
  elsif File.directory?(full_path)
    exclude_all_from_dir full_path
  end
end
look_for_sources() click to toggle source
# File lib/coco/lister/source_lister.rb, line 30
def look_for_sources
  @folders.each do |folder|
    @list += Helpers.rb_files_from folder
  end
end