Sha256: 3cc3306c42335579a02ee062bff560dae216be37cc739b918b35f92b95ffc62f

Contents?: true

Size: 635 Bytes

Versions: 9

Compression:

Stored size: 635 Bytes

Contents

module Hydra::Works::Characterization
  class AlreadyThereStrategy < ActiveTriples::ExtensionStrategy
    # override apply method to check if property already exists or reciever already has predicate defined.
    # Do not add property if the rdf_resource already responds to the property name
    # Do not add property if the rdf_resource already has a property with the same predicate.
    def self.apply(resource, property)
      return if resource.respond_to?(property.name)
      return if resource.properties.any? { |p| p[1].predicate == property.predicate }
      resource.property property.name, property.to_h
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
hydra-works-0.9.0 lib/hydra/works/models/characterization/already_there_strategy.rb
hydra-works-0.8.1 lib/hydra/works/models/characterization/already_there_strategy.rb
hydra-works-0.8 lib/hydra/works/models/characterization/already_there_strategy.rb
hydra-works-0.7.1 lib/hydra/works/models/characterization/already_there_strategy.rb
hydra-works-0.7.0 lib/hydra/works/models/characterization/already_there_strategy.rb
hydra-works-0.6.0 lib/hydra/works/models/characterization/already_there_strategy.rb
hydra-works-0.5.0 lib/hydra/works/models/characterization/already_there_strategy.rb
hydra-works-0.4.0 lib/hydra/works/models/characterization/already_there_strategy.rb
hydra-works-0.3.0 lib/hydra/works/models/characterization/already_there_strategy.rb