Permalink
Browse files

Now work with Mongoid 2.x and 3.x fix #881

  • Loading branch information...
WaYdotNET committed Jul 18, 2012
1 parent 4e87332 commit 263b3edd913943e10640cf22ebdad3a25ce025b2
@@ -27,7 +27,11 @@ class <%= @model_name %>
# This method is for authentication purpose
#
def self.authenticate(email, password)
<%- if ::Mongoid::VERSION > '3'-%>
account = where(email: email).first if email.present?
<%- else -%>
account = first(:conditions => { :email => email }) if email.present?
<%- end -%>
account && account.has_password?(password) ? account : nil
end
@@ -1,5 +1,6 @@
MONGOID = (<<-MONGO) unless defined?(MONGOID)
require 'mongoid'
MONGOID = (<<-MONGO) unless defined?(MONGOID)
# Connection.new takes host, port
host = 'localhost'
port = Mongo::Connection::DEFAULT_PORT
@@ -25,12 +26,38 @@
#
# More installation and setup notes are on http://mongoid.org/docs/
MONGO
MONGOID_V3 = (<<-MONGO3) unless defined?(MONGOID_V3) && ::Mongoid::VERSION < '3'
development:
sessions:
default:
database: !NAME!_development
hosts:
- localhost:27017
production:
sessions:
default:
database: !NAME!_production
hosts:
- localhost:27017
test:
sessions:
default:
database: !NAME!_test
hosts:
- localhost:27017
MONGO3
def setup_orm
require_dependencies 'bson_ext', :require => 'mongo'
require_dependencies 'bson_ext' #, :require => 'mongo'
require_dependencies 'mongoid'
require_dependencies('SystemTimer', :require => 'system_timer') if RUBY_VERSION =~ /1\.8/ && (!defined?(RUBY_ENGINE) || RUBY_ENGINE == 'ruby')
create_file("config/database.rb", MONGOID.gsub(/!NAME!/, @app_name.underscore))
if ::Mongoid::VERSION > '3'
create_file('config/database.yml', MONGOID_V3.gsub(/!NAME!/, @app_name.underscore))
inject_into_file destination_root('config/boot.rb'), " Mongoid.load!(File.join(Padrino.root,'config/database.yml'),\"#{@app_name.underscore}_\#{PADRINO_ENV\}\")\n", :after => "Padrino.before_load do\n"
else
create_file('config/database.rb', MONGOID.gsub(/!NAME!/, @app_name.underscore))
end
end
MONGOID_MODEL = (<<-MODEL) unless defined?(MONGOID_MODEL)

0 comments on commit 263b3ed

Please sign in to comment.