Module: Gearbox

Defined in:
lib/gearbox.rb,
lib/gearbox/type.rb,
lib/gearbox/types.rb,
lib/gearbox/attribute.rb,
lib/gearbox/vocabulary.rb,
lib/gearbox/rdf_collection.rb,
lib/gearbox/mixins/resource.rb,
lib/gearbox/attribute_collection.rb,
lib/gearbox/mixins/subject_methods.rb,
lib/gearbox/mixins/ad_hoc_properties.rb,
lib/gearbox/mixins/semantic_accessors.rb,
lib/gearbox/mixins/queryable_implementation.rb,
lib/gearbox/mixins/active_model_implementation.rb

Defined Under Namespace

Modules: ActiveModelImplementation, AdHocProperties, QueryableImplementation, Resource, SemanticAccessors, SubjectMethods, Type, Types Classes: Attribute, AttributeCollection, RDFCollection, Vocabulary

Class Method Summary collapse

Class Method Details

.add_repository(name, repo) ⇒ Void .add_repository(name, klass, *args) ⇒ Void

Add a repository to Gearbox’s list of repositories.

Examples:

Adding an ntriples file as a repository

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

Adding an empty repository to be instantiated on use

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

Overloads:

  • .add_repository(name, repo) ⇒ Void

    Parameters:

    • name (Symbol)

      The name of this repository

    • repo (RDF::Repository)

      An RDF::Repository

  • .add_repository(name, klass, *args) ⇒ Void

    Parameters:

    • name (Symbol)

      The name of this repository

    • repo (RDF::Repository, Class)

      A Class that inherits from RDF::Repository

    • The (*Object)

      list of arguments to instantiate the class

Returns:

  • (Void)

See Also:

  • RDF::Repository


61
62
63
64
65
66
67
68
69
70
71
# 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

.add_repository(name, repo) ⇒ Void .add_repository(name, klass, *args) ⇒ Void

Add a repository to Gearbox’s list of repositories.

Examples:

Adding an ntriples file as a repository

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

Adding an empty repository to be instantiated on use

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

Overloads:

  • .add_repository(name, repo) ⇒ Void

    Parameters:

    • name (Symbol)

      The name of this repository

    • repo (RDF::Repository)

      An RDF::Repository

  • .add_repository(name, klass, *args) ⇒ Void

    Parameters:

    • name (Symbol)

      The name of this repository

    • repo (RDF::Repository, Class)

      A Class that inherits from RDF::Repository

    • The (*Object)

      list of arguments to instantiate the class

Returns:

  • (Void)

See Also:

  • RDF::Repository


72
73
74
75
76
77
78
79
80
81
82
# File 'lib/gearbox.rb', line 72

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

.clear_repositories!Void

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

Returns:

  • (Void)


92
93
94
# File 'lib/gearbox.rb', line 92

def clear_repositories!
  settings[:repositories] = {}
end

.path(path) ⇒ Object

Helper Utility: path =



114
115
116
# File 'lib/gearbox.rb', line 114

def path(path)
  File.expand_path("../gearbox/#{path}", __FILE__)
end

.repositoriesHash{Symbol => RDF::Repository}

Settings from Spira =

The list of repositories available for Gearbox resources

Returns:

  • (Hash{Symbol => RDF::Repository})

See Also:



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

def repositories
  settings[:repositories] ||= {}
end

.repository(name) ⇒ RDF::Repository

The RDF::Repository for the named repository

Parameters:

  • name (Symbol)

    The name of the repository

Returns:

  • (RDF::Repository)

See Also:

  • RDF::Repository


81
82
83
# File 'lib/gearbox.rb', line 81

def repository(name)
  repositories[name]
end

.settingsObject

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



40
41
42
# File 'lib/gearbox.rb', line 40

def settings
  Thread.current[:gearbox] ||= {}
end

.type_alias(new, original) ⇒ Void

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

Parameters:

  • new (Any)

    The new symbol or reference

  • original (Any)

    The type the new symbol should refer to

Returns:

  • (Void)


105
106
107
# File 'lib/gearbox.rb', line 105

def type_alias(new, original)
  types[new] = original 
end

.typesHash{Symbol => Gearbox::Type}

The list of all property types available for Gearbox resources

Returns:

See Also:



29
30
31
# File 'lib/gearbox.rb', line 29

def types
  settings[:types] ||= {}
end