Class: Valkyrie::Persistence::Fedora::Persister::OrmConverter::GraphToAttributes::Applicator
- Inherits:
-
Object
- Object
- Valkyrie::Persistence::Fedora::Persister::OrmConverter::GraphToAttributes::Applicator
- Defined in:
- lib/valkyrie/persistence/fedora/persister/orm_converter.rb
Overview
Class for mapping RDF statements in Property objects to Valkyrie Resource attributes
Direct Known Subclasses
Instance Attribute Summary collapse
-
#property ⇒ Object
readonly
Returns the value of attribute property.
Instance Method Summary collapse
-
#apply_to(hsh) ⇒ Hash
Apply as a single value by default, if there are multiple then create an array.
- #blacklist ⇒ Array<String> deprecated Deprecated.
- #blacklist?(key) ⇒ Boolean deprecated Deprecated.
-
#cast_array(values) ⇒ Array<Object>
Casts values into an Array.
-
#deny?(key) ⇒ Boolean
Determines whether or not a key is on the deny list for mapping (For example <fedora.info/definitions> assertions are not mapped to Valkyrie attributes).
-
#denylist ⇒ Array<String>
Retrieve a list of denied URIs for predicates.
-
#initialize(property) ⇒ Applicator
constructor
A new instance of Applicator.
-
#key ⇒ Symbol
Derive the key for the Valkyrie resource attribute from the RDF statement in the Property.
-
#namespaces ⇒ Array<String>
Retrieve a list of namespace URIs for predicates.
-
#values ⇒ RDF::URI
Access the object for the RDF statement.
Constructor Details
#initialize(property) ⇒ Applicator
Returns a new instance of Applicator.
520 521 522 |
# File 'lib/valkyrie/persistence/fedora/persister/orm_converter.rb', line 520 def initialize(property) @property = property end |
Instance Attribute Details
#property ⇒ Object (readonly)
Returns the value of attribute property.
515 516 517 |
# File 'lib/valkyrie/persistence/fedora/persister/orm_converter.rb', line 515 def property @property end |
Instance Method Details
#apply_to(hsh) ⇒ Hash
Apply as a single value by default, if there are multiple then create an array. Done to support single values - if the resource is a Set or Array then it’ll cast the single value back to an array appropriately.
530 531 532 533 534 535 536 537 |
# File 'lib/valkyrie/persistence/fedora/persister/orm_converter.rb', line 530 def apply_to(hsh) return if deny?(key) hsh[key.to_sym] = if hsh.key?(key.to_sym) Array.wrap(hsh[key.to_sym]) + cast_array(values) else values end end |
#blacklist ⇒ Array<String>
Retrieve a list of denied URIs for predicates
581 582 583 584 |
# File 'lib/valkyrie/persistence/fedora/persister/orm_converter.rb', line 581 def blacklist warn "[DEPRECATION] Samvera is deprecating '#{self.class}#blacklist' in 3.0.0. Use #{self.class}#denylist instead." denylist end |
#blacklist?(key) ⇒ Boolean
Determines whether or not a key is on the deny list for mapping (For example <fedora.info/definitions> assertions are not mapped to Valkyrie attributes)
555 556 557 558 |
# File 'lib/valkyrie/persistence/fedora/persister/orm_converter.rb', line 555 def blacklist?(key) warn "[DEPRECATION] Samvera is deprecating '#{self.class}#blacklist?' in 3.0.0. Use #{self.class}#deny? instead." deny?(key) end |
#cast_array(values) ⇒ Array<Object>
Casts values into an Array
574 575 576 |
# File 'lib/valkyrie/persistence/fedora/persister/orm_converter.rb', line 574 def cast_array(values) Array(values) end |
#deny?(key) ⇒ Boolean
Determines whether or not a key is on the deny list for mapping (For example <fedora.info/definitions> assertions are not mapped to Valkyrie attributes)
564 565 566 567 568 569 |
# File 'lib/valkyrie/persistence/fedora/persister/orm_converter.rb', line 564 def deny?(key) denylist.each do |denylist_item| return true if key.start_with?(denylist_item) end false end |
#denylist ⇒ Array<String>
Retrieve a list of denied URIs for predicates
588 589 590 591 592 593 |
# File 'lib/valkyrie/persistence/fedora/persister/orm_converter.rb', line 588 def denylist [ "http://fedora.info/definitions", "http://www.iana.org/assignments/relation/last" ] end |
#key ⇒ Symbol
Derive the key for the Valkyrie resource attribute from the RDF statement in the Property
541 542 543 544 545 546 547 548 |
# File 'lib/valkyrie/persistence/fedora/persister/orm_converter.rb', line 541 def key predicate = statement.predicate.to_s key = schema.property_for(resource: nil, predicate: predicate) namespaces.each do |namespace| key = key.to_s.gsub(/^#{namespace}/, '') end key end |
#namespaces ⇒ Array<String>
Retrieve a list of namespace URIs for predicates
597 598 599 600 601 602 |
# File 'lib/valkyrie/persistence/fedora/persister/orm_converter.rb', line 597 def namespaces [ "http://www.fedora.info/definitions/v4/", "http://www.w3.org/1999/02/22-rdf-syntax-ns#" ] end |
#values ⇒ RDF::URI
Access the object for the RDF statement
606 607 608 |
# File 'lib/valkyrie/persistence/fedora/persister/orm_converter.rb', line 606 def values statement.object end |