Sha256: e11feef3d68d2ddb6a72926e1677b9ee19bd8c449e639a10387eac5f34aeaa8a

Contents?: true

Size: 599 Bytes

Versions: 6

Compression:

Stored size: 599 Bytes

Contents

module Locomotive::Steam
  module Adapters
    module MongoDB

      class Command

        def initialize(collection, mapper)
          @collection = collection
          @mapper     = mapper
        end

        def insert(entity)
          # make sure the entity gets a valid id
          entity[:_id] ||= BSON::ObjectId.new

          serialized_entity = @mapper.serialize(entity)

          @collection.insert(serialized_entity)

          entity
        end

        def delete(entity)
          @collection.find(_id: entity._id).remove if entity._id
        end

      end

    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
locomotivecms_steam-1.0.0.rc3 lib/locomotive/steam/adapters/mongodb/command.rb
locomotivecms_steam-1.0.0.rc2 lib/locomotive/steam/adapters/mongodb/command.rb
locomotivecms_steam-1.0.0.rc1 lib/locomotive/steam/adapters/mongodb/command.rb
locomotivecms_steam-1.0.0.pre.beta.3 lib/locomotive/steam/adapters/mongodb/command.rb
locomotivecms_steam-1.0.0.pre.beta.2 lib/locomotive/steam/adapters/mongodb/command.rb
locomotivecms_steam-1.0.0.pre.beta.1 lib/locomotive/steam/adapters/mongodb/command.rb