Module: NoBrainer::RQL

Extended by:
RQL
Includes:
RethinkDB::Term::TermType
Included in:
RQL
Defined in:
lib/no_brainer/rql.rb

Instance Method Summary collapse

Instance Method Details

#db_drop?(rql) ⇒ Boolean

Returns:



24
25
26
# File 'lib/no_brainer/rql.rb', line 24

def db_drop?(rql)
  get_rql_statement(rql) == DB_DROP
end

#get_rql_statement(rql) ⇒ Object



20
21
22
# File 'lib/no_brainer/rql.rb', line 20

def get_rql_statement(rql)
  rql.is_a?(RethinkDB::RQL) && rql.body.is_a?(Array) && rql.body.first
end

#is_write_query?(rql) ⇒ Boolean

Returns:



16
17
18
# File 'lib/no_brainer/rql.rb', line 16

def is_write_query?(rql)
  type_of(rql) == :write
end

#reset_lambda_var_counterObject



5
6
7
# File 'lib/no_brainer/rql.rb', line 5

def reset_lambda_var_counter
  RethinkDB::RQL.class_variable_set(:@@gensym_cnt, 0)
end

#rql_proc_as_json(block) ⇒ Object



9
10
11
12
13
14
# File 'lib/no_brainer/rql.rb', line 9

def rql_proc_as_json(block)
  reset_lambda_var_counter
  RethinkDB::Shim.load_json(
    RethinkDB::Shim.dump_json(
      RethinkDB::RQL.new.new_func(&block)))
end

#type_of(rql) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/no_brainer/rql.rb', line 28

def type_of(rql)
  case get_rql_statement(rql)
  when UPDATE, DELETE, REPLACE, INSERT
    :write
  when DB_CREATE, DB_DROP, DB_LIST, TABLE_CREATE, TABLE_DROP, TABLE_LIST,
       INDEX_CREATE, INDEX_DROP, INDEX_LIST, INDEX_STATUS, INDEX_WAIT, INDEX_RENAME,
       CONFIG, STATUS, WAIT, RECONFIGURE, REBALANCE, SYNC
    :management
  else
    # XXX Not necessarily correct, but we'll be happy for logging colors.
    :read
  end
end