Class: DRbSQLite
- Inherits:
-
Object
- Object
- DRbSQLite
- Defined in:
- lib/drb_sqlite.rb
Instance Method Summary collapse
- #execute(*args, &blk) ⇒ Object
- #exists?(dbfile) ⇒ Boolean
-
#initialize(raw_dbfile = nil, host: nil, port: '57000', debug: false) ⇒ DRbSQLite
constructor
A new instance of DRbSQLite.
- #load_db(raw_dbfile) ⇒ Object
- #query(*args, &blk) ⇒ Object
Constructor Details
#initialize(raw_dbfile = nil, host: nil, port: '57000', debug: false) ⇒ DRbSQLite
Returns a new instance of DRbSQLite.
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/drb_sqlite.rb', line 15 def initialize(raw_dbfile=nil, host: nil, port: '57000', debug: false) @host, @port, @debug = host, port, debug puts 'inside DRbSQLite'.info if @debug DRb.start_service if raw_dbfile then load_db(raw_dbfile) else @server = DRbObject.new nil, "druby://#{host}:#{port}" end end |
Instance Method Details
#execute(*args, &blk) ⇒ Object
32 33 34 35 36 37 38 39 40 41 |
# File 'lib/drb_sqlite.rb', line 32 def execute(*args, &blk) r = @server.execute @dbfile, *args, &blk if r.is_a? String and r =~ /^SQLiteServerError:/ then raise SQLiteServerError, r[/(?<=^SQLiteServerError: )(.*)/] end r end |
#exists?(dbfile) ⇒ Boolean
43 44 45 |
# File 'lib/drb_sqlite.rb', line 43 def exists?(dbfile) @server.exists? dbfile end |
#load_db(raw_dbfile) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/drb_sqlite.rb', line 47 def load_db(raw_dbfile) puts 'DRbSQLite | inside load_db'.info if @debug if raw_dbfile =~ /^sqlite:\/\// then host, @dbfile = raw_dbfile\ .match(/(?<=^sqlite:\/\/)([^\/]+)\/(.*)/).captures if @debug then puts ('host: ' + host.inspect).debug puts ('@dbfile: ' + @dbfile.inspect).debug end @server = DRbObject.new nil, "druby://#{host}:#{@port}" else @dbfile = raw_dbfile @server = DRbObject.new nil, "druby://#{@host}:#{@port}" end @server.load_db(@dbfile) end |
#query(*args, &blk) ⇒ Object
69 70 71 72 73 74 75 76 77 78 |
# File 'lib/drb_sqlite.rb', line 69 def query(*args, &blk) r = @server.query @dbfile, *args, &blk if r.is_a? String and r =~ /^SQLiteServerError:/ then raise SQLiteServerError, r[/(?<=^SQLiteServerError: )(.*)/] end r end |