Sha256: dcbc24f793cc5ec404162ca5d683eda6a529c92d08d831f90ead9fce9787ced6

Contents?: true

Size: 812 Bytes

Versions: 10

Compression:

Stored size: 812 Bytes

Contents

module CyberarmEngine
  module ModelCache
    CACHE = {}

    def self.find_or_cache(manifest:)
      model_file = manifest.file_path + "/model/#{manifest.model}"

      type = File.basename(model_file).split(".").last.to_sym

      if model = load_model_from_cache(type, model_file)
        model
      else
        model = CyberarmEngine::Model.new(file_path: model_file)
        cache_model(type, model_file, model)

        model
      end
    end

    def self.load_model_from_cache(type, model_file)
      return CACHE[type][model_file] if CACHE[type].is_a?(Hash) && (CACHE[type][model_file])

      false
    end

    def self.cache_model(type, model_file, model)
      CACHE[type] = {} unless CACHE[type].is_a?(Hash)
      CACHE[type][model_file] = model
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
cyberarm_engine-0.24.4 lib/cyberarm_engine/model_cache.rb
cyberarm_engine-0.24.3 lib/cyberarm_engine/model_cache.rb
cyberarm_engine-0.24.2 lib/cyberarm_engine/model_cache.rb
cyberarm_engine-0.24.1 lib/cyberarm_engine/model_cache.rb
cyberarm_engine-0.24.0 lib/cyberarm_engine/model_cache.rb
cyberarm_engine-0.23.0 lib/cyberarm_engine/model_cache.rb
cyberarm_engine-0.22.0 lib/cyberarm_engine/model_cache.rb
cyberarm_engine-0.21.0 lib/cyberarm_engine/model_cache.rb
cyberarm_engine-0.20.0 lib/cyberarm_engine/model_cache.rb
cyberarm_engine-0.19.1 lib/cyberarm_engine/model_cache.rb