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') ⇒ DRbSQLite
constructor
A new instance of DRbSQLite.
- #load(raw_dbfile) ⇒ Object
- #query(*args, &blk) ⇒ Object
Constructor Details
#initialize(raw_dbfile = nil, host: nil, port: '57000') ⇒ DRbSQLite
Returns a new instance of DRbSQLite.
12 13 14 15 16 17 18 |
# File 'lib/drb_sqlite.rb', line 12 def initialize(raw_dbfile=nil, host: nil, port: '57000') DRb.start_service @server = DRbObject.new nil, "druby://#{host}:#{port}" load(raw_dbfile) if raw_dbfile end |
Instance Method Details
#execute(*args, &blk) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/drb_sqlite.rb', line 20 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
31 32 33 |
# File 'lib/drb_sqlite.rb', line 31 def exists?(dbfile) @server.exists? dbfile end |
#load(raw_dbfile) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/drb_sqlite.rb', line 35 def load(raw_dbfile) if raw_dbfile =~ /^sqlite:\/\// then host, @dbfile = raw_dbfile\ .match(/(?<=^sqlite:\/\/)([^\/]+)\/(.*)/).captures else @dbfile = raw_dbfile end @server.load(@dbfile) end |
#query(*args, &blk) ⇒ Object
47 48 49 50 51 52 53 54 55 56 |
# File 'lib/drb_sqlite.rb', line 47 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 |