Sha256: e68ed9fa335e52e8cfbd8c11dad9ab4e3d004266bb8de5e0b8ced12093a91d49

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

module Legion
  module Data
    module Models
      class << self
        attr_reader :loaded_models

        def models
          %w[extension function task runner node setting]
        end

        def load
          Legion::Logging.info 'Loading Legion::Data::Models'
          @loaded_models ||= []
          require_sequel_models(models)
          Legion::Settings[:data][:models][:loaded] = true
        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 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}")
          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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
legion-data-1.2.0 lib/legion/data/model.rb