| Class | Amalgalite::Requires |
| In: |
lib/amalgalite/requires.rb
ext/amalgalite3.c |
| Parent: | Object |
Bootstrapping module to help require when Amalgalite::Requires is not availble in files.
| contents_column | [R] | |
| db_connection | [R] | |
| dbfile_name | [R] | |
| filename_column | [R] | |
| table_name | [R] |
# File lib/amalgalite/requires.rb, line 15
15: def db_connection_to( dbfile_name )
16: unless connection = load_path_db_connections[ dbfile_name ]
17: puts "loading file #{dbfile_name}"
18: connection = ::Amalgalite::Database.new( dbfile_name )
19: load_path_db_connections[dbfile_name] = connection
20: end
21: return connection
22: end
# File lib/amalgalite/requires.rb, line 8
8: def load_path_db_connections
9: @load_path_db_connections ||= {}
10: end
# File lib/amalgalite/requires.rb, line 70
70: def initialize( opts = {} )
71: @dbfile_name = opts[:dbfile_name] || "lib.db"
72: @table_name = opts[:table_name] || "rubylibs"
73: @filename_column = opts[:filename_column] || "filename"
74: @contents_column = opts[:contents_column] || "contents"
75: @db_connection = Requires.db_connection_to( dbfile_name )
76: Requires.load_path << self
77: end
# File lib/amalgalite/requires.rb, line 24
24: def require( filename )
25: load_path.each { |lp| lp.require( filename ) }
26: end
return the files in their dependency order for use for packing into a database
# File lib/amalgalite/requires.rb, line 32
32: def require_order
33: @require_roder ||= %w[
34: amalgalite.rb
35: amalgalite/blob.rb
36: amalgalite/boolean.rb
37: amalgalite/column.rb
38: amalgalite/statement.rb
39: amalgalite/trace_tap.rb
40: amalgalite/profile_tap.rb
41: amalgalite/type_map.rb
42: amalgalite/type_maps/storage_map.rb
43: amalgalite/type_maps/text_map.rb
44: amalgalite/type_maps/default_map.rb
45: amalgalite/database.rb
46: amalgalite/index.rb
47: amalgalite/paths.rb
48: amalgalite/table.rb
49: amalgalite/view.rb
50: amalgalite/schema.rb
51: amalgalite/version.rb
52: amalgalite/sqlite3/version.rb
53: amalgalite/sqlite3/constants.rb
54: amalgalite/sqlite3.rb
55: amalgalite/taps/io.rb
56: amalgalite/taps/console.rb
57: amalgalite/taps.rb
58: amalgalite/core_ext/kernel/require.rb
59: amalgalite/requires.rb
60: ]
61: end
require a file in this database table. This will check and see if the file is already required. If it isn‘t it will select the contents associated with the row identified by the filename and eval those contents within the context of TOPLEVEL_BINDING. The filename is then appended to $".
if the file was required then true is returned, otherwise false
# File lib/amalgalite/requires.rb, line 95
95: def require( filename )
96: if $".include?( filename ) then
97: return false
98: else
99: begin
100: rows = db_connection.execute(sql, filename)
101: row = rows.first
102: eval( row[contents_column].to_s, TOPLEVEL_BINDING)
103: $" << row[filename_column]
104: rescue => e
105: raise LoadError, "Failure loading #{filename} from #{dbfile_name} : #{e}"
106: end
107: end
108: return true
109: end