Sha256: ebda01c1cec1afb64fe48ccbda1f2f17fa59cf9e3c5e243eae3515fdd4930425

Contents?: true

Size: 1.07 KB

Versions: 22

Compression:

Stored size: 1.07 KB

Contents

# frozen_string_literal: true

module ConvenientService
  module Support
    ##
    # A wrapper for Ruby's stdlib `::Forwardable` module.
    # https://ruby-doc.org/stdlib-2.5.1/libdoc/forwardable/rdoc/Forwardable.html
    #
    # Tries to follow Rails `delegate` interface.
    # https://api.rubyonrails.org/classes/Module.html#method-i-delegate
    #
    module Delegate
      include Support::Concern

      included do
        extend ::Forwardable

        extend ClassMethodsForForwardable
      end

      ##
      # @internal
      #   `ClassMethods` is loaded faster than `included` by `Concern`.
      #   Since `Forwardable` has it own `delegate` - a different name is used.
      #
      module ClassMethodsForForwardable
        def delegate(*methods, to:)
          ##
          # NOTE: The following condition will NOT ever change. That is why it is inlined.
          #
          receiver =
            if to == :class
              :"self.class"
            else
              to
            end

          def_delegators receiver, *methods
        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
convenient_service-0.19.1 lib/convenient_service/support/delegate.rb
convenient_service-0.19.0 lib/convenient_service/support/delegate.rb
convenient_service-0.18.0 lib/convenient_service/support/delegate.rb
convenient_service-0.17.0 lib/convenient_service/support/delegate.rb
convenient_service-0.16.0 lib/convenient_service/support/delegate.rb
convenient_service-0.15.0 lib/convenient_service/support/delegate.rb
convenient_service-0.14.0 lib/convenient_service/support/delegate.rb
convenient_service-0.13.0 lib/convenient_service/support/delegate.rb
convenient_service-0.12.0 lib/convenient_service/support/delegate.rb
convenient_service-0.11.0 lib/convenient_service/support/delegate.rb
convenient_service-0.10.1 lib/convenient_service/support/delegate.rb
convenient_service-0.10.0 lib/convenient_service/support/delegate.rb
convenient_service-0.9.0 lib/convenient_service/support/delegate.rb
convenient_service-0.8.0 lib/convenient_service/support/delegate.rb
convenient_service-0.7.0 lib/convenient_service/support/delegate.rb
convenient_service-0.6.0 lib/convenient_service/support/delegate.rb
convenient_service-0.5.0 lib/convenient_service/support/delegate.rb
convenient_service-0.4.0 lib/convenient_service/support/delegate.rb
convenient_service-0.3.1 lib/convenient_service/support/delegate.rb
convenient_service-0.3.0 lib/convenient_service/support/delegate.rb