Module: ActiveTriples::Configurable
Overview
Module to include configurable class-wide properties common to Resource and RDFDatastream. It does its work at the class level, and is meant to be extended.
Define properties at the class level with:
configure base_uri: "http://oregondigital.org/resource/", repository: :default
Available properties are base_uri, rdf_label, type, and repository
Instance Method Summary collapse
- #base_uri ⇒ Object
- #configuration ⇒ Object
-
#configure(options = {}) ⇒ Object
API for configuring class properties on a Resource.
- #rdf_label ⇒ Object
-
#rdf_type(value) ⇒ Object
deprecated
Deprecated.
use ‘configure type:` instead.
- #repository ⇒ Object
- #transform_type(values) ⇒ Object
- #type ⇒ Object
Instance Method Details
#base_uri ⇒ Object
15 16 17 |
# File 'lib/active_triples/configurable.rb', line 15 def base_uri configuration[:base_uri] end |
#configuration ⇒ Object
27 28 29 |
# File 'lib/active_triples/configurable.rb', line 27 def configuration @configuration ||= Configuration.new end |
#configure(options = {}) ⇒ Object
API for configuring class properties on a Resource. This is an alternative to overriding the methods in this module.
Can configure the following values:
- base_uri (allows passing slugs to the Resource initializer
in place of fully qualified URIs)
- rdf_label (overrides default label predicates)
- type (a default rdf:type to include when initializing a
new Resource)
- repository (the target persist location to for the Resource)
configure base_uri: "http://oregondigital.org/resource/", repository: :default
57 58 59 60 61 62 63 64 65 |
# File 'lib/active_triples/configurable.rb', line 57 def configure( = {}) = .map do |key, value| if self.respond_to?("transform_#{key}") value = self.__send__("transform_#{key}", value) end [key, value] end @configuration = configuration.merge() end |
#rdf_label ⇒ Object
19 20 21 |
# File 'lib/active_triples/configurable.rb', line 19 def rdf_label configuration[:rdf_label] end |
#rdf_type(value) ⇒ Object
Deprecated.
use ‘configure type:` instead.
33 34 35 36 |
# File 'lib/active_triples/configurable.rb', line 33 def rdf_type(value) Deprecation.warn Configurable, "rdf_type is deprecated and will be removed in active-fedora 8.0.0. Use configure type: instead.", caller configure type: value end |
#repository ⇒ Object
38 39 40 |
# File 'lib/active_triples/configurable.rb', line 38 def repository configuration[:repository] || :parent end |
#transform_type(values) ⇒ Object
67 68 69 70 71 72 73 |
# File 'lib/active_triples/configurable.rb', line 67 def transform_type(values) Array(values).map do |value| RDF::URI.new(value).tap do |uri| Resource.type_registry[uri] = self end end end |
#type ⇒ Object
23 24 25 |
# File 'lib/active_triples/configurable.rb', line 23 def type configuration[:type] end |