Class: Hyrax::Resource

Inherits:
Valkyrie::Resource
  • Object
show all
Includes:
Naming, Suppressible, WithEmbargoesAndLeases, WithEvents
Defined in:
app/models/hyrax/resource.rb

Overview

Note:

Hyrax permissions are managed via Access Control List style permissions. Legacy Hyrax models powered by ActiveFedora linked the ACLs from the repository object itself (as an acl:accessControl link to a container). Valkyrie models jettison that approach in favor of relying on links back from the permissions using access_to. As was the case in the past implementation, we include an object to represent the access list itself (Hyrax::AccessControl). This object's #access_to is the way Hyrax discovers list entries--it MUST match between the AccessControl and its individual Permissions.

The effect of this change is that our AccessControl objects are detached from Hyrax::Resource they can (and usually should) be edited and persisted independently from the resource itself.

Some utilitiy methods are provided for ergonomics in transitioning from ActiveFedora: the #visibility accessor, and the #*_users and #*_group accessors. The main purpose of these is to provide a cached ACL attached to a given Resource instance. However, these will likely be deprecated in the future, and it's advisable to avoid them in favor of Hyrax::AccessControlList, Hyrax::PermissionManager and/or Hyrax::VisibilityWriter (which provide their underlying implementations).

The base Valkyrie model for Hyrax.

Direct Known Subclasses

AdministrativeSet, FileSet, PcdmCollection, Work

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Suppressible

#suppressed?

Methods included from WithEmbargoesAndLeases

#embargo, #embargo=, #lease, #lease=

Methods included from WithEvents

#event_class, #events, #log_event, #stream

Class Method Details

.acts_as_flexible_resourceObject



54
55
56
57
58
# File 'app/models/hyrax/resource.rb', line 54

def acts_as_flexible_resource
  include Hyrax::Flexibility
  include Hyrax::Schema(name, schema_loader: Hyrax::Schema.m3_schema_loader)
  Hyrax.config.flexible_classes << name unless Hyrax.config.flexible_classes.include?(name)
end

.collection?Boolean

Returns:

  • (Boolean)


72
73
74
# File 'app/models/hyrax/resource.rb', line 72

def collection?
  pcdm_collection?
end

.file?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'app/models/hyrax/resource.rb', line 78

def file?
  false
end

.file_set?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'app/models/hyrax/resource.rb', line 84

def file_set?
  false
end

.flexible?Boolean

Returns:

  • (Boolean)


60
61
62
# File 'app/models/hyrax/resource.rb', line 60

def flexible?
  defined?(super) ? super : false
end

.human_readable_typeString

Returns a human readable name for the model.

Returns:

  • (String)

    a human readable name for the model



66
67
68
# File 'app/models/hyrax/resource.rb', line 66

def human_readable_type
  I18n.translate("hyrax.models.#{model_name.i18n_key}", default: model_name.human)
end

.inherited(subclass) ⇒ Object



49
50
51
52
# File 'app/models/hyrax/resource.rb', line 49

def inherited(subclass)
  super
  subclass.acts_as_flexible_resource if Hyrax.config.flexible_classes.include?(subclass.name)
end

.pcdm_collection?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'app/models/hyrax/resource.rb', line 90

def pcdm_collection?
  false
end

.pcdm_object?Boolean

Returns:

  • (Boolean)


96
97
98
# File 'app/models/hyrax/resource.rb', line 96

def pcdm_object?
  false
end

.to_rdf_representationString

Returns:

  • (String)


110
111
112
# File 'app/models/hyrax/resource.rb', line 110

def to_rdf_representation
  name
end

.work?Boolean

Works are PCDM Objects which are not File Sets.

Returns:

  • (Boolean)


104
105
106
# File 'app/models/hyrax/resource.rb', line 104

def work?
  pcdm_object? && !file_set?
end

Instance Method Details

#==(other) ⇒ Object



178
179
180
# File 'app/models/hyrax/resource.rb', line 178

def ==(other)
  attributes.except(:created_at, :updated_at) == other.attributes.except(:created_at, :updated_at) if other.respond_to?(:attributes)
end

#collection?Boolean

Returns:

  • (Boolean)


131
132
133
# File 'app/models/hyrax/resource.rb', line 131

def collection?
  self.class.collection?
end

#file?Boolean

Returns:

  • (Boolean)


137
138
139
# File 'app/models/hyrax/resource.rb', line 137

def file?
  self.class.file?
end

#file_set?Boolean

Returns:

  • (Boolean)


143
144
145
# File 'app/models/hyrax/resource.rb', line 143

def file_set?
  self.class.file_set?
end

#flexible?Boolean

Returns:

  • (Boolean)


125
126
127
# File 'app/models/hyrax/resource.rb', line 125

def flexible?
  self.class.flexible?
end

#pcdm_collection?Boolean

Returns:

  • (Boolean)


149
150
151
# File 'app/models/hyrax/resource.rb', line 149

def pcdm_collection?
  self.class.pcdm_collection?
end

#pcdm_object?Boolean

Returns:

  • (Boolean)


155
156
157
# File 'app/models/hyrax/resource.rb', line 155

def pcdm_object?
  self.class.pcdm_object?
end

#permission_managerObject



182
183
184
# File 'app/models/hyrax/resource.rb', line 182

def permission_manager
  @permission_manager ||= Hyrax::PermissionManager.new(resource: self)
end

#to_rdf_representationString

Returns:

  • (String)


161
162
163
# File 'app/models/hyrax/resource.rb', line 161

def to_rdf_representation
  self.class.to_rdf_representation
end

#visibilityObject



190
191
192
# File 'app/models/hyrax/resource.rb', line 190

def visibility
  visibility_reader.read
end

#visibility=(value) ⇒ Object



186
187
188
# File 'app/models/hyrax/resource.rb', line 186

def visibility=(value)
  visibility_writer.assign_access_for(visibility: value)
end

#wings?Boolean

Its nice to know if a record is still in AF or not

Returns:

  • (Boolean)


174
175
176
# File 'app/models/hyrax/resource.rb', line 174

def wings?
  respond_to?(:head) && respond_to?(:tail)
end

#work?Boolean

Works are PCDM Objects which are not File Sets.

Returns:

  • (Boolean)


169
170
171
# File 'app/models/hyrax/resource.rb', line 169

def work?
  self.class.work?
end