module ActiveTriples::Configurable

Module to include configurable class-wide properties common to RDFSources.

Define properties at the class level with:

@example

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

Available properties are base_uri, rdf_label, type, and repository

Public Instance Methods

base_uri() click to toggle source
# File lib/active_triples/configurable.rb, line 22
def base_uri
  configuration[:base_uri]
end
configuration() click to toggle source
# File lib/active_triples/configurable.rb, line 34
def configuration
  @configuration ||= Configuration.new
end
configure(options = {}) click to toggle source

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)

@example

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

@param options [Hash]

# File lib/active_triples/configurable.rb, line 58
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
inherited(child_class) click to toggle source
Calls superclass method
# File lib/active_triples/configurable.rb, line 17
def inherited(child_class)
  child_class.configure type: self.type
  super
end
rdf_label() click to toggle source
# File lib/active_triples/configurable.rb, line 26
def rdf_label
  configuration[:rdf_label]
end
repository() click to toggle source
# File lib/active_triples/configurable.rb, line 38
def repository
  configuration[:repository]
end
transform_type(values) click to toggle source
# File lib/active_triples/configurable.rb, line 68
def transform_type(values)
  Array.wrap(values).map do |value|
    RDF::URI.intern(value).tap do |uri|
      RDFSource.type_registry[uri] = self
    end
  end
end
type() click to toggle source
# File lib/active_triples/configurable.rb, line 30
def type
  configuration[:type]
end