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
- #types ⇒ Object
Constructor Details
#initialize(config_location) ⇒ Config
Returns a new instance of Config.
4 5 6 7 |
# File 'lib/ultragrep/config.rb', line 4 def initialize(config_location) @config_location = config_location parse! end |
Instance Method Details
#[](val) ⇒ Object
22 23 24 |
# File 'lib/ultragrep/config.rb', line 22 def [](val) @data[val] end |
#available_types ⇒ Object
43 44 45 |
# File 'lib/ultragrep/config.rb', line 43 def available_types types.keys end |
#default_file_type ⇒ Object
30 31 32 |
# File 'lib/ultragrep/config.rb', line 30 def default_file_type @data.fetch('default_type') end |
#fetch(*args) ⇒ Object
26 27 28 |
# File 'lib/ultragrep/config.rb', line 26 def fetch(*args) @data.fetch(*args) end |
#find_file! ⇒ Object
9 10 11 12 13 14 15 16 |
# File 'lib/ultragrep/config.rb', line 9 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
34 35 36 |
# File 'lib/ultragrep/config.rb', line 34 def log_path_glob(type) Array(types.fetch(type).fetch('glob')) end |
#parse! ⇒ Object
18 19 20 |
# File 'lib/ultragrep/config.rb', line 18 def parse! @data = YAML.load_file(find_file!) end |
#types ⇒ Object
38 39 40 41 |
# File 'lib/ultragrep/config.rb', line 38 def types raise "Please configure the 'types' section of ultragrep.yml" unless @data["types"] @data["types"] end |