summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorSaku Ytti <saku@ytti.fi>2014-06-11 15:34:14 +0300
committerSaku Ytti <saku@ytti.fi>2014-06-11 15:34:14 +0300
commit6434e1a36caf025530363a16f52d77a5780ecc8a (patch)
treea68c5120605dbf63a8ab6ee57b8ff630f898c169 /lib
parent829654ad75d7329e5d9216899e019417f21d31d1 (diff)
Change dynamic discover of file => class name
We needed this, because use of 'def inherited' not idempotent, in Oxidized::Script use case we may need to restart Oxidized, even though it's already loaded, and we won't get class names populated via 'def inherited' anymore. There are quite many optiosn to do this a) filename == class name + no discovery/mapping, very clean - user 'source' must give us model name in exactly right capitalization b) add 'self' at end of files, so eval will return class name + deterministic with arbitrary name - DSL cruft, DSL being light is our main value (can we do this via parent class? I couldn't find way) c) load in new module via Module.module_eval X + module will contain only consts we just created - but which one is the one we want? - if we use eval, load errors won't tell line error But at least now we got rid of 'inherited' methods and not adding too much cruft, hope it's better than before.
Diffstat (limited to 'lib')
-rw-r--r--lib/oxidized/input/input.rb5
-rw-r--r--lib/oxidized/manager.rb14
-rw-r--r--lib/oxidized/model/model.rb1
-rw-r--r--lib/oxidized/output/output.rb5
-rw-r--r--lib/oxidized/source/source.rb5
5 files changed, 9 insertions, 21 deletions
diff --git a/lib/oxidized/input/input.rb b/lib/oxidized/input/input.rb
index 769b196..1184a0b 100644
--- a/lib/oxidized/input/input.rb
+++ b/lib/oxidized/input/input.rb
@@ -14,10 +14,5 @@ module Oxidized
Errno::EPIPE,
],
}
- class << self
- def inherited klass
- Oxidized.mgr.loader = { :class => klass }
- end
- end
end
end
diff --git a/lib/oxidized/manager.rb b/lib/oxidized/manager.rb
index 9352eaf..f901a5f 100644
--- a/lib/oxidized/manager.rb
+++ b/lib/oxidized/manager.rb
@@ -8,17 +8,21 @@ module Oxidized
def load dir, file
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] }
+ klass = nil
+ [Oxidized, Object].each do |mod|
+ klass = mod.constants.find { |const| const.to_s.downcase.match file.downcase }
+ klass = mod.const_get klass if klass
+ break if klass
+ end
+ i = klass.new
+ i.setup if i.respond_to? :setup
+ { file => klass }
rescue LoadError
{}
end
end
end
attr_reader :input, :output, :model, :source
- attr_accessor :loader
def initialize
@input = {}
@output = {}
diff --git a/lib/oxidized/model/model.rb b/lib/oxidized/model/model.rb
index 6f4f54d..c3d8760 100644
--- a/lib/oxidized/model/model.rb
+++ b/lib/oxidized/model/model.rb
@@ -9,7 +9,6 @@ module Oxidized
klass.instance_variable_set '@procs', Hash.new { |h,k| h[k] = [] }
klass.instance_variable_set '@expect', []
klass.const_set :CFG, CFG
- Oxidized.mgr.loader = { :class => klass }
end
def comment _comment='# '
return @comment if @comment
diff --git a/lib/oxidized/output/output.rb b/lib/oxidized/output/output.rb
index 54d616c..eaf149a 100644
--- a/lib/oxidized/output/output.rb
+++ b/lib/oxidized/output/output.rb
@@ -1,10 +1,5 @@
module Oxidized
class Output
class NoConfig < OxidizedError; end
- class << self
- def inherited klass
- Oxidized.mgr.loader = { :class => klass }
- end
- end
end
end
diff --git a/lib/oxidized/source/source.rb b/lib/oxidized/source/source.rb
index 5093950..3c1f255 100644
--- a/lib/oxidized/source/source.rb
+++ b/lib/oxidized/source/source.rb
@@ -1,11 +1,6 @@
module Oxidized
class Source
class NoConfig < OxidizedError; end
- class << self
- def inherited klass
- Oxidized.mgr.loader = { :class => klass }
- end
- end
def initialize
@map = (CFG.model_map or {})
end