Skip to content

Commit

Permalink
Now we can use only mongoid > 3
Browse files Browse the repository at this point in the history
  • Loading branch information
DAddYE committed Aug 20, 2012
1 parent f05a78a commit 78a9b9b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 44 deletions.
47 changes: 5 additions & 42 deletions padrino-gen/lib/padrino-gen/generators/components/orms/mongoid.rb
Original file line number Diff line number Diff line change
@@ -1,58 +1,21 @@
require 'mongoid'

MONGOID = (<<-MONGO) unless defined?(MONGOID)
# Connection.new takes host, port
host = 'localhost'
port = Mongo::Connection::DEFAULT_PORT
MONGOID = (<<-MONGO) unless defined?(MONGOID3)
host = 'localhost'
port = Mongo::Connection::DEFAULT_PORT
database_name = case Padrino.env
when :development then '!NAME!_development'
when :production then '!NAME!_production'
when :test then '!NAME!_test'
end
Mongoid.database = Mongo::Connection.new(host, port).db(database_name)
# You can also configure Mongoid this way
# Mongoid.configure do |config|
# name = @settings["database"]
# host = @settings["host"]
# config.master = Mongo::Connection.new.db(name)
# config.slaves = [
# Mongo::Connection.new(host, @settings["slave_one"]["port"], :slave_ok => true).db(name),
# Mongo::Connection.new(host, @settings["slave_two"]["port"], :slave_ok => true).db(name)
# ]
# end
#
# More installation and setup notes are on http://mongoid.org/docs/
Mongoid::Config.sessions = {default: {hosts: ["#\{host\}:#\{port\}"], database: database_name}}
MONGO

MONGOID3 = (<<-Mv3) unless defined?(MONGOID3) && ::Mongoid::VERSION > '3'
# Connection.new takes host, port
host = 'localhost'
port = Mongo::Connection::DEFAULT_PORT
database_name = case Padrino.env
when :development then '!NAME!_development'
when :production then '!NAME!_production'
when :test then '!NAME!_test'
end
Mongoid::Config.sessions= {default: {hosts: ["#\{host\}:#\{port\}"], database: database_name}}
Mv3

def setup_orm
require_dependencies 'bson_ext'
require_dependencies 'mongo', :require => 'mongo'
require_dependencies 'mongoid'
require_dependencies('SystemTimer', :require => 'system_timer') if RUBY_VERSION =~ /1\.8/ && (!defined?(RUBY_ENGINE) || RUBY_ENGINE == 'ruby')

if ::Mongoid::VERSION > '3'
create_file('config/database.rb', MONGOID3.gsub(/!NAME!/, @app_name.underscore))
else
create_file('config/database.rb', MONGOID.gsub(/!NAME!/, @app_name.underscore))
end
create_file('config/database.rb', MONGOID.gsub(/!NAME!/, @app_name.underscore))
end

MONGOID_MODEL = (<<-MODEL) unless defined?(MONGOID_MODEL)
Expand Down
3 changes: 1 addition & 2 deletions padrino-gen/test/test_project_generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ def teardown
should "output gem files for base app" do
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none') }
assert_match_in_file(/gem 'padrino'/, "#{@apptmp}/sample_project/Gemfile")
assert_match_in_file(/gem 'sinatra-flash'/, "#{@apptmp}/sample_project/Gemfile")
end
end

Expand Down Expand Up @@ -299,7 +298,7 @@ def teardown
assert_match(/applying.*?mongoid.*?orm/, out)
assert_match_in_file(/gem 'mongoid'/, "#{@apptmp}/project.com/Gemfile")
assert_match_in_file(/gem 'bson_ext'/, "#{@apptmp}/project.com/Gemfile")
assert_match_in_file(/Mongoid.database/, "#{@apptmp}/project.com/config/database.rb")
assert_match_in_file(/Mongoid::Config.sessions/, "#{@apptmp}/project.com/config/database.rb")
assert_match_in_file(/project_com/, "#{@apptmp}/project.com/config/database.rb")
end

Expand Down

0 comments on commit 78a9b9b

Please sign in to comment.