lib/chronicle/etl/config.rb in chronicle-etl-0.5.5 vs lib/chronicle/etl/config.rb in chronicle-etl-0.6.1

- old
+ new

@@ -1,6 +1,6 @@ -require "active_support/core_ext/hash/keys" +require 'active_support/core_ext/hash/keys' require 'fileutils' require 'yaml' module Chronicle module ETL @@ -13,11 +13,11 @@ def load(type, identifier) base = config_pathname_for_type(type) path = base.join("#{identifier}.yml") return {} unless path.exist? - YAML.safe_load(File.read(path), symbolize_names: true, permitted_classes: [Symbol, Date, Time]) + YAML.safe_load_file(path, symbolize_names: true, permitted_classes: [Symbol, Date, Time]) end # Writes a hash as a yml config file def write(type, identifier, data) base = config_pathname_for_type(type) @@ -29,31 +29,41 @@ # Ruby likes to add --- separators when writing yaml files f << data.to_yaml.gsub(/^-+\n/, '') end end + # Returns path for a given config type and identifier + def path(type, identifier) + base = config_pathname_for_type(type) + base.join("#{identifier}.yml") + end + + # Whether a config exists for a given type and identifier def exists?(type, identifier) base = config_pathname_for_type(type) path = base.join("#{identifier}.yml") - return path.exist? + path.exist? end # Returns all jobs available in ~/.config/chronicle/etl/jobs/*.yml def available_jobs - Dir.glob(File.join(config_pathname_for_type("jobs"), "*.yml")).map do |filename| - File.basename(filename, ".*") + Dir.glob(File.join(config_pathname_for_type('jobs'), '*.yml')).map do |filename| + File.basename(filename, '.*') end end + # Returns all configs available for a given type def available_configs(type) - Dir.glob(File.join(config_pathname_for_type(type), "*.yml")).map do |filename| - File.basename(filename, ".*") + Dir.glob(File.join(config_pathname_for_type(type), '*.yml')).map do |filename| + File.basename(filename, '.*') end end # Load a job definition from job config directory def read_job(job_name) - load('jobs', job_name) + definition = load('jobs', job_name) + definition[:name] ||= job_name + definition end def config_pathname base = Pathname.new(xdg_config.config_home) base.join('chronicle', 'etl')