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

#human_readable_typeString

Returns:

  • (String)


53
54
55
# File 'lib/hyrax/active_fedora_dummy_model.rb', line 53

def human_readable_type
  @model.human_readable_type
end

#model_nameObject



46
47
48
# File 'lib/hyrax/active_fedora_dummy_model.rb', line 46

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



71
72
73
74
75
76
77
78
# File 'lib/hyrax/active_fedora_dummy_model.rb', line 71

def to_global_id
  # this covers the use case of creating a non Valkyrie::Resource, while using Valkyrie
  if model_name.name.constantize <= Valkyrie::Resource
    URI::GID.build app: GlobalID.app, model_name: Hyrax::ValkyrieGlobalIdProxy.to_s, model_id: @id
  else
    URI::GID.build app: GlobalID.app, model_name: model_name.name, model_id: @id
  end
end

#to_keyObject



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

def to_key
  [@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



62
63
64
65
66
67
# File 'lib/hyrax/active_fedora_dummy_model.rb', line 62

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

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