Skip to content
This repository was archived by the owner on Nov 12, 2019. It is now read-only.

Commit e80fb45

Browse files
committed
Merge pull request #3 from johnnyshields/master
Do not load if ActiveRecord not present. Merged because @seanlinsley has special power over me.
2 parents a0a6a9e + b670542 commit e80fb45

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

lib/polyamorous.rb

+20-19
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,27 @@
11
require "polyamorous/version"
2-
require 'active_record'
32

4-
module Polyamorous
5-
if defined?(::ActiveRecord::Associations::JoinDependency)
6-
JoinDependency = ::ActiveRecord::Associations::JoinDependency
7-
JoinAssociation = ::ActiveRecord::Associations::JoinDependency::JoinAssociation
8-
JoinBase = ::ActiveRecord::Associations::JoinDependency::JoinBase
9-
else
10-
JoinDependency = ::ActiveRecord::Associations::ClassMethods::JoinDependency
11-
JoinAssociation = ::ActiveRecord::Associations::ClassMethods::JoinDependency::JoinAssociation
12-
JoinBase = ::ActiveRecord::Associations::ClassMethods::JoinDependency::JoinBase
3+
if defined?(::ActiveRecord)
4+
module Polyamorous
5+
if defined?(::ActiveRecord::Associations::JoinDependency)
6+
JoinDependency = ::ActiveRecord::Associations::JoinDependency
7+
JoinAssociation = ::ActiveRecord::Associations::JoinDependency::JoinAssociation
8+
JoinBase = ::ActiveRecord::Associations::JoinDependency::JoinBase
9+
else
10+
JoinDependency = ::ActiveRecord::Associations::ClassMethods::JoinDependency
11+
JoinAssociation = ::ActiveRecord::Associations::ClassMethods::JoinDependency::JoinAssociation
12+
JoinBase = ::ActiveRecord::Associations::ClassMethods::JoinDependency::JoinBase
13+
end
1314
end
14-
end
1515

16-
require 'polyamorous/join'
17-
require 'polyamorous/join_association'
18-
require 'polyamorous/join_dependency'
16+
require 'polyamorous/join'
17+
require 'polyamorous/join_association'
18+
require 'polyamorous/join_dependency'
1919

20-
Polyamorous::JoinDependency.send(:include, Polyamorous::JoinDependencyExtensions)
21-
Polyamorous::JoinAssociation.send(:include, Polyamorous::JoinAssociationExtensions)
22-
Polyamorous::JoinBase.class_eval do
23-
if method_defined?(:active_record)
24-
alias_method :base_klass, :active_record
20+
Polyamorous::JoinDependency.send(:include, Polyamorous::JoinDependencyExtensions)
21+
Polyamorous::JoinAssociation.send(:include, Polyamorous::JoinAssociationExtensions)
22+
Polyamorous::JoinBase.class_eval do
23+
if method_defined?(:active_record)
24+
alias_method :base_klass, :active_record
25+
end
2526
end
2627
end

0 commit comments

Comments
 (0)