module Seam::Mongodb
Constants
- VERSION
Public Class Methods
all()
click to toggle source
# File lib/seam/mongodb.rb, line 68 def self.all Seam::Mongodb.collection.find.to_a end
collection()
click to toggle source
# File lib/seam/mongodb.rb, line 9 def self.collection @collection end
create(effort)
click to toggle source
# File lib/seam/mongodb.rb, line 64 def self.create effort Seam::Mongodb.collection.insert(effort.to_hash) end
destroy()
click to toggle source
# File lib/seam/mongodb.rb, line 72 def self.destroy Seam::Mongodb.collection.drop end
find_all_pending_executions_by_step(step)
click to toggle source
# File lib/seam/mongodb.rb, line 26 def self.find_all_pending_executions_by_step step Seam::Mongodb.collection .find( { next_step: step, next_execute_at: { '$lte' => Time.now } } ) .select( { '_id' => 1 } ) .map do |x| -> do record = Seam::Mongodb.collection.find( { '_id' => x['_id'] } ).first Seam::Effort.parse record end.to_object end end
find_by_effort_id(effort_id)
click to toggle source
# File lib/seam/mongodb.rb, line 20 def self.find_by_effort_id effort_id document = Seam::Mongodb.collection.find( { id: effort_id } ).first return nil unless document Seam::Effort.parse document end
find_something_to_do()
click to toggle source
# File lib/seam/mongodb.rb, line 41 def self.find_something_to_do record = Seam::Mongodb.collection .find( { next_execute_at: { '$lte' => Time.now }, next_step: { '$ne' => nil }, complete: { '$in' => [nil, false] }, } ) .first return [] unless record [record].map do |x| -> do record = Seam::Mongodb.collection.find( { '_id' => x['_id'] } ).first Seam::Effort.parse record end.to_object end end
overwrite_the_persistence_layer()
click to toggle source
# File lib/seam/mongodb.rb, line 18 def self.overwrite_the_persistence_layer Seam::Persistence.class_eval do def self.find_by_effort_id effort_id document = Seam::Mongodb.collection.find( { id: effort_id } ).first return nil unless document Seam::Effort.parse document end def self.find_all_pending_executions_by_step step Seam::Mongodb.collection .find( { next_step: step, next_execute_at: { '$lte' => Time.now } } ) .select( { '_id' => 1 } ) .map do |x| -> do record = Seam::Mongodb.collection.find( { '_id' => x['_id'] } ).first Seam::Effort.parse record end.to_object end end def self.find_something_to_do record = Seam::Mongodb.collection .find( { next_execute_at: { '$lte' => Time.now }, next_step: { '$ne' => nil }, complete: { '$in' => [nil, false] }, } ) .first return [] unless record [record].map do |x| -> do record = Seam::Mongodb.collection.find( { '_id' => x['_id'] } ).first Seam::Effort.parse record end.to_object end end def self.save effort Seam::Mongodb.collection .find( { id: effort.id } ) .update("$set" => effort.to_hash) end def self.create effort Seam::Mongodb.collection.insert(effort.to_hash) end def self.all Seam::Mongodb.collection.find.to_a end def self.destroy Seam::Mongodb.collection.drop end end end
save(effort)
click to toggle source
# File lib/seam/mongodb.rb, line 58 def self.save effort Seam::Mongodb.collection .find( { id: effort.id } ) .update("$set" => effort.to_hash) end
set_collection(collection)
click to toggle source
# File lib/seam/mongodb.rb, line 13 def self.set_collection collection @collection = collection overwrite_the_persistence_layer end