diff options
author | Saku Ytti <saku@ytti.fi> | 2014-03-02 12:36:37 +0200 |
---|---|---|
committer | Saku Ytti <saku@ytti.fi> | 2014-03-02 12:36:37 +0200 |
commit | 4baedb0667185fb899ad1c1f5a7782d1228807a9 (patch) | |
tree | 180d71eeeb06baaf16163aeee33b8ecd1d2e6b6e /lib/oxidized/manager.rb | |
parent | 465de586078eb40e6d0ae820d9da8a254c181021 (diff) |
Change dynamic loading
If we use assignment method (#method=) we don't get return value, so we
never know that manager fails to load.
Also we do not want to rescue failures of input/output/source loading,
they are catastrophic and should fail whole process, loading of model is
not catastrophic.
Diffstat (limited to 'lib/oxidized/manager.rb')
-rw-r--r-- | lib/oxidized/manager.rb | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/lib/oxidized/manager.rb b/lib/oxidized/manager.rb index 5065617..9352eaf 100644 --- a/lib/oxidized/manager.rb +++ b/lib/oxidized/manager.rb @@ -6,11 +6,15 @@ module Oxidized class Manager class << self def load dir, file - require File.join dir, file+'.rb' - obj, Oxidized.mgr.loader = Oxidized.mgr.loader, nil - k = obj[:class].new - k.setup if k.respond_to? :setup - { file => obj[:class] } + begin + require File.join dir, file+'.rb' + obj, Oxidized.mgr.loader = Oxidized.mgr.loader, nil + k = obj[:class].new + k.setup if k.respond_to? :setup + { file => obj[:class] } + rescue LoadError + {} + end end end attr_reader :input, :output, :model, :source @@ -21,22 +25,22 @@ module Oxidized @model = {} @source = {} end - def input= method + def add_input method method = Manager.load Config::InputDir, method return false if method.empty? @input.merge! method end - def output= method + def add_output method method = Manager.load Config::OutputDir, method return false if method.empty? @output.merge! method end - def model= _model + def add_model _model _model = Manager.load Config::ModelDir, _model return false if _model.empty? @model.merge! _model end - def source= _source + def add_source _source return nil if @source.key? _source _source = Manager.load Config::SourceDir, _source return false if _source.empty? |