Class: Wings::ModelTransformer::ResourceClassCache

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/wings/model_transformer.rb

Overview

Caches dynamically generated `Valkyrie::Resource` subclasses mapped from legacy `ActiveFedora` model classes.

Examples:

cache = ResourceClassCache.new

klass = cache.fetch(GenericWork) do
  # logic mapping GenericWork to a Valkyrie::Resource subclass
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeResourceClassCache

Returns a new instance of ResourceClassCache.


95
96
97
# File 'lib/wings/model_transformer.rb', line 95

def initialize
  @cache = {}
end

Instance Attribute Details

#cacheObject (readonly)

Returns the value of attribute cache


93
94
95
# File 'lib/wings/model_transformer.rb', line 93

def cache
  @cache
end

Instance Method Details

#fetch(key) ⇒ Class

Parameters:

  • key (Class)

    the ActiveFedora class to map

Returns:

  • (Class)

103
104
105
106
107
# File 'lib/wings/model_transformer.rb', line 103

def fetch(key)
  @cache.fetch(key) do
    @cache[key] = yield
  end
end