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.



132
133
134
# File 'lib/wings/model_transformer.rb', line 132

def initialize
  @cache = {}
end

Instance Attribute Details

#cacheObject (readonly)

Returns the value of attribute cache.



130
131
132
# File 'lib/wings/model_transformer.rb', line 130

def cache
  @cache
end

Instance Method Details

#fetch(key) ⇒ Class

Parameters:

  • key (Class)

    the ActiveFedora class to map

Returns:

  • (Class)


140
141
142
143
144
# File 'lib/wings/model_transformer.rb', line 140

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