Module: ActiveTriples::Configurable
- Included in:
- List
- Defined in:
- lib/active_triples/configurable.rb
Overview
Module to include configurable class-wide properties common to RDFSources.
Define properties at the class level with:
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 RDFSource.
- #rdf_label ⇒ Object
- #repository ⇒ Object
- #transform_type(values) ⇒ Object
- #type ⇒ Object
Instance Method Details
#base_uri ⇒ Object
17 18 19 |
# File 'lib/active_triples/configurable.rb', line 17 def base_uri configuration[:base_uri] end |
#configuration ⇒ Object
29 30 31 |
# File 'lib/active_triples/configurable.rb', line 29 def configuration @configuration ||= Configuration.new end |
#configure(options = {}) ⇒ Object
API for configuring class properties on a RDFSource. This is an alternative to overriding the methods in this module.
Can configure the following values:
- base_uri (allows passing slugs to the RDFSource initializer
in place of fully qualified URIs)
- rdf_label (overrides default label predicates)
- type (a default rdf:type to include when initializing a
new RDFSource)
- repository (the target persist location to for the RDFSource)
53 54 55 56 57 58 59 60 61 |
# File 'lib/active_triples/configurable.rb', line 53 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
21 22 23 |
# File 'lib/active_triples/configurable.rb', line 21 def rdf_label configuration[:rdf_label] end |
#repository ⇒ Object
33 34 35 |
# File 'lib/active_triples/configurable.rb', line 33 def repository configuration[:repository] end |
#transform_type(values) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/active_triples/configurable.rb', line 63 def transform_type(values) Array.wrap(values).map do |value| RDF::URI.new(value).tap do |uri| RDFSource.type_registry[uri] = self end end end |
#type ⇒ Object
25 26 27 |
# File 'lib/active_triples/configurable.rb', line 25 def type configuration[:type] end |