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
# ApplicationSetting EE mixin
#
# 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
extend ::Prependable
extend ActiveSupport::Concern
prepended do
validates :shared_runners_minutes,
......
......@@ -2,9 +2,9 @@ module EE
# Namespace EE mixin
#
# 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
extend ::Prependable
extend ActiveSupport::Concern
prepended do
has_one :namespace_statistics, dependent: :destroy
......
......@@ -2,9 +2,9 @@ module EE
# Project EE mixin
#
# 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
extend ::Prependable
extend ActiveSupport::Concern
prepended do
scope :with_shared_runners_limit_enabled, -> { with_shared_runners.non_public_only }
......
......@@ -5,7 +5,7 @@ module EE
# This module is intended to encapsulate EE-specific service logic
# and be included in the `RegisterBuildService` service
module RegisterBuildService
extend ::Prependable
extend ActiveSupport::Concern
def builds_for_shared_runner
return super unless shared_runner_build_limits_feature_enabled?
......
# This module is based on: https://gist.github.com/bcardarella/5735987
module Prependable
include ActiveSupport::Concern
def self.extended(base) #:nodoc:
base.instance_variable_set(:@_dependencies, [])
end
def prepend_features(base)
if base.instance_variable_defined?(:@_dependencies)
base.instance_variable_get(:@_dependencies) << self
......@@ -14,11 +8,17 @@ module Prependable
else
return false if base < self
super
base.singleton_class.send(:prepend, const_get('ClassMethods')) if const_defined?(:ClassMethods)
@_dependencies.each { |dep| base.send(:include, dep) }
base.singleton_class.send(:prepend, const_get('ClassMethods')) if const_defined?(:ClassMethods)
@_dependencies.each { |dep| base.send(:prepend, dep) }
base.class_eval(&@_included_block) if instance_variable_defined?(:@_included_block)
end
end
end
module ActiveSupport
module Concern
prepend Prependable
alias_method :prepended, :included
alias_method :prepended, :included
end
end
......@@ -24,7 +24,7 @@ describe Prependable do
end
module Foo
extend Prependable
extend ActiveSupport::Concern
prepended do
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