mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Refactor AS concern to avoid hacking the "include" method.
Ruby Magic!
This commit is contained in:
parent
7b169ed1bb
commit
7ec947d59c
3 changed files with 10 additions and 24 deletions
|
@ -7,7 +7,6 @@ module ActiveSupport
|
|||
autoload :Callbacks, 'active_support/callbacks'
|
||||
autoload :Concern, 'active_support/concern'
|
||||
autoload :ConcurrentHash, 'active_support/concurrent_hash'
|
||||
autoload :DependencyModule, 'active_support/dependency_module'
|
||||
autoload :DeprecatedCallbacks, 'active_support/deprecated_callbacks'
|
||||
autoload :Deprecation, 'active_support/deprecation'
|
||||
autoload :Gzip, 'active_support/gzip'
|
||||
|
|
|
@ -1,11 +1,17 @@
|
|||
require 'active_support/dependency_module'
|
||||
|
||||
module ActiveSupport
|
||||
module Concern
|
||||
include DependencyModule
|
||||
def self.extended(base)
|
||||
base.instance_variable_set("@_dependencies", [])
|
||||
end
|
||||
|
||||
def append_features(base)
|
||||
if super
|
||||
if base.instance_variable_defined?("@_dependencies")
|
||||
base.instance_variable_get("@_dependencies") << self
|
||||
return false
|
||||
else
|
||||
return false if base < self
|
||||
@_dependencies.each { |dep| base.send(:include, dep) }
|
||||
super
|
||||
base.extend const_get("ClassMethods") if const_defined?("ClassMethods")
|
||||
base.send :include, const_get("InstanceMethods") if const_defined?("InstanceMethods")
|
||||
base.class_eval(&@_included_block) if instance_variable_defined?("@_included_block")
|
||||
|
@ -19,7 +25,5 @@ module ActiveSupport
|
|||
super
|
||||
end
|
||||
end
|
||||
|
||||
alias_method :include, :depends_on
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,17 +0,0 @@
|
|||
module ActiveSupport
|
||||
module DependencyModule
|
||||
def append_features(base)
|
||||
return false if base < self
|
||||
(@_dependencies ||= []).each { |dep| base.send(:include, dep) }
|
||||
super
|
||||
end
|
||||
|
||||
def depends_on(*mods)
|
||||
mods.each do |mod|
|
||||
next if self < mod
|
||||
@_dependencies ||= []
|
||||
@_dependencies << mod
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue