Skip to content

Commit

Permalink
Fix #913: Deferred ORM (ActiveRecord) models loading
Browse files Browse the repository at this point in the history
  • Loading branch information
nbulaj committed Feb 3, 2018
1 parent 384983e commit 9170e5b
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 12 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ User-visible changes worth mentioning.

## master

- [#913] Deferred ORM (ActiveRecord) models loading
- [#943] Fix Access Token token generation when certain errors occur in custom token generators
- [#1026] Implement RFC7662 - OAuth 2.0 Token Introspection
- [#985] Generate valid migration files for Rails >= 5
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[![Dependency Status](https://gemnasium.com/doorkeeper-gem/doorkeeper.svg?travis)](https://gemnasium.com/doorkeeper-gem/doorkeeper)
[![Code Climate](https://codeclimate.com/github/doorkeeper-gem/doorkeeper.svg)](https://codeclimate.com/github/doorkeeper-gem/doorkeeper)
[![Gem Version](https://badge.fury.io/rb/doorkeeper.svg)](https://rubygems.org/gems/doorkeeper)
[![Coverage Status](https://coveralls.io/repos/github/doorkeeper-gem/doorkeeper/badge.svg?branch=master)](https://coveralls.io/github/doorkeeper-gem/doorkeeper?branch=master)
[![Security](https://hakiri.io/github/doorkeeper-gem/doorkeeper/master.svg)](https://hakiri.io/github/doorkeeper-gem/doorkeeper/master)

Doorkeeper is a gem that makes it easy to introduce OAuth 2 provider
Expand Down
2 changes: 1 addition & 1 deletion doorkeeper.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require "doorkeeper/version"

Gem::Specification.new do |s|
s.name = "doorkeeper"
s.version = Doorkeeper::VERSION
s.version = Doorkeeper.gem_version
s.authors = ["Felipe Elias Philipp", "Tute Costa", "Jon Moss"]
s.email = %w([email protected])
s.homepage = "https://github.com/doorkeeper-gem/doorkeeper"
Expand Down
27 changes: 19 additions & 8 deletions lib/doorkeeper/orm/active_record.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,33 @@
require 'active_support/lazy_load_hooks'

module Doorkeeper
module Orm
module ActiveRecord
def self.initialize_models!
require 'doorkeeper/orm/active_record/access_grant'
require 'doorkeeper/orm/active_record/access_token'
require 'doorkeeper/orm/active_record/application'
lazy_load do
require 'doorkeeper/orm/active_record/access_grant'
require 'doorkeeper/orm/active_record/access_token'
require 'doorkeeper/orm/active_record/application'

if Doorkeeper.configuration.active_record_options[:establish_connection]
[Doorkeeper::AccessGrant, Doorkeeper::AccessToken, Doorkeeper::Application].each do |c|
c.send :establish_connection, Doorkeeper.configuration.active_record_options[:establish_connection]
if Doorkeeper.configuration.active_record_options[:establish_connection]
[Doorkeeper::AccessGrant, Doorkeeper::AccessToken, Doorkeeper::Application].each do |c|
options = Doorkeeper.configuration.active_record_options[:establish_connection]
c.send :establish_connection, options
end
end
end
end

def self.initialize_application_owner!
require 'doorkeeper/models/concerns/ownership'
lazy_load do
require 'doorkeeper/models/concerns/ownership'

Doorkeeper::Application.send :include, Doorkeeper::Models::Ownership
end
end

Doorkeeper::Application.send :include, Doorkeeper::Models::Ownership
def self.lazy_load(&block)
ActiveSupport.on_load(:active_record, {}, &block)
end
end
end
Expand Down
14 changes: 13 additions & 1 deletion lib/doorkeeper/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
module Doorkeeper
VERSION = "4.2.6".freeze
def self.gem_version
Gem::Version.new VERSION::STRING
end

module VERSION
# Semantic versioning
MAJOR = 4
MINOR = 2
TINY = 6

# Full version number
STRING = [MAJOR, MINOR, TINY].compact.join('.')
end
end
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Require `belongs_to` associations by default. This is a new Rails 5.0
# default, so it is introduced as a configuration option to ensure that apps
# made on earlier versions of Rails are not affected when upgrading.
if Rails.version.to_i >= 5
if Rails::VERSION::MAJOR >= 5
Rails.application.config.active_record.belongs_to_required_by_default = true
end
7 changes: 6 additions & 1 deletion spec/spec_helper_integration.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
if ENV['TRAVIS']
require 'coveralls'
Coveralls.wear!('rails') { add_filter('/spec/') }

Coveralls.wear!('rails') do
add_filter('/spec/')
add_filter('/lib/generators/doorkeeper/templates/')
add_filter('/lib/version')
end
end

ENV['RAILS_ENV'] ||= 'test'
Expand Down

0 comments on commit 9170e5b

Please sign in to comment.