Sha256: df01b6fd2bb4fd921010dc73de86b92b81608a8a2f31c6e7e2fca8f0c34e788b

Contents?: true

Size: 671 Bytes

Versions: 1

Compression:

Stored size: 671 Bytes

Contents

require "params_builder/version"
require "params_builder/configuration"
require "yaml"

module ParamsBuilder
  def self.root
    File.dirname __dir__
  end

  def self.build(file_name, variables = {})
    erb_context = Struct.new(*variables.keys) do
      def with_binding
        binding
      end
    end

    path = "#{config.file_path}/#{file_name}.yml.erb"

    YAML.load_stream(
      ERB.new(File.read(path)).result(
        erb_context.new(*variables.values).with_binding
      )
    ).first
  end

  def self.read(file_name)
    path = "#{config.file_path}/#{file_name}.yml.erb"

    YAML.load_stream(
      ERB.new(File.read(path)).result
    ).first
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
params_builder-0.2.0 lib/params_builder.rb