Module: Seam::Mongodb

Defined in:
lib/seam/mongodb.rb,
lib/seam/mongodb/version.rb

Constant Summary collapse

VERSION =
"0.0.4"

Class Method Summary collapse

Class Method Details

.collectionObject



9
10
11
# File 'lib/seam/mongodb.rb', line 9

def self.collection
  @collection
end

.overwrite_the_persistence_layerObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# 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.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

.set_collection(collection) ⇒ Object



13
14
15
16
# File 'lib/seam/mongodb.rb', line 13

def self.set_collection collection
  @collection = collection
  overwrite_the_persistence_layer
end