Sha256: 01ce2c7476954ab8d3226008f3411500121a772b4b1652348e5b69b6c177e4bf

Contents?: true

Size: 845 Bytes

Versions: 3

Compression:

Stored size: 845 Bytes

Contents

module Evil::Client::DSL
  # Provides a namespace for client's top-level DSL
  class Scope
    extend Dry::Initializer::Mixin
    option :__scope__, default: proc {}

    # Declares a method that opens new scope inside the current one
    # An instance of new scope has access to methods of its parent
    #
    # @param  [#to_sym] name (:[]) The name of the new scope
    # @return [self]
    #
    def self.scope(name = :[], &block)
      klass = Class.new(Scope, &block)
      define_method(name) do |*args, **options|
        klass.new(*args, __scope__: self, **options)
      end
      self
    end

    private

    private :__scope__

    def respond_to_missing?(name, *)
      __scope__.respond_to? name
    end

    def method_missing(name, *args)
      super unless respond_to? name
      __scope__.send(name, *args)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
evil-client-0.2.3 lib/evil/client/dsl/scope.rb
evil-client-0.2.2 lib/evil/client/dsl/scope.rb
evil-client-0.2.1 lib/evil/client/dsl/scope.rb