Class: Changit::ConfigReader

Inherits:
Object
  • Object
show all
Defined in:
lib/changit/config_reader.rb

Constant Summary collapse

DEFAULT_SEARCH_PATH =
"#{Dir.pwd}/.gitconfig".freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(search_path: DEFAULT_SEARCH_PATH) ⇒ ConfigReader

Returns a new instance of ConfigReader.



7
8
9
10
11
# File 'lib/changit/config_reader.rb', line 7

def initialize(search_path: DEFAULT_SEARCH_PATH)
  @search_path = search_path

  freeze
end

Instance Attribute Details

#search_pathObject (readonly)

Returns the value of attribute search_path.



5
6
7
# File 'lib/changit/config_reader.rb', line 5

def search_path
  @search_path
end

Instance Method Details

#readObject



13
14
15
16
17
18
19
20
21
# File 'lib/changit/config_reader.rb', line 13

def read
  search_result = Dir.glob(@search_path)

  if search_result.empty?
    fail "File #{@search_path} not found."
  else
    File.read(search_result.first)
  end
end