module Diffend::Configs::Fetcher

Class responsible for fetching the config from .diffend.yml

Public Class Methods

call(plugin_path, build_path) click to toggle source

@param plugin_path [String] path of the plugin @param build_path [String] path of the current build

@return [Hash] details from configuration file

@example

details = Fetcher.new.call('./')
details.build_path #=> './'
# File lib/diffend/configs/fetcher.rb, line 22
def call(plugin_path, build_path)
  default_config = File.join(plugin_path, 'config', 'diffend.yml')
  project_config = File.join(build_path, Diffend::Config::FILENAME)

  hash = read_file(default_config)

  if File.exist?(project_config)
    hash.merge!(read_file(project_config) || {})
  end

  hash
end

Private Class Methods

read_file(file_path) click to toggle source

Load config file

@param file_path [String]

@return [Hash]

# File lib/diffend/configs/fetcher.rb, line 42
def read_file(file_path)
  YAML.safe_load(ERB.new(File.read(file_path)).result)
rescue Psych::SyntaxError
  raise Errors::MalformedConfigurationFile
end