Class: TwistlockControl::RethinkDBRepository
- Inherits:
-
Object
- Object
- TwistlockControl::RethinkDBRepository
- Defined in:
- lib/twistlock_control/rethinkdb_repository.rb
Overview
Some helper functions around access to RethinkDB collections
Instance Attribute Summary collapse
-
#table_name ⇒ Object
Returns the value of attribute table_name.
Class Method Summary collapse
Instance Method Summary collapse
- #all ⇒ Object
- #create_table ⇒ Object
- #delete_all ⇒ Object
- #find_by_attributes(attrs) ⇒ Object
- #find_by_id(id) ⇒ Object
- #find_with_ids(ids) ⇒ Object
-
#initialize(table_name) ⇒ RethinkDBRepository
constructor
A new instance of RethinkDBRepository.
- #remove(id) ⇒ Object
- #save(attributes) ⇒ Object
- #table ⇒ Object
- #with_connection ⇒ Object
Constructor Details
#initialize(table_name) ⇒ RethinkDBRepository
Returns a new instance of RethinkDBRepository.
8 9 10 |
# File 'lib/twistlock_control/rethinkdb_repository.rb', line 8 def initialize(table_name) @table_name = table_name end |
Instance Attribute Details
#table_name ⇒ Object
Returns the value of attribute table_name.
12 13 14 |
# File 'lib/twistlock_control/rethinkdb_repository.rb', line 12 def table_name @table_name end |
Class Method Details
.[](table_name) ⇒ Object
4 5 6 |
# File 'lib/twistlock_control/rethinkdb_repository.rb', line 4 def self.[](table_name) new(table_name) end |
Instance Method Details
#all ⇒ Object
48 49 50 51 52 |
# File 'lib/twistlock_control/rethinkdb_repository.rb', line 48 def all with_connection do |conn| table.run(conn) end end |
#create_table ⇒ Object
60 61 62 63 64 65 66 |
# 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 ⇒ Object
68 69 70 71 72 |
# 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) ⇒ Object
30 31 32 33 34 |
# 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) ⇒ Object
24 25 26 27 28 |
# 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) ⇒ Object
36 37 38 39 40 |
# 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) ⇒ Object
42 43 44 45 46 |
# 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) ⇒ Object
18 19 20 21 22 |
# 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 ⇒ Object
14 15 16 |
# File 'lib/twistlock_control/rethinkdb_repository.rb', line 14 def table TwistlockControl.database.table(table_name) end |
#with_connection ⇒ Object
54 55 56 57 58 |
# File 'lib/twistlock_control/rethinkdb_repository.rb', line 54 def with_connection TwistlockControl.with_connection do |conn| yield conn end end |