Class: LD4L::OpenAnnotationRDF::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/ld4l/open_annotation_rdf/configuration.rb

Overview

Note:

Use LD4L::OpenAnnotationRDF.configure to call the methods in this class. See ‘Configure all configurable properties’ example for most common approach to configuration.

Used by LD4L::OpenAnnotationRDF class to configure…

  • base_uri

  • local_minter

  • unique_tags

Examples:

Configure all configurable properties

LD4L::OpenAnnotationRDF.configure do |config|
  config.base_uri         = "http://www.example.org/annotations/"
  config.localname_minter = lambda { |prefix=""| prefix+SecureRandom.uuid }
  config.unique_tags      = true
end

Usage of base uri and local name

# uri = base_uri + localname"
annotation = LD4L::OpenAnnotationRDF::CommentAnnotation.new(
  ActiveTriples::LocalName::Minter.generate_local_name(
      LD4L::OpenAnnotationRDF::CommentBody, 10, 'a',
      LD4L::OpenAnnotationRDF.configuration.localname_minter ))
annotation.rdf_subject
# => "http://www.example.org/annotations/a9f85752c-9c2c-4a65-997a-68482895a656"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



84
85
86
87
88
# File 'lib/ld4l/open_annotation_rdf/configuration.rb', line 84

def initialize
  @base_uri         = self.class.send(:default_base_uri)
  @localname_minter = self.class.send(:default_localname_minter)
  @unique_tags      = self.class.send(:default_unique_tags)
end

Instance Attribute Details

#base_uriObject #base_uri=(new_base_uri) ⇒ Object

Overloads:

  • #base_uriObject

    Get the base_uri to be used when generating rdf_subjects for new objects. See example configuration and usage in class documentation examples.

    Returns:

    • the configured base_uri

  • #base_uri=(new_base_uri) ⇒ Object
    Note:

    base_uri will only take effect when a model class is first created. Once the model class is created, the base_uri is bound to the class.

    Set the base_uri to be used when generating rdf_subjects for new objects. See example configuration and usage in class documentation examples.

    Parameters:

    • new (String)

      value for the base_uri



37
38
39
# File 'lib/ld4l/open_annotation_rdf/configuration.rb', line 37

def base_uri
  @base_uri
end

#localname_minterObject #localname_minter=(new_localname_minter) ⇒ Object

Overloads:

  • #localname_minterObject

    Get the localname_minter to be used when generating rdf_subjects for new objects. See example configuration and usage in class documentation examples.

    Returns:

    • the configured localname_minter

  • #localname_minter=(new_localname_minter) ⇒ Object

    Set the localname_minter to be used when generating rdf_subjects for new objects. See example configuration and usage in class documentation examples.

    Parameters:

    • new (String)

      value for the localname_minter



46
47
48
# File 'lib/ld4l/open_annotation_rdf/configuration.rb', line 46

def localname_minter
  @localname_minter
end

#unique_tagsObject #unique_tags=(new_unique_tags) ⇒ Object

Overloads:

  • #unique_tagsObject

    Get whether the GEM should enforce uniqueness of user generated tags when using the TagAnnotation::setTag method. See example configuration and usage in class documentation examples.

    Returns:

    • the configured unique_tags

  • #unique_tags=(new_unique_tags) ⇒ Object

    Set whether the GEM should enforce uniqueness of user generated tags when using the TagAnnotation::setTag method.

    Parameters:

    • new (Boolean)

      value for the unique_tags

      true - enforce uniqueness (default)

      - annotations share TagBodys
      - setTag method looks for an existing TagBody with the tag value and reuses the existing TagBody
      - setTag to change a tag's value will create/reuse a different TagBody for the new tag value
      

      false - do not enforce uniqueness

      - annotation owns its TagBody
      - setTag first time call creates a TagBody with the tag value
      - setTag to change the tag's value will modify the tag value in this annotation's TagBody
      


66
67
68
# File 'lib/ld4l/open_annotation_rdf/configuration.rb', line 66

def unique_tags
  @unique_tags
end

Instance Method Details

#reset_base_uriObject

Reset the base_uri to be used when generating rdf_subject for new objects back to the default configuration.



97
98
99
# File 'lib/ld4l/open_annotation_rdf/configuration.rb', line 97

def reset_base_uri
  @base_uri = self.class.send(:default_base_uri)
end

#reset_localname_minterObject

Reset the minter to be used to generate the local name portion of the rdf_subject for new objects to the default minter.



109
110
111
# File 'lib/ld4l/open_annotation_rdf/configuration.rb', line 109

def reset_localname_minter
  @localname_minter = self.class.send(:default_localname_minter)
end

#reset_unique_tagsObject

Reset whether the GEM should enforce uniqueness of user generated tags, when using the TagAnnotation::setTag method, to the default configuration (true).

See Also:



122
123
124
# File 'lib/ld4l/open_annotation_rdf/configuration.rb', line 122

def reset_unique_tags
  @unique_tags = self.class.send(:default_unique_tags)
end