Class: Ultragrep::Config
- Inherits:
-
Object
- Object
- Ultragrep::Config
- Defined in:
- lib/ultragrep/config.rb
Constant Summary collapse
- DEFAULT_LOCATIONS =
[".ultragrep.yml", "#{ENV['HOME']}/.ultragrep.yml", "/etc/ultragrep.yml"]
Instance Method Summary collapse
- #[](val) ⇒ Object
- #available_types ⇒ Object
- #default_file_type ⇒ Object
- #fetch(*args) ⇒ Object
- #find_file! ⇒ Object
-
#initialize(config_location) ⇒ Config
constructor
A new instance of Config.
- #log_path_glob(type) ⇒ Object
- #parse! ⇒ Object
- #to_s ⇒ Object
- #types ⇒ Object
Constructor Details
#initialize(config_location) ⇒ Config
Returns a new instance of Config.
6 7 8 9 |
# File 'lib/ultragrep/config.rb', line 6 def initialize(config_location) @config_location = config_location parse! end |
Instance Method Details
#[](val) ⇒ Object
24 25 26 |
# File 'lib/ultragrep/config.rb', line 24 def [](val) @data[val] end |
#available_types ⇒ Object
49 50 51 |
# File 'lib/ultragrep/config.rb', line 49 def available_types types.keys end |
#default_file_type ⇒ Object
36 37 38 |
# File 'lib/ultragrep/config.rb', line 36 def default_file_type @data.fetch('default_type') end |
#fetch(*args) ⇒ Object
32 33 34 |
# File 'lib/ultragrep/config.rb', line 32 def fetch(*args) @data.fetch(*args) end |
#find_file! ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'lib/ultragrep/config.rb', line 11 def find_file! if @config_location && !File.exist?(@config_location) abort("#{@config_location} not found") end file = ([@config_location] + DEFAULT_LOCATIONS).compact.detect { |fname| File.exist?(fname) } abort("Please configure ultragrep.yml (#{DEFAULT_LOCATIONS.join(", ")})") unless file file end |
#log_path_glob(type) ⇒ Object
40 41 42 |
# File 'lib/ultragrep/config.rb', line 40 def log_path_glob(type) Array(types.fetch(type).fetch('glob')) end |
#parse! ⇒ Object
20 21 22 |
# File 'lib/ultragrep/config.rb', line 20 def parse! @data = YAML.load_file(find_file!) end |
#to_s ⇒ Object
28 29 30 |
# File 'lib/ultragrep/config.rb', line 28 def to_s @data.to_s end |
#types ⇒ Object
44 45 46 47 |
# File 'lib/ultragrep/config.rb', line 44 def types raise "Please configure the 'types' section of ultragrep.yml" unless @data["types"] @data["types"] end |