Sha256: cda8ab17f88385f7c9fd50565103b8e4632a69e3afafb46e1bd1f79f3c4a19e6
Contents?: true
Size: 1.05 KB
Versions: 1
Compression:
Stored size: 1.05 KB
Contents
require 'ostruct' module Figtree class IniConfig < OpenStruct def initialize(ini, override = :none) # cheat to allow a parsed hash in if ini.is_a?(Hash) parsed_subgroups = ini else parsed_subgroups = figgy_transform( figgy_parse( File.read(ini) ), override ).reduce({}, :merge!) end super( parsed_subgroups ) end private def 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 figgy_transform(tree, override) Transformer.new.apply(tree, override: override) rescue => e STDERR.puts "\nInvalid transformation rule.\n" + "Error: #{e}" + "Please correct your transformer rule and retry." raise TransformFailed end end class Subgroup < OpenStruct end class TransformFailed < Exception end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
figtree-1.0.0 | lib/figtree/ini_config.rb |