lib/burglar/heist.rb in burglar-0.1.1 vs lib/burglar/heist.rb in burglar-0.1.2

- old
+ new

@@ -1,11 +1,17 @@ +require 'cymbal' +require 'yaml' + module Burglar + # Default config file + DEFAULT_CONFIG_FILE = '~/.burglar.yml'.freeze + ## # Collection of banks class Heist def initialize(params = {}) - @options = params + @options = load_options(params) end def banks @banks ||= @options[:banks].map do |k, v| [k, Burglar::Bank.new(@options.merge(v))] @@ -14,8 +20,20 @@ def transactions @transactions ||= Ledger.new( entries: banks.map { |_, v| v.transactions.entries }.flatten.sort ) + end + + private + + def load_config(file) + file ||= DEFAULT_CONFIG_FILE + file = File.expand_path file + Cymbal.symbolize YAML.safe_load(File.read(file)) + end + + def load_options(params) + load_config(params[:config]).merge(params) end end end