Module: ActiveTriples::Configurable

Extended by:
Deprecation
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

Examples:

configure base_uri: "http://oregondigital.org/resource/",
  repository: :default

Instance Method Summary collapse

Instance Method Details

#base_uriObject



19
20
21
# File 'lib/active_triples/configurable.rb', line 19

def base_uri
  configuration[:base_uri]
end

#configurationObject



31
32
33
# File 'lib/active_triples/configurable.rb', line 31

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)

Examples:

configure base_uri: "http://oregondigital.org/resource/", repository: :default

Parameters:

  • options (Hash) (defaults to: {})


55
56
57
58
59
60
61
62
63
# File 'lib/active_triples/configurable.rb', line 55

def configure(options = {})
  options = options.map do |key, value|
    if self.respond_to?("transform_#{key}")
      value = self.__send__("transform_#{key}", value)
    end
    [key, value]
  end
  @configuration = configuration.merge(options)
end

#rdf_labelObject



23
24
25
# File 'lib/active_triples/configurable.rb', line 23

def rdf_label
  configuration[:rdf_label]
end

#repositoryObject



35
36
37
# File 'lib/active_triples/configurable.rb', line 35

def repository
  configuration[:repository]
end

#transform_type(values) ⇒ Object



65
66
67
68
69
70
71
# File 'lib/active_triples/configurable.rb', line 65

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

#typeObject



27
28
29
# File 'lib/active_triples/configurable.rb', line 27

def type
  configuration[:type]
end