Sha256: e35f0626853b22898c75f29e9be4f6639091905afcf53fe0cfa67cd66680c85f

Contents?: true

Size: 923 Bytes

Versions: 1

Compression:

Stored size: 923 Bytes

Contents

require 'figtree/parser'
require 'figtree/transformer'
require 'figtree/ini_config'

module Figtree
  def self.load_config(file_path, overrides=[])
    parsed_subgroups = figgy_transform(
      figgy_parse(
        File.read(file_path)
      ),
      overrides
    )
    IniConfig.new(
      parsed_subgroups.reduce({}, :merge!)
    )
  end

  private
  def self.figgy_parse(str)
    Parser.new.parse(str)
  rescue Parslet::ParseFailed => failure
    STDERR.puts "\nInvalid ini file.\n" +
      "Error: #{failure.cause.ascii_tree}" +
      "Please correct the file and retry."
      raise
  end

  def self.figgy_transform(tree, overrides = [])
    Transformer.new.apply(tree, overrides: overrides)
  rescue => e
    STDERR.puts "\nInvalid transformation rule.\n" +
      "Error: #{e}" +
      "Please correct your transformer rule and retry."
    raise TransformFailed
  end

  class TransformFailed < Exception
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
figtree-0.0.2 lib/figtree.rb