Sha256: 5366c1016ae4c859340f523077d2f0a791bb4665f996ed2ce6b85ac252ddffab

Contents?: true

Size: 655 Bytes

Versions: 6

Compression:

Stored size: 655 Bytes

Contents

# frozen_string_literal: true

require 'erb'
require 'yaml'
require_relative 'configurable'

module Branch
  module Name
    module Loadable
      include Configurable

      def load_options(defaults: {})
        options = {}

        options.merge!(load_config(system_config_file))
        options.merge!(load_config(global_config_file))
        options.merge!(load_config(local_config_file))

        options.presence || defaults
      end

      def load_config(config_file)
        return {} unless File.exist? config_file

        yaml_options = File.read(config_file)
        YAML.safe_load ERB.new(yaml_options).result
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
branch-name-2.2.0 lib/branch/name/loadable.rb
branch-name-2.1.0 lib/branch/name/loadable.rb
branch-name-2.0.1.pre.beta lib/branch/name/loadable.rb
branch-name-2.0.0.pre.beta lib/branch/name/loadable.rb
branch-name-1.0.1.pre.beta lib/branch/name/loadable.rb
branch-name-1.0.0.pre.beta lib/branch/name/loadable.rb