Class: Hyrax::ActiveFedoraDummyModel

Inherits:
Object
  • Object
show all
Defined in:
lib/hyrax/active_fedora_dummy_model.rb

Overview

Note:

this was originally implemented for SolrDocument as Hyrax::SolrDocumentBehavior::ModelWrapper, but is useful in the more general case that we know the model class and id, but don't have a full model object.

Given a model class and an id, provides ActiveModel style methods. This is a tool for providing route resolution and other ActiveModel behavior for ActiveFedora without loading the object from the fedora backend.

Instance Method Summary collapse

Constructor Details

#initialize(model, id) ⇒ ActiveFedoraDummyModel

Returns a new instance of ActiveFedoraDummyModel.

Parameters:

  • model (Class)
  • id (String, nil)

21
22
23
24
# File 'lib/hyrax/active_fedora_dummy_model.rb', line 21

def initialize(model, id)
  @model = model
  @id = id
end

Instance Method Details

#model_nameObject


40
41
42
# File 'lib/hyrax/active_fedora_dummy_model.rb', line 40

def model_name
  @model.model_name
end

#persisted?Boolean

Returns:

  • (Boolean)

28
29
30
# File 'lib/hyrax/active_fedora_dummy_model.rb', line 28

def persisted?
  true
end

#to_global_idObject


58
59
60
# File 'lib/hyrax/active_fedora_dummy_model.rb', line 58

def to_global_id
  URI::GID.build app: GlobalID.app, model_name: model_name.name, model_id: @id
end

#to_paramObject


34
35
36
# File 'lib/hyrax/active_fedora_dummy_model.rb', line 34

def to_param
  @id
end

#to_partial_pathObject

Note:

uses the @model's `._to_partial_path` if implemented, otherwise constructs a default


49
50
51
52
53
54
# File 'lib/hyrax/active_fedora_dummy_model.rb', line 49

def to_partial_path
  return @model._to_partial_path if
    @model.respond_to?(:_to_partial_path)

  "hyrax/#{model_name.collection}/#{model_name.element}"
end