class SimpleNavigation::ConfigFileFinder
Internal: Encapsulates the configuration file finding logic.
Attributes
paths[R]
Public Class Methods
new(paths)
click to toggle source
Internal: Initializes a ConfigFileFinder
.
paths - an enumerable list of paths in which to look for configuration
files.
# File lib/simple_navigation/config_file_finder.rb, line 10 def initialize(paths) @paths = paths end
Public Instance Methods
find(context)
click to toggle source
Internal: Searches a configuration file for the given context in the initialization paths.
context - The navigation context for which to look the configuration file.
Returns a String representing the full path of the configuation file. Raises StandardError if no file is found.
# File lib/simple_navigation/config_file_finder.rb, line 21 def find(context) config_file_name = config_file_name_for_context(context) find_config_file(config_file_name) || fail("Config file '#{config_file_name}' not found in " \ "path(s) #{paths.join(', ')}!") end
Private Instance Methods
config_file_name_for_context(context)
click to toggle source
# File lib/simple_navigation/config_file_finder.rb, line 33 def config_file_name_for_context(context) ConfigFile.new(context).name end
find_config_file(config_file_name)
click to toggle source
# File lib/simple_navigation/config_file_finder.rb, line 37 def find_config_file(config_file_name) paths.map { |path| File.join(path, config_file_name) } .find { |full_path| File.exist?(full_path) } end