Sha256: 63f3d93378ec546e62ebc89e68dbf6368f539aba969417f3470a0079c459de6a

Contents?: true

Size: 1.05 KB

Versions: 49

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

require "active_support/core_ext/hash/deep_merge"

module ActiveSupport
  class OptionMerger # :nodoc:
    instance_methods.each do |method|
      undef_method(method) unless method.start_with?("__", "instance_eval", "class", "object_id")
    end

    def initialize(context, options)
      @context, @options = context, options
    end

    private
      def method_missing(method, *arguments, &block)
        options = nil
        if arguments.size == 1 && arguments.first.is_a?(Proc)
          proc = arguments.shift
          arguments << lambda { |*args| @options.deep_merge(proc.call(*args)) }
        elsif arguments.last.respond_to?(:to_hash)
          options = @options.deep_merge(arguments.pop)
        else
          options = @options
        end

        if options
          @context.__send__(method, *arguments, **options, &block)
        else
          @context.__send__(method, *arguments, &block)
        end
      end

      def respond_to_missing?(*arguments)
        @context.respond_to?(*arguments)
      end
  end
end

Version data entries

49 entries across 47 versions & 10 rubygems

Version Path
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/activesupport-7.1.3.4/lib/active_support/option_merger.rb
activesupport-7.1.5.1 lib/active_support/option_merger.rb
activesupport-7.0.8.7 lib/active_support/option_merger.rb
activesupport-7.1.5 lib/active_support/option_merger.rb
activesupport-7.1.4.2 lib/active_support/option_merger.rb
activesupport-7.0.8.6 lib/active_support/option_merger.rb
activesupport-7.1.4.1 lib/active_support/option_merger.rb
activesupport-7.0.8.5 lib/active_support/option_merger.rb
activesupport-7.1.4 lib/active_support/option_merger.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/activesupport-7.0.8.4/lib/active_support/option_merger.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/activesupport-7.1.3.4/lib/active_support/option_merger.rb
cm-admin-1.5.22 vendor/bundle/ruby/3.3.0/gems/activesupport-7.0.5.1/lib/active_support/option_merger.rb
cm-admin-1.5.21 vendor/bundle/ruby/3.3.0/gems/activesupport-7.0.5.1/lib/active_support/option_merger.rb
cm-admin-1.5.20 vendor/bundle/ruby/3.3.0/gems/activesupport-7.0.5.1/lib/active_support/option_merger.rb
katalyst-govuk-formbuilder-1.9.2 vendor/bundle/ruby/3.3.0/gems/activesupport-7.1.3.4/lib/active_support/option_merger.rb
tinymce-rails-7.1.2 vendor/bundle/ruby/3.3.0/gems/activesupport-7.1.3.4/lib/active_support/option_merger.rb
activesupport-7.1.3.4 lib/active_support/option_merger.rb
activesupport-7.0.8.4 lib/active_support/option_merger.rb
activesupport-7.1.3.2 lib/active_support/option_merger.rb
activesupport-7.1.3.1 lib/active_support/option_merger.rb