Class: Hyrax::SolrDocumentBehavior::ModelWrapper

Inherits:
Object
  • Object
show all
Defined in:
app/models/concerns/hyrax/solr_document_behavior.rb

Overview

Note:

access this via #to_model.

Given a model class and an id, provides ActiveModel style model methods.

Instance Method Summary collapse

Constructor Details

#initialize(model, id) ⇒ ModelWrapper

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of ModelWrapper.

Parameters:

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


52
53
54
55
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 52

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

Instance Method Details

#model_nameObject



71
72
73
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 71

def model_name
  @model.model_name
end

#persisted?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 59

def persisted?
  true
end

#to_global_idObject



89
90
91
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 89

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

#to_paramObject



65
66
67
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 65

def to_param
  @id
end

#to_partial_pathObject

Note:

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



80
81
82
83
84
85
# File 'app/models/concerns/hyrax/solr_document_behavior.rb', line 80

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

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