mongar
!! This is still fresh off the oven and hasn’t been thoroughly tested yet in production. !!
Ruby GEM to facilitate replicating data from ActiveRecord (or any data represented by a set of Ruby classes) to MongoDB.
Adding to a rails project
Put your Mongar config into config/mongar.rb (See Example Config below)
Put the following code into script/mongar.rb
require 'mongar'
mongar_config = File.join(Rails.root, 'config', 'mongar.rb')
mongar = eval(File.read(mongar_config))
mongar.run
Run it with rails runner (rails 3.x) or script/runner (rails 2.x) script/mongar.rb
Example Config
Mongar.configure do
log_level :debug
mongo :default do
database 'mydb'
user 'mongouser'
password 'password'
host '127.0.0.1'
port 27017
end
mongo :otherdb do
database 'mydb'
user 'mongouser'
password 'password'
status_collection :statuses
end
replicate Domain => 'domains' do
use_mongodb :otherdb
full_refresh :every => 60.minutes
column :uri do
primary_index
transform :downcase
end
column :allow_anyone_to_anyone_policy
end
replicate Client do
db_time_selector do
current_time_on_db_server
end
column :id do
primary_index
end
column :name
column :employee_count do
transform do |value|
value.nil? ? 0 : value
end
end
end
replicate EmailAddress do
no_deleted_finder
set_updated_finder do |last_replicated_date|
find(:all, :conditions => ['something > ?', last_replicated_date])
end
set_created_finder do |last_replicated_date|
created_scope(last_replicated_date)
end
full_refresh :if => Proc.new do |last_replicated_date|
# class eval'ed code
any_changes_since?(last_replicated_date)
end
column :address
end
end
Contributing to mongar
Find this project on Pivotal Tracker here: www.pivotaltracker.com/projects/434475
-
Check out the latest master to make sure the feature hasn’t been implemented or the bug hasn’t been fixed yet
-
Check out the issue tracker to make sure someone already hasn’t requested it and/or contributed it
-
Fork the project
-
Start a feature/bugfix branch
-
Commit and push until you are happy with your contribution
-
Make sure to add tests for it. This is important so I don’t break it in a future version unintentionally.
-
Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
Copyright
Copyright © 2011 Greenview Data, Inc. See LICENSE.txt for further details.