Verified Commit f6206755 authored by Rémy Coutable's avatar Rémy Coutable 🏖️
Browse files

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
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -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 −2
Original line number Diff line number Diff line
@@ -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 −2
Original line number Diff line number Diff line
@@ -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 }
+1 −1
Original line number Diff line number Diff line
@@ -5,7 +5,7 @@ module Ci
    # 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?
+7 −7
Original line number Diff line number Diff line
# 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
@@ -15,10 +9,16 @@ def prepend_features(base)
      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) }
      @_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
  end
end
Loading