Sha256: a3e066a3a08b10d6fa041f0a5649e9d141121f171409f2a5ffac5549f6359169

Contents?: true

Size: 691 Bytes

Versions: 1

Compression:

Stored size: 691 Bytes

Contents

require "yaml"
require "erb"

module RockConfig
  class YamlLoader
    def find_at(directory, file_name)
      path = full_path(directory, file_name)

      if readable?(path)
        return Config.new(load_yaml_from(path))
      end
    end

    private

    def full_path(directory, file_name)
      File.join(directory, full_name(file_name))
    end

    def full_name(file_name)
      "#{file_name}.yml"
    end

    def readable?(path)
      File.exists?(path) && File.readable?(path)
    end

    def load_yaml_from(path)
      template = ERB.new File.read path
      YAML.load template.result binding
    rescue Exception => e
      raise ConfigLoadError, e.message
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rock_config-0.0.7 lib/rock_config/yaml_loader.rb