lib/legion/data/model.rb in legion-data-0.1.1 vs lib/legion/data/model.rb in legion-data-0.2.0
- old
+ new
@@ -1,35 +1,33 @@
module Legion
module Data
- class Models
- attr_reader :loaded_models
- def initialize(options = {})
- options.merge!(default_options) { |_key, v1, _v2| v1 }
- @loaded_models = []
- require_sequel_models if options[:auto_load]
- end
+ module Models
+ class << self
+ attr_reader :loaded_models
+ def models
+ %w[user group extension chain relationship function task runner task_log datacenter environment node setting]
+ end
- def default_options
- { continue_on_model_fail: false,
- auto_load: true }
- end
+ def load
+ Legion::Logging.info 'Loading Legion::Data::Models'
+ @loaded_models ||= []
+ require_sequel_models(models)
+ end
- def models
- %w[chain relationship function task namespace task_log datacenter environment node]
- end
+ def require_sequel_models(files = models)
+ Dir[File.dirname(__FILE__) + 'models/*.rb'].each { |file| puts file }
+ files.each { |file| load_sequel_model(file) }
+ end
- def require_sequel_models(files = models)
- files.each { |file| load_sequel_model(file) }
- end
-
- def load_sequel_model(model)
- Legion::Logging.debug("Trying to load #{model}.rb")
- require_relative "models/#{model}"
- @loaded_models << model
- Legion::Logging.debug("Successfully loaded #{model}")
- rescue LoadError => e
- Legion::Logging.fatal("Failed to load #{model}")
- raise e unless Legion::Settings[:data][:models][:continue_on_fail]
+ def load_sequel_model(model)
+ Legion::Logging.debug("Trying to load #{model}.rb")
+ require_relative "models/#{model}"
+ @loaded_models << model
+ Legion::Logging.debug("Successfully loaded #{model}")
+ rescue LoadError => e
+ Legion::Logging.fatal("Failed to load #{model}")
+ raise e unless Legion::Settings[:data][:models][:continue_on_fail]
+ end
end
end
end
end