Class: Kotoshu::ProjectConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/kotoshu/project_config.rb

Overview

Project configuration for .kotoshu file.

Auto-discovers .kotoshu file by searching up directory tree.

Constant Summary collapse

CONFIG_FILE =
".kotoshu"

Class Method Summary collapse

Class Method Details

.exists?(start_path = Dir.pwd) ⇒ Boolean

Check if project config exists.

Parameters:

  • start_path (String) (defaults to: Dir.pwd)

    Starting directory

Returns:

  • (Boolean)

    True if config exists



26
27
28
# File 'lib/kotoshu/project_config.rb', line 26

def exists?(start_path = Dir.pwd)
  !find_config_file(start_path).nil?
end

.ignore_patterns(start_path = Dir.pwd) ⇒ Hash

Get ignore patterns from project config.

Parameters:

  • start_path (String) (defaults to: Dir.pwd)

    Starting directory

Returns:

  • (Hash)

    Configuration with ignore patterns



34
35
36
37
38
39
40
# File 'lib/kotoshu/project_config.rb', line 34

def ignore_patterns(start_path = Dir.pwd)
  config = load(start_path) || {}
  {
    words: config["ignore_words"] || [],
    patterns: (config["ignore_patterns"] || []).map { |p| Regexp.new(p) }
  }
end

.load(start_path = Dir.pwd) ⇒ Hash?

Load project config for given path.

Parameters:

  • start_path (String) (defaults to: Dir.pwd)

    Starting directory

Returns:

  • (Hash, nil)

    Configuration hash or nil



15
16
17
18
19
20
# File 'lib/kotoshu/project_config.rb', line 15

def load(start_path = Dir.pwd)
  path = find_config_file(start_path)
  return nil unless path

  parse_config_file(path)
end