Class: Wings::ActiveFedoraConverter::PropertyApplicator

Inherits:
Object
  • Object
show all
Defined in:
lib/wings/active_fedora_converter/default_work.rb

Overview

Constructs an ActiveFedora property from a Dry::Types schema key. This applicator is intended to handle details like assocation types, where needed.

Examples:

MyValkyrieResource.schema.each do |schema_key|
  PropertyApplicator.new(schema_key).apply(MyActiveFedoraClass)
end

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ PropertyApplicator

Returns a new instance of PropertyApplicator.

Parameters:

  • key (Dry::Types::Schema::Key)

20
21
22
# File 'lib/wings/active_fedora_converter/default_work.rb', line 20

def initialize(key)
  @key = key
end

Instance Method Details

#apply(klass) ⇒ void

Note:

this method is a silent no-op if the property is already defined or is a protected property on the target class

This method returns an undefined value.

Returns apply the property.


29
30
31
32
33
# File 'lib/wings/active_fedora_converter/default_work.rb', line 29

def apply(klass)
  return if klass.properties.keys.include?(name) ||
            klass.protected_property_name?(name)
  klass.send(definition_method, name, options)
end

#definition_methodSymbol

Returns the method name for property/association definition.

Returns:

  • (Symbol)

    the method name for property/association definition


37
38
39
40
41
# File 'lib/wings/active_fedora_converter/default_work.rb', line 37

def definition_method
  return :ordered_aggregation if @key.name == :member_ids
  return :indirectly_contains if @key.name == :member_of_collection_ids
  :property
end

#nameSymbol

Returns:

  • (Symbol)

45
46
47
48
49
# File 'lib/wings/active_fedora_converter/default_work.rb', line 45

def name
  return :members if @key.name == :member_ids
  return :member_of_collections if @key.name == :member_of_collection_ids
  @key.name
end

#optionsHash<Symbol, Object>

Returns:

  • (Hash<Symbol, Object>)

53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/wings/active_fedora_converter/default_work.rb', line 53

def options
  return { has_member_relation: predicate, class_name: 'ActiveFedora::Base', through: :list_source } if
    @key.name == :member_ids

  if @key.name == :member_of_collection_ids
    return { has_member_relation: predicate, class_name: 'ActiveFedora::Base',
             inserted_content_relation: RDF::Vocab::ORE.proxyFor, through: 'ActiveFedora::Aggregation::Proxy',
             foreign_key: :target }
  end

  { predicate: predicate }
end

#predicateRDF::URI

Returns:

  • (RDF::URI)

68
69
70
71
72
73
# File 'lib/wings/active_fedora_converter/default_work.rb', line 68

def predicate
  return Hydra::PCDM::Vocab::PCDMTerms.hasMember if @key.name == :member_ids
  return Hydra::PCDM::Vocab::PCDMTerms.memberOf if @key.name == :member_of_collection_ids

  RDF::URI.intern("http://hyrax.samvera.org/ns/wings##{name}")
end