Module: RethinkDBJob::Setup

Included in:
RethinkDBJob
Defined in:
lib/rethinkdb_job/setup.rb

Instance Method Summary collapse

Instance Method Details

#databaseObject



7
8
9
10
11
12
13
14
15
# File 'lib/rethinkdb_job/setup.rb', line 7

def database
  # ugly hack until @rdb.default_db works properly
  db = rdb.instance_variable_get("@default_opts")[:db]
  if db
    rql_db_string(db)
  else
    @rdb_config[:db] || "test"
  end
end

#done_setup?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/rethinkdb_job/setup.rb', line 17

def done_setup?
  @done_setup
end

#ensure_setupObject



21
22
23
24
25
26
# File 'lib/rethinkdb_job/setup.rb', line 21

def ensure_setup
  unless done_setup?
    setup
    @done_setup = true
  end
end

#rql_db_string(rql_db) ⇒ Object



3
4
5
# File 'lib/rethinkdb_job/setup.rb', line 3

def rql_db_string(rql_db)
  rql_db.instance_variable_get("@body")[1].first
end

#setupObject



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rethinkdb_job/setup.rb', line 28

def setup
  begin
    rdb
  rescue => e
    msg = "cannot connect to RethinkDB #{@rdb_config.inspect}"
    raise e.class, e.message + ", #{msg}", caller
  end

  begin
    r.db_create(database).run(rdb)
  rescue RethinkDB::RqlRuntimeError => err
    # already exists, cool
  rescue => e
    msg = "cannot create db #{database.inspect}"
    raise e.class, e.message + ", #{msg}", caller
  end

  begin
    r.db(database).table_create(table).run(rdb)
  rescue RethinkDB::RqlRuntimeError => err
    # already exists, cool
  rescue => e
    msg = "cannot create table #{table.inspect} on database #{database.inspect}"
    raise e.class, e.message + ", #{msg}", caller
  end
end