class Stibium::Bundled::Bundle::Config::Reader

Config file reader.

Attributes

env[R]

@return [Hash{String => String}]

Public Class Methods

new(env: ENV.to_h) click to toggle source
# File lib/stibium/bundled/bundle/config/reader.rb, line 18
def initialize(env: ENV.to_h)
  self.tap do
    @env = env.dup.map { |k, v| [k.freeze, v.freeze] }.to_h.freeze
  end.freeze
end

Public Instance Methods

ignore_config?() click to toggle source

@return [Boolean]

# File lib/stibium/bundled/bundle/config/reader.rb, line 25
def ignore_config?
  env.key?('BUNDLE_IGNORE_CONFIG')
end
read(file) click to toggle source

Read given config file.

@param file [Pathname]

@return [Hash{String => Object}]

# File lib/stibium/bundled/bundle/config/reader.rb, line 34
def read(file)
  scrutinize(file).transform_values { |v| v.is_a?(String) ? YAML.safe_load(v) : v }
end

Protected Instance Methods

scrutinize(file) click to toggle source

@api private

@param file [Pathname]

@raise [RuntimeError] @return [Hash{String => Object}]

# File lib/stibium/bundled/bundle/config/reader.rb, line 46
def scrutinize(file)
  return {} if ignore_config?

  return {} unless file.file? and file.readable?

  file.read
      .yield_self { |content| YAML.safe_load(content) }
      .yield_self { |result| result.nil? ? {} : result }
      .tap { |result| raise RuntimeError, "Hash expected, got #{result.class}" unless result.is_a?(Hash) }
end