Sha256: 877e478dedc4b59de29c3d330d82d625eb8577d6e256e08974ea22281a18e845

Contents?: true

Size: 781 Bytes

Versions: 6

Compression:

Stored size: 781 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

6 entries across 6 versions & 1 rubygems

Version Path
cyberarm_engine-0.19.0 lib/cyberarm_engine/model_cache.rb
cyberarm_engine-0.18.0 lib/cyberarm_engine/model_cache.rb
cyberarm_engine-0.17.1 lib/cyberarm_engine/model_cache.rb
cyberarm_engine-0.17.0 lib/cyberarm_engine/model_cache.rb
cyberarm_engine-0.16.0 lib/cyberarm_engine/model_cache.rb
cyberarm_engine-0.15.0 lib/cyberarm_engine/model_cache.rb