class TwistlockControl::RethinkDBRepository
Some helper functions around access to RethinkDB collections
Attributes
table_name[RW]
Public Class Methods
[](table_name)
click to toggle source
# File lib/twistlock_control/rethinkdb_repository.rb, line 4 def self.[](table_name) new(table_name) end
new(table_name)
click to toggle source
# File lib/twistlock_control/rethinkdb_repository.rb, line 8 def initialize(table_name) @table_name = table_name end
Public Instance Methods
all()
click to toggle source
# File lib/twistlock_control/rethinkdb_repository.rb, line 48 def all with_connection do |conn| table.run(conn) end end
create_table()
click to toggle source
# File lib/twistlock_control/rethinkdb_repository.rb, line 60 def create_table with_connection do |conn| TwistlockControl.database.table_create(table_name).run(conn) end rescue RethinkDB::RqlRuntimeError nil end
delete_all()
click to toggle source
# File lib/twistlock_control/rethinkdb_repository.rb, line 68 def delete_all with_connection do |conn| table.delete.run(conn) end end
find_by_attributes(attrs)
click to toggle source
# File lib/twistlock_control/rethinkdb_repository.rb, line 30 def find_by_attributes(attrs) with_connection do |conn| table.filter(attrs).limit(1).run(conn).first end end
find_by_id(id)
click to toggle source
# File lib/twistlock_control/rethinkdb_repository.rb, line 24 def find_by_id(id) with_connection do |conn| table.get(id).run(conn) end end
find_with_ids(ids)
click to toggle source
# File lib/twistlock_control/rethinkdb_repository.rb, line 36 def find_with_ids(ids) with_connection do |conn| table.get_all(*ids).run(conn) end end
remove(id)
click to toggle source
# File lib/twistlock_control/rethinkdb_repository.rb, line 42 def remove(id) with_connection do |conn| table.get(id).delete.run(conn) end end
save(attributes)
click to toggle source
# File lib/twistlock_control/rethinkdb_repository.rb, line 18 def save(attributes) with_connection do |conn| table.get(attributes[:id]).replace(attributes).run(conn) end end
table()
click to toggle source
# File lib/twistlock_control/rethinkdb_repository.rb, line 14 def table TwistlockControl.database.table(table_name) end
with_connection() { |conn| ... }
click to toggle source
# File lib/twistlock_control/rethinkdb_repository.rb, line 54 def with_connection TwistlockControl.with_connection do |conn| yield conn end end