Module: CodeLister
- Defined in:
- lib/code_lister/cli.rb,
lib/code_lister/main.rb,
lib/code_lister/logger.rb,
lib/code_lister/version.rb,
lib/code_lister/code_lister.rb
Defined Under Namespace
Constant Summary collapse
- VERSION =
'0.0.7'
- CustomError =
Class.new(StandardError)
Class Attribute Summary collapse
-
.logger ⇒ Logger
The Logger for the project.
Class Method Summary collapse
-
.files(args = {}) ⇒ Object
List files base on some extension.
-
.filter(file_list, args = {}) ⇒ Object
Filter out the list based on given list of words.
Class Attribute Details
.logger ⇒ Logger
Returns the Logger for the project.
6 7 8 |
# File 'lib/code_lister/logger.rb', line 6 def logger @logger ||= Logger.new STDOUT end |
Class Method Details
.files(args = {}) ⇒ Object
List files base on some extension
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/code_lister/code_lister.rb', line 8 def files(args = {}) opts = { base_dir: Dir.pwd, recursive: false, exts: [], non_exts: [] }.merge(args) base_dir = opts[:base_dir] raise CustomError, "The directory #{base_dir} is not valid or or not readable!" unless File.exists?(base_dir) wildcard = opts[:recursive] ? '**' : '' exts = opts[:exts] non_exts = opts[:non_exts] file_with_extension = Dir.glob(File.join(base_dir, wildcard, "*.{#{exts.join(",")}}")) file_with_no_extension = no_extension_files(base_dir, wildcard, non_exts) # combine the result (file_with_extension + file_with_no_extension).sort end |
.filter(file_list, args = {}) ⇒ Object
Filter out the list based on given list of words
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/code_lister/code_lister.rb', line 31 def filter(file_list, args = {}) opts = { inc_words: [], exc_words: [], ignore_case: true }.merge(args) take_any!(file_list, opts) drop_any!(file_list, opts) file_list end |