lib/figtree/ini_config.rb in figtree-1.0.0 vs lib/figtree/ini_config.rb in figtree-1.0.1

- old
+ new

@@ -1,25 +1,24 @@ 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 - ) + parsed_subgroups = ini.is_a?(Hash) ? + ini : subgroups_from(ini, override) + super(parsed_subgroups) end private + def subgroups_from(ini_file, override) + figgy_transform( + figgy_parse( + File.read(ini_file) + ), + override + ).reduce({}, :merge!) + end + def figgy_parse(str) Parser.new.parse(str) rescue Parslet::ParseFailed => failure STDERR.puts "\nInvalid ini file.\n" + "Error: #{failure.cause.ascii_tree}" +