Module: Watnow::Config

Included in:
Extractor
Defined in:
lib/watnow/config.rb

Defined Under Namespace

Classes: YamlParser

Constant Summary collapse

FOLDER_IGNORE =

Default constants

%w(tmp node_modules db public log)
FILE_EXTENSION_IGNORE =
%w(tmproj markdown md txt)
PATTERNS =
%w(TODO FIXME)

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/watnow/config.rb', line 10

def self.included(base)
  defaults = {
    'color' => true,
    'folder_ignore' => [],
    'file_extension_ignore' => [],
    'patterns' => [],
    'username' => ''
  }

  # Parse YAML config file (~/.watnowconfig)
  parser = YamlParser.new
  custom_options = parser.parse

  # Merge defaults with custom options
  # Add default constants
  options = custom_options ? defaults.merge(custom_options) : defaults
  options['folder_ignore'].concat(FOLDER_IGNORE)
  options['file_extension_ignore'].concat(FILE_EXTENSION_IGNORE)
  options['patterns'].concat(PATTERNS)

  # Generate singleton methods with options keys for quick access
  # i.e. self.color, self.patterns, self.username, etc
  options.each do |option|
    define_singleton_method option[0] do
      option[1]
    end
  end
end