Commit f6206755 authored by Rémy Coutable's avatar Rémy Coutable

Prepend the Prependable module to ActiveSupport::Concern

This is more robust on Ruby 2.1 where we would get the following error:

NoMethodError: super: no superclass method `included' for
EE::Namespace:Module
Signed-off-by: default avatarRémy Coutable <remy@rymai.me>
parent 1473908e
...@@ -2,9 +2,9 @@ module EE ...@@ -2,9 +2,9 @@ module EE
# ApplicationSetting EE mixin # ApplicationSetting EE mixin
# #
# This module is intended to encapsulate EE-specific model logic # This module is intended to encapsulate EE-specific model logic
# and be included in the `ApplicationSetting` model # and be prepended in the `ApplicationSetting` model
module ApplicationSetting module ApplicationSetting
extend ::Prependable extend ActiveSupport::Concern
prepended do prepended do
validates :shared_runners_minutes, validates :shared_runners_minutes,
......
...@@ -2,9 +2,9 @@ module EE ...@@ -2,9 +2,9 @@ module EE
# Namespace EE mixin # Namespace EE mixin
# #
# This module is intended to encapsulate EE-specific model logic # This module is intended to encapsulate EE-specific model logic
# and be included in the `Namespace` model # and be prepended in the `Namespace` model
module Namespace module Namespace
extend ::Prependable extend ActiveSupport::Concern
prepended do prepended do
has_one :namespace_statistics, dependent: :destroy has_one :namespace_statistics, dependent: :destroy
......
...@@ -2,9 +2,9 @@ module EE ...@@ -2,9 +2,9 @@ module EE
# Project EE mixin # Project EE mixin
# #
# This module is intended to encapsulate EE-specific model logic # This module is intended to encapsulate EE-specific model logic
# and be included in the `Project` model # and be prepended in the `Project` model
module Project module Project
extend ::Prependable extend ActiveSupport::Concern
prepended do prepended do
scope :with_shared_runners_limit_enabled, -> { with_shared_runners.non_public_only } scope :with_shared_runners_limit_enabled, -> { with_shared_runners.non_public_only }
......
...@@ -5,7 +5,7 @@ module EE ...@@ -5,7 +5,7 @@ module EE
# This module is intended to encapsulate EE-specific service logic # This module is intended to encapsulate EE-specific service logic
# and be included in the `RegisterBuildService` service # and be included in the `RegisterBuildService` service
module RegisterBuildService module RegisterBuildService
extend ::Prependable extend ActiveSupport::Concern
def builds_for_shared_runner def builds_for_shared_runner
return super unless shared_runner_build_limits_feature_enabled? return super unless shared_runner_build_limits_feature_enabled?
......
# This module is based on: https://gist.github.com/bcardarella/5735987 # This module is based on: https://gist.github.com/bcardarella/5735987
module Prependable module Prependable
include ActiveSupport::Concern
def self.extended(base) #:nodoc:
base.instance_variable_set(:@_dependencies, [])
end
def prepend_features(base) def prepend_features(base)
if base.instance_variable_defined?(:@_dependencies) if base.instance_variable_defined?(:@_dependencies)
base.instance_variable_get(:@_dependencies) << self base.instance_variable_get(:@_dependencies) << self
...@@ -14,11 +8,17 @@ module Prependable ...@@ -14,11 +8,17 @@ module Prependable
else else
return false if base < self return false if base < self
super super
base.singleton_class.send(:prepend, const_get('ClassMethods')) if const_defined?(:ClassMethods) base.singleton_class.send(:prepend, const_get('ClassMethods')) if const_defined?(:ClassMethods)
@_dependencies.each { |dep| base.send(:include, dep) } @_dependencies.each { |dep| base.send(:prepend, dep) }
base.class_eval(&@_included_block) if instance_variable_defined?(:@_included_block) base.class_eval(&@_included_block) if instance_variable_defined?(:@_included_block)
end end
end end
end
module ActiveSupport
module Concern
prepend Prependable
alias_method :prepended, :included alias_method :prepended, :included
end
end end
...@@ -24,7 +24,7 @@ describe Prependable do ...@@ -24,7 +24,7 @@ describe Prependable do
end end
module Foo module Foo
extend Prependable extend ActiveSupport::Concern
prepended do prepended do
def self.class_value def self.class_value
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment