Skip to content

Commit

Permalink
not loading ORM class in enable_orm function
Browse files Browse the repository at this point in the history
  • Loading branch information
jasl authored and tute committed Oct 11, 2014
1 parent c5a8cb9 commit 56e3296
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
2 changes: 2 additions & 0 deletions lib/doorkeeper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
require 'doorkeeper/rails/routes'
require 'doorkeeper/rails/helpers'

require 'doorkeeper/orm/active_record'

module Doorkeeper
def self.configured?
@config.present?
Expand Down
15 changes: 11 additions & 4 deletions lib/doorkeeper/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,17 @@ def self.configuration

def self.enable_orm
# using Orm namespace to prevent some class finding problem
require "doorkeeper/orm/#{configuration.orm}"
"doorkeeper/orm/#{configuration.orm}".classify.constantize.initialize_models!
rescue LoadError => e
fail e, "Doorkeeper: ORM adapter not found (#{configuration.orm}). You probably need to add the related gem."
class_name = "doorkeeper/orm/#{configuration.orm}".classify
class_name.constantize.initialize_models!
rescue NameError => e
# `constantize` should raise NameError,
# message is like `NameError: uninitialized constant Doorkeeper::Orm::Mongoid4`
# make sure only rescue this error(NoMethodError is a subclass of NameError, we won't catch that).
if e.message.include? class_name
fail e, "Doorkeeper: ORM adapter not found (#{configuration.orm}). You probably need to add the related gem."
else
raise e
end
end

def self.setup_application_owner
Expand Down

0 comments on commit 56e3296

Please sign in to comment.