class Translatomatic::Config::Files
Configuration file operations. Configuration settings may be specified in the following locations:
- environment variables - user configuration file $HOME/.translatomatic/config.yml - project configuration file $PROJECT/.translatomatic/config.yml - command line options
Settings
are read in the order given above, with last setting found taking precedence over values read earlier.
Constants
- CONFIG_DIR
- CONFIG_PATH
Public Class Methods
find_project(user_path)
click to toggle source
find a project directory working upwards from current directory. stop at user path.
# File lib/translatomatic/config/files.rb, line 39 def find_project(user_path) user_path = user_path.to_s Pathname.new(Dir.pwd).ascend do |v| return nil if v.to_s == user_path || user_path.start_with?(v.to_s) config_path = v + CONFIG_DIR return v if config_path.directory? end nil end
load(path, options = {})
click to toggle source
load configuration from the yaml file at path. @param path to config file @return [LocationSettings] Location settings object
# File lib/translatomatic/config/files.rb, line 28 def load(path, options = {}) return nil unless path config_path = File.join(path, CONFIG_PATH) options = options.merge(path: path) return new_settings({}, options) unless File.exist?(config_path) config = YAML.load_file(config_path) || {} new_settings(config, options) end
save(settings)
click to toggle source
Save location settings to file @param settings [LocationSettings] Location settings object @return [void]
# File lib/translatomatic/config/files.rb, line 18 def save(settings) return unless settings && settings.path config_path = File.join(settings.path, CONFIG_PATH) FileUtils.mkdir_p(File.dirname(config_path)) File.write(config_path, settings.to_yaml) end
Private Class Methods
new_settings(config, options = {})
click to toggle source
# File lib/translatomatic/config/files.rb, line 54 def new_settings(config, options = {}) LocationSettings.new(config.deep_symbolize_keys, options) end