Browse files

Load files with autoload, not explicit require.

  • Loading branch information...
1 parent 5d2fd0e commit 19a552670fb2d99fb4c3876b011f70a6c2c629fe @gkellogg committed Dec 18, 2010
View
68 lib/rdf_context.rb
@@ -16,27 +16,57 @@
require 'treetop'
end
-Dir.glob(File.join(File.dirname(__FILE__), 'rdf_context/*.rb')).sort.each { |f| require f }
-
-# Include Storage types, but be tollerant of failure to load as dependencies might not be available
-Dir.glob(File.join(File.dirname(__FILE__), "rdf_context/store/*.rb")).each do |f|
- begin
- require f
- rescue LoadError
- puts "Error loading #{f}: #{$!}"
- end
-end
-
-# Include Serializer types, but be tollerant of failure to load as dependencies might not be available
-Dir.glob(File.join(File.dirname(__FILE__), "rdf_context/serializer/*.rb")).each do |f|
- begin
- require f
- rescue LoadError
- puts "Error loading #{f}: #{$!}"
- end
-end
+require 'rdf_context/string_hacks'
module RdfContext
+ # Primary model classes
+ autoload :BNode, "rdf_context/bnode"
+ autoload :Duration, "rdf_context/duration"
+ autoload :Literal, "rdf_context/literal"
+ autoload :Namespace, "rdf_context/namespace"
+ autoload :Resource, "rdf_context/resource"
+ autoload :Triple, "rdf_context/triple"
+ autoload :URIRef, "rdf_context/uriref"
+ autoload :TermUtils, "rdf_context/term_utils"
+
+ # Graphs
+ autoload :Graph, "rdf_context/graph"
+ autoload :ConjunctiveGraph, "rdf_context/conjunctive_graph"
+ autoload :AggregateGraph, "rdf_context/aggregate_graph"
+ autoload :QuotedGraph, "rdf_context/quoted_graph"
+
+ # Stores
+ autoload :AbstractStore, "rdf_context/store/abstract_store"
+ autoload :ActiveRecordStore, "rdf_context/store/active_record_store"
+ autoload :ListStore, "rdf_context/store/list_store"
+ autoload :MemoryStore, "rdf_context/store/memory_store"
+ autoload :SQLite3Store, "rdf_context/store/sqlite3_store"
+
+ # Parsers
+ autoload :Parser, "rdf_context/parser"
+ autoload :N3Parser, "rdf_context/n3parser"
+ autoload :RdfaParser, "rdf_context/rdfaparser"
+ autoload :RdfXmlParser, "rdf_context/rdfxmlparser"
+
+ # Serializers
+ autoload :AbstractSerializer, "rdf_context/serializer/abstract_serializer"
+ autoload :NTSerializer, "rdf_context/serializer/nt_serializer"
+ autoload :RecursiveSerializer, "rdf_context/serializer/recursive_serializer"
+ autoload :TurtleSerializer, "rdf_context/serializer/turtle_serializer"
+ autoload :XmlSerializer, "rdf_context/serializer/xml_serializer"
+
+ # Exceptions
+ autoload :BNodeException, "rdf_context/exceptions"
+ autoload :GraphException, "rdf_context/exceptions"
+ autoload :InvalidNode, "rdf_context/exceptions"
+ autoload :InvalidPredicate, "rdf_context/exceptions"
+ autoload :ParserException, "rdf_context/exceptions"
+ autoload :RdfException, "rdf_context/exceptions"
+ autoload :ReadOnlyGraphException, "rdf_context/exceptions"
+ autoload :SparqlException, "rdf_context/exceptions"
+ autoload :StoreException, "rdf_context/exceptions"
+ autoload :TypeError, "rdf_context/exceptions"
+
VERSION = File.read(File.join(File.dirname(__FILE__), "..", "VERSION")).chop # Version in parent directory
LINK_TYPES = %w(
View
2 lib/rdf_context/aggregate_graph.rb
@@ -1,5 +1,3 @@
-require File.join(File.dirname(__FILE__), "graph")
-
module RdfContext
# AggregateGraph - A read-only graph composed of multiple other graphs.
#
View
2 lib/rdf_context/bnode.rb
@@ -1,5 +1,3 @@
-require File.join(File.dirname(__FILE__), "resource")
-
module RdfContext
# The BNode class creates RDF blank nodes.
class BNode < Resource
View
2 lib/rdf_context/conjunctive_graph.rb
@@ -1,5 +1,3 @@
-require File.join(File.dirname(__FILE__), "graph")
-
module RdfContext
# ConjunctiveGraph - The top level container for all named Graphs sharing a _Store_
#
View
8 lib/rdf_context/graph.rb
@@ -1,12 +1,4 @@
-require File.join(File.dirname(__FILE__), "resource")
-require File.join(File.dirname(__FILE__), 'namespace')
-require File.join(File.dirname(__FILE__), 'triple')
require File.join(File.dirname(__FILE__), 'array_hacks')
-require File.join(File.dirname(__FILE__), 'store', 'list_store')
-require File.join(File.dirname(__FILE__), 'store', 'memory_store')
-require File.join(File.dirname(__FILE__), 'serializer', 'nt_serializer')
-require File.join(File.dirname(__FILE__), 'serializer', 'turtle_serializer')
-require File.join(File.dirname(__FILE__), 'serializer', 'xml_serializer')
module RdfContext
# A simple graph to hold triples.
View
6 lib/rdf_context/literal.rb
@@ -4,8 +4,10 @@
rescue LoadError
end
-require File.join(File.dirname(__FILE__), 'duration')
-require File.join(File.dirname(__FILE__), "resource")
+require 'date'
+require 'time'
+
+require File.join(File.dirname(__FILE__), "string_hacks")
module RdfContext
# An RDF Literal, with value, encoding and language elements.
View
2 lib/rdf_context/n3parser.rb
@@ -1,5 +1,5 @@
require 'treetop'
-require File.join(File.dirname(__FILE__), 'parser')
+require File.join(File.dirname(__FILE__), 'array_hacks')
Treetop.load(File.join(File.dirname(__FILE__), "n3_grammar"))
View
2 lib/rdf_context/parser.rb
@@ -1,5 +1,3 @@
-require File.join(File.dirname(__FILE__), 'graph')
-
module RdfContext
# Generic RdfContext Parser class
class Parser
View
2 lib/rdf_context/quoted_graph.rb
@@ -1,5 +1,3 @@
-require File.join(File.dirname(__FILE__), "graph")
-
module RdfContext
# QuotedGraph - Supports N3 Formulae.
#
View
2 lib/rdf_context/rdfaparser.rb
@@ -1,4 +1,4 @@
-require File.join(File.dirname(__FILE__), 'parser')
+require File.join(File.dirname(__FILE__), "nokogiri_hacks")
require 'open-uri'
module RdfContext
View
3 lib/rdf_context/rdfxmlparser.rb
@@ -1,4 +1,5 @@
-require File.join(File.dirname(__FILE__), 'parser')
+require File.join(File.dirname(__FILE__), "nokogiri_hacks")
+require File.join(File.dirname(__FILE__), "string_hacks")
module RdfContext
class RdfXmlParser < Parser
View
3 lib/rdf_context/serializer/recursive_serializer.rb
@@ -1,6 +1,5 @@
require File.join(File.dirname(__FILE__), 'abstract_serializer')
-require File.join(File.dirname(__FILE__), '..', 'bnode')
-require File.join(File.dirname(__FILE__), '..', 'literal')
+require File.join(File.dirname(__FILE__), '..', 'array_hacks')
module RdfContext
# Recursive serializer
View
2 lib/rdf_context/serializer/xml_serializer.rb
@@ -1,4 +1,4 @@
-require File.join(File.dirname(__FILE__), 'abstract_serializer')
+require File.join(File.dirname(__FILE__), 'recursive_serializer')
module RdfContext
# Serialize RDF graphs in NTriples format
View
4 lib/rdf_context/store/abstract_sql_store.rb
@@ -1,7 +1,9 @@
-require File.join(File.dirname(__FILE__), 'abstract_store')
+require File.join(File.dirname(__FILE__), "..", "string_hacks")
require 'digest/sha1'
module RdfContext
+ autoload :AbstractStore, File.join(File.dirname(__FILE__), 'abstract_store')
+
# SQL-92 formula-aware implementation of an RDF Store.
# It stores it's triples in the following partitions:
# - Asserted non rdf:type statements
View
4 lib/rdf_context/store/list_store.rb
@@ -1,6 +1,6 @@
-require File.join(File.dirname(__FILE__), 'abstract_store')
-
module RdfContext
+ autoload :AbstractStore, File.join(File.dirname(__FILE__), 'abstract_store')
+
# List storage, most efficient, but slow storage model. Works well for basic parse and serialize.
class ListStore < AbstractStore
def initialize(identifier = nil, configuration = {})
View
4 lib/rdf_context/store/memory_store.rb
@@ -1,6 +1,6 @@
-require File.join(File.dirname(__FILE__), 'abstract_store')
-
module RdfContext
+ autoload :AbstractStore, File.join(File.dirname(__FILE__), 'abstract_store')
+
# An integer-key-optimized-context-aware-in-memory store.
#
# Uses nested dictionaries to store triples and context. Each triple
View
4 lib/rdf_context/store/sqlite3_store.rb
@@ -1,8 +1,8 @@
gem 'sqlite3-ruby', "=1.2.5" # XXX version 1.3.0 & 1.3.1 break executes with multiple arguments: http://groups.google.com/group/sqlite3-ruby/browse_frm/thread/93494ce04bc07fd5
require 'sqlite3'
-require File.join(File.dirname(__FILE__), 'abstract_sql_store')
module RdfContext
+ autoload :AbstractSQLStore, File.join(File.dirname(__FILE__), 'abstract_sql_store')
# SQLite3 store context-ware and formula-aware implementation.
# It stores it's triples in the following partitions:
# - Asserted non rdf:type statements
@@ -20,7 +20,7 @@ class SQLite3Store < AbstractSQLStore
# @option configuration [String] :connection ActiveRecord::Base.connection.raw_connection
# @return [SQLite3Store]
def initialize(identifier = nil, configuration = {})
- configuration[:path] ||= File.join(Dir.getwd, "#{@internedId}.db")
+ @path = configuration[:path] ||= File.join(Dir.getwd, "#{@internedId}.db")
super(identifier, configuration)
View
4 lib/rdf_context/term_utils.rb
@@ -1,7 +1,3 @@
-require File.join(File.dirname(__FILE__), 'bnode')
-require File.join(File.dirname(__FILE__), 'literal')
-require File.join(File.dirname(__FILE__), 'uriref')
-
module RdfContext
module TermUtils
TERM_INSTANTIATION_DICT = {
View
4 lib/rdf_context/triple.rb
@@ -1,6 +1,4 @@
-require File.join(File.dirname(__FILE__), 'bnode')
-require File.join(File.dirname(__FILE__), 'literal')
-require File.join(File.dirname(__FILE__), 'uriref')
+require 'time'
module RdfContext
# An RDF Triple, or statement.
View
2 lib/rdf_context/uriref.rb
@@ -1,5 +1,5 @@
require 'net/http'
-require File.join(File.dirname(__FILE__), "resource")
+require File.join(File.dirname(__FILE__), "string_hacks")
module RdfContext
class URIRef < Resource
View
1 spec/string_hacks_spec.rb
@@ -1,6 +1,7 @@
# coding: utf-8
$:.unshift "."
require File.join(File.dirname(__FILE__), 'spec_helper')
+require 'rdf_context/string_hacks'
describe String do
{

0 comments on commit 19a5526

Please sign in to comment.