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 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

Instance Method Details

#base_uriObject



15
16
17
# File 'lib/active_triples/configurable.rb', line 15

def base_uri
  configuration[:base_uri]
end

#configurationObject



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

Parameters:

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


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

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



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

#repositoryObject



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

#typeObject



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

def type
  configuration[:type]
end