Class: Hyrax::Resource

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

Overview

Note:

Hyrax permissions are managed via [Access Control List](en.wikipedia.org/wiki/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 WithEmbargoesAndLeases

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

Methods included from WithEvents

#event_class, #events, #log_event, #stream

Class Method Details

.acts_as_flexible_resourceObject



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

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)


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

def collection?
  pcdm_collection?
end

.file?Boolean

Returns:

  • (Boolean)


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

def file?
  false
end

.file_set?Boolean

Returns:

  • (Boolean)


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

def file_set?
  false
end

.flexible?Boolean

Returns:

  • (Boolean)


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

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



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

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

.inherited(subclass) ⇒ Object



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

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

.pcdm_collection?Boolean

Returns:

  • (Boolean)


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

def pcdm_collection?
  false
end

.pcdm_object?Boolean

Returns:

  • (Boolean)


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

def pcdm_object?
  false
end

.to_rdf_representationString

Returns:

  • (String)


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

def to_rdf_representation
  name
end

.work?Boolean

Works are PCDM Objects which are not File Sets.

Returns:

  • (Boolean)


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

def work?
  pcdm_object? && !file_set?
end

Instance Method Details

#==(other) ⇒ Object



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

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)


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

def collection?
  self.class.collection?
end

#file?Boolean

Returns:

  • (Boolean)


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

def file?
  self.class.file?
end

#file_set?Boolean

Returns:

  • (Boolean)


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

def file_set?
  self.class.file_set?
end

#flexible?Boolean

Returns:

  • (Boolean)


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

def flexible?
  self.class.flexible?
end

#pcdm_collection?Boolean

Returns:

  • (Boolean)


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

def pcdm_collection?
  self.class.pcdm_collection?
end

#pcdm_object?Boolean

Returns:

  • (Boolean)


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

def pcdm_object?
  self.class.pcdm_object?
end

#permission_managerObject



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

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

#to_rdf_representationString

Returns:

  • (String)


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

def to_rdf_representation
  self.class.to_rdf_representation
end

#visibilityObject



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

def visibility
  visibility_reader.read
end

#visibility=(value) ⇒ Object



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

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)


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

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

#work?Boolean

Works are PCDM Objects which are not File Sets.

Returns:

  • (Boolean)


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

def work?
  self.class.work?
end