Sha256: 468a124e9289ff1129fd00609c79173d09fc9e9f0d2ea21bced35df6d0ced1cc

Contents?: true

Size: 836 Bytes

Versions: 4

Compression:

Stored size: 836 Bytes

Contents

module Schemacop
  class ScopedEnv
    def initialize(delegation_object, methods, backup_binding = nil, prefix = nil)
      @delegation_object = delegation_object
      @methods = methods
      @backup_binding = backup_binding
      @prefix = prefix
    end

    def method_missing(symbol, *args, **kwargs, &block)
      symbol = :"#{@prefix}#{symbol}" if @prefix

      if @methods.include?(symbol)
        if @delegation_object.respond_to?(symbol)
          @delegation_object.send(symbol, *args, **kwargs, &block)
        elsif @backup_binding.respond_to?(symbol)
          @backup_binding.send(symbol, *args, **kwargs, &block)
        else
          super
        end
      else
        super
      end
    end

    def respond_to_missing?(symbol, include_private = false)
      @methods.include?(symbol) || super
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
schemacop-3.0.0.rc4 lib/schemacop/scoped_env.rb
schemacop-3.0.0.rc3 lib/schemacop/scoped_env.rb
schemacop-3.0.0.rc2 lib/schemacop/scoped_env.rb
schemacop-3.0.0.rc1 lib/schemacop/scoped_env.rb