module Gearbox

Public Class Methods

add_repository(name, klass, *args) click to toggle source

Add a repository to Gearbox’s list of repositories.

@overload add_repository(name, repo)

@param [Symbol] name The name of this repository
@param [RDF::Repository] repo An RDF::Repository

@overload add_repository(name, klass, *args)

@param [Symbol] name The name of this repository
@param [RDF::Repository, Class] repo A Class that inherits from RDF::Repository
@param [*Object] The list of arguments to instantiate the class

@example Adding an ntriples file as a repository

Gearbox.add_repository(:default, RDF::Repository.load('http://datagraph.org/jhacker/foaf.nt'))

@example Adding an empty repository to be instantiated on use

Gearbox.add_repository(:default, RDF::Repository)

@return [Void] @see RDF::Repository

# File lib/gearbox.rb, line 61
def add_repository(name, klass, *args)
  repositories[name] = case klass
    when Class
      promise { klass.new(*args) }
    else
      klass
   end
   if (name == :default) && settings[:repositories][name].nil?
      warn "WARNING: Adding nil default repository"
   end
end
Also aliased as: add_repository!
add_repository!(name, klass, *args)
Alias for: add_repository
clear_repositories!() click to toggle source

Clear all repositories from Gearbox’s knowledge. Use it if you want, but it’s really here for testing.

@return [Void] @private

# File lib/gearbox.rb, line 92
def clear_repositories!
  settings[:repositories] = {}
end
path(path) click to toggle source

Helper Utility: path =

@private

# File lib/gearbox.rb, line 114
def path(path)
  File.expand_path("../gearbox/#{path}", __FILE__)
end
repositories() click to toggle source

Settings from Spira =

The list of repositories available for Gearbox resources

@see rdf.rubyforge.org/RDF/Repository.html @return [Hash{Symbol => RDF::Repository}] @private

# File lib/gearbox.rb, line 19
def repositories
  settings[:repositories] ||= {}
end
repository(name) click to toggle source

The RDF::Repository for the named repository

@param [Symbol] name The name of the repository @return [RDF::Repository] @see RDF::Repository

# File lib/gearbox.rb, line 81
def repository(name)
  repositories[name]
end
settings() click to toggle source

A thread-local hash for storing settings. Used by Resource classes.

@see Gearbox::Resource @see Gearbox.repositories @see Gearbox.types

# File lib/gearbox.rb, line 40
def settings
  Thread.current[:gearbox] ||= {}
end
type_alias(new, original) click to toggle source

Alias a property type to another. This allows a range of options to be specified for a property type which all reference one Gearbox::Type

@param [Any] new The new symbol or reference @param [Any] original The type the new symbol should refer to @return [Void] @private

# File lib/gearbox.rb, line 105
def type_alias(new, original)
  types[new] = original 
end
types() click to toggle source

The list of all property types available for Gearbox resources

@see Gearbox::Types @return [Hash{Symbol => Gearbox::Type}]

# File lib/gearbox.rb, line 29
def types
  settings[:types] ||= {}
end

Private Instance Methods

add_repository(name, klass, *args) click to toggle source

Add a repository to Gearbox’s list of repositories.

@overload add_repository(name, repo)

@param [Symbol] name The name of this repository
@param [RDF::Repository] repo An RDF::Repository

@overload add_repository(name, klass, *args)

@param [Symbol] name The name of this repository
@param [RDF::Repository, Class] repo A Class that inherits from RDF::Repository
@param [*Object] The list of arguments to instantiate the class

@example Adding an ntriples file as a repository

Gearbox.add_repository(:default, RDF::Repository.load('http://datagraph.org/jhacker/foaf.nt'))

@example Adding an empty repository to be instantiated on use

Gearbox.add_repository(:default, RDF::Repository)

@return [Void] @see RDF::Repository

# File lib/gearbox.rb, line 61
def add_repository(name, klass, *args)
  repositories[name] = case klass
    when Class
      promise { klass.new(*args) }
    else
      klass
   end
   if (name == :default) && settings[:repositories][name].nil?
      warn "WARNING: Adding nil default repository"
   end
end
Also aliased as: add_repository!
add_repository!(name, klass, *args)
Alias for: add_repository
clear_repositories!() click to toggle source

Clear all repositories from Gearbox’s knowledge. Use it if you want, but it’s really here for testing.

@return [Void] @private

# File lib/gearbox.rb, line 92
def clear_repositories!
  settings[:repositories] = {}
end
path(path) click to toggle source

Helper Utility: path =

@private

# File lib/gearbox.rb, line 114
def path(path)
  File.expand_path("../gearbox/#{path}", __FILE__)
end
repositories() click to toggle source

Settings from Spira =

The list of repositories available for Gearbox resources

@see rdf.rubyforge.org/RDF/Repository.html @return [Hash{Symbol => RDF::Repository}] @private

# File lib/gearbox.rb, line 19
def repositories
  settings[:repositories] ||= {}
end
repository(name) click to toggle source

The RDF::Repository for the named repository

@param [Symbol] name The name of the repository @return [RDF::Repository] @see RDF::Repository

# File lib/gearbox.rb, line 81
def repository(name)
  repositories[name]
end
settings() click to toggle source

A thread-local hash for storing settings. Used by Resource classes.

@see Gearbox::Resource @see Gearbox.repositories @see Gearbox.types

# File lib/gearbox.rb, line 40
def settings
  Thread.current[:gearbox] ||= {}
end
type_alias(new, original) click to toggle source

Alias a property type to another. This allows a range of options to be specified for a property type which all reference one Gearbox::Type

@param [Any] new The new symbol or reference @param [Any] original The type the new symbol should refer to @return [Void] @private

# File lib/gearbox.rb, line 105
def type_alias(new, original)
  types[new] = original 
end
types() click to toggle source

The list of all property types available for Gearbox resources

@see Gearbox::Types @return [Hash{Symbol => Gearbox::Type}]

# File lib/gearbox.rb, line 29
def types
  settings[:types] ||= {}
end