Skip to content

Instantly share code, notes, and snippets.

@bcardarella
Last active September 5, 2019 16:06
Show Gist options
  • Save bcardarella/5735987 to your computer and use it in GitHub Desktop.
Save bcardarella/5735987 to your computer and use it in GitHub Desktop.
module ActiveSupport::Concern
def append_features(base)
if base.instance_variable_defined?("@_dependencies")
base.instance_variable_get("@_dependencies") << { :module => self, :method => :include }
return false
else
return false if base < self
@_dependencies.each { |dep| base.send(dep[:method], dep[:module]) }
super
base.extend const_get("ClassMethods") if const_defined?("ClassMethods")
base.class_eval(&@_included_block) if instance_variable_defined?("@_included_block")
end
end
def prepend_features(base)
if base.instance_variable_defined?("@_dependencies")
base.instance_variable_get("@_dependencies").unshift({ :module => self, :method => :prepend })
return false
else
return false if base < self
super
base.singleton_class.send(:prepend, const_get('ClassMethods'))
@_dependencies.each { |dep| base.send(dep[:method], dep[:module]) }
base.class_eval(&@_included_block) if instance_variable_defined?("@_included_block")
end
end
alias_method :prepended, :included
end
@Qqwy
Copy link

Qqwy commented Sep 5, 2019

I believe that the slightly different version that is part of easy_auth still works correctly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment