Skip to content

Commit

Permalink
Adds Mongoid backend for UntiedConsumerSync.
Browse files Browse the repository at this point in the history
  • Loading branch information
julianalucena committed Jan 2, 2013
1 parent f2fc4bc commit 1aa245a
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/untied-consumer-sync-mongoid.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
require "untied-consumer-sync-mongoid/version"
require "untied-consumer-sync-mongoid/backend/mongoid"
require "untied-consumer-sync"

module Untied
module Consumer
module Sync
module Mongoid
# Your code goes here...
end
end
end
Expand Down
26 changes: 26 additions & 0 deletions lib/untied-consumer-sync-mongoid/backend/mongoid.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require "untied-consumer-sync"

module Untied
module Consumer
module Sync
module Backend
module Mongoid
class ModelHelper
include Sync::Backend::Base

# Public: Finds the instance by the id.
#
# id - Integer that identifies the objects according to config file.
#
# Returns the instance (if exists in the database) or nil.
def find(id)
# Used where so no exception will be raised if the instance
# does not exist.
@model.unscoped.where(@model_data['mappings']['id'].to_sym => id).first
end
end
end
end
end
end
end
7 changes: 7 additions & 0 deletions spec/mongoid_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'spec_helper'

module Untied::Consumer::Sync::Backend::Mongoid
describe ModelHelper do
it_behaves_like 'a untied-consumer-sync backend'
end
end

0 comments on commit 1aa245a

Please sign in to comment.