summaryrefslogtreecommitdiff
path: root/lib/gitlab/patch
diff options
context:
space:
mode:
authorLin Jen-Shin <godfat@godfat.org>2018-08-31 00:25:17 +0800
committerLin Jen-Shin <godfat@godfat.org>2018-09-11 18:45:49 +0800
commit07da8f9128f507bb20d5694c1c0b5ca73e58d203 (patch)
tree02d55edafb3c40b056b1857804008dffba8b8672 /lib/gitlab/patch
parentd7f87a2bc9b9638285eb85b50957879c8599a6b9 (diff)
downloadgitlab-ce-07da8f9128f507bb20d5694c1c0b5ca73e58d203.tar.gz
Preserve prepend semantics for Ruby
However we still want to make ClassMethods work! And we'll need to fix codes using the wrong include/prepend along the way. There were a lot of misuses.
Diffstat (limited to 'lib/gitlab/patch')
-rw-r--r--lib/gitlab/patch/prependable.rb48
1 files changed, 17 insertions, 31 deletions
diff --git a/lib/gitlab/patch/prependable.rb b/lib/gitlab/patch/prependable.rb
index 45fac0ed4a7..617c6eeacd2 100644
--- a/lib/gitlab/patch/prependable.rb
+++ b/lib/gitlab/patch/prependable.rb
@@ -10,42 +10,29 @@ module Gitlab
end
end
- module MetaConcern
- def extended(base)
- super
- base.instance_variable_set(:@_prepend_dependencies, [])
- end
- end
-
- def self.prepended(base)
- super
- base.singleton_class.prepend MetaConcern
- end
+ def prepend_features(base)
+ return false if prepended?(base)
- def append_features(base)
super
- prepend_features(base)
- end
-
- def prepend_features(base)
- if base.instance_variable_defined?(:@_prepend_dependencies)
- base.instance_variable_get(:@_prepend_dependencies) << self
- false
- else
- return false if prepended?(base)
+ if const_defined?(:ClassMethods)
+ klass_methods = const_get(:ClassMethods)
+ base.singleton_class.prepend klass_methods
+ base.instance_variable_set(:@_prepended_class_methods, klass_methods)
+ end
- @_prepend_dependencies.each { |dep| base.prepend(dep) }
+ if instance_variable_defined?(:@_prepended_block)
+ base.class_eval(&@_prepended_block)
+ end
- super
+ true
+ end
- if const_defined?(:ClassMethods)
- base.singleton_class.prepend const_get(:ClassMethods)
- end
+ def class_methods
+ super
- if instance_variable_defined?(:@_prepended_block)
- base.class_eval(&@_prepended_block)
- end
+ if instance_variable_defined?(:@_prepended_class_methods)
+ const_get(:ClassMethods).prepend @_prepended_class_methods
end
end
@@ -63,8 +50,7 @@ module Gitlab
def prepended?(base)
index = base.ancestors.index(base)
- @_prepend_dependencies.index(self) ||
- base.ancestors[0...index].index(self)
+ base.ancestors[0...index].index(self)
end
end
end