Class: Lab::Lims::Api::CouchDbApi
- Inherits:
-
Object
- Object
- Lab::Lims::Api::CouchDbApi
- Defined in:
- app/services/lab/lims/api/couchdb_api.rb
Overview
Talk to LIMS like a boss
Direct Known Subclasses
Instance Attribute Summary collapse
-
#bum ⇒ Object
readonly
Returns the value of attribute bum.
Instance Method Summary collapse
-
#consume_orders(from: 0, limit: 30) ⇒ Object
Consume orders from the LIMS queue.
- #create_order(order) ⇒ Object
-
#initialize(config: nil) ⇒ CouchDbApi
constructor
A new instance of CouchDbApi.
- #update_order(id, order) ⇒ Object
Constructor Details
#initialize(config: nil) ⇒ CouchDbApi
Returns a new instance of CouchDbApi.
15 16 17 18 19 20 21 22 23 24 |
# File 'app/services/lab/lims/api/couchdb_api.rb', line 15 def initialize(config: nil) config ||= Config.couchdb @bum = CouchBum.new(protocol: config['protocol'], host: config['host'], port: config['port'], database: "#{config['prefix']}_order_#{config['suffix']}", username: config['username'], password: config['password']) end |
Instance Attribute Details
#bum ⇒ Object (readonly)
Returns the value of attribute bum.
13 14 15 |
# File 'app/services/lab/lims/api/couchdb_api.rb', line 13 def bum @bum end |
Instance Method Details
#consume_orders(from: 0, limit: 30) ⇒ Object
Consume orders from the LIMS queue.
Retrieves orders from the LIMS queue and passes each order to given block until the queue is empty or connection is terminated by calling method choke
.
32 33 34 35 36 37 38 |
# File 'app/services/lab/lims/api/couchdb_api.rb', line 32 def consume_orders(from: 0, limit: 30) bum.binge_changes(since: from, limit: limit, include_docs: true) do |change| next unless change['doc']['type']&.casecmp?('Order') yield OrderDTO.new(change['doc']), self end end |
#create_order(order) ⇒ Object
40 41 42 43 44 45 |
# File 'app/services/lab/lims/api/couchdb_api.rb', line 40 def create_order(order) order = order.dup order.delete('_id') bum.couch_rest :post, '/', order end |
#update_order(id, order) ⇒ Object
47 48 49 |
# File 'app/services/lab/lims/api/couchdb_api.rb', line 47 def update_order(id, order) bum.couch_rest :put, "/#{id}", order end |