Sha256: 8f35160b9eab5ba6a33327722f2bfcf256731ac1c2c42affa91e0902f58cc96e

Contents?: true

Size: 1.53 KB

Versions: 38

Compression:

Stored size: 1.53 KB

Contents

#--
# Copyright (C)2007-10 Tony Arcieri
# You can redistribute this under the terms of the Ruby license
# See file LICENSE for details
#++

module Coolio
  module Meta
    # Use an alternate watcher with the attach/detach/enable/disable methods
    # if it is presently assigned.  This is useful if you are waiting for
    # an event to occur before the current watcher can be used in earnest,
    # such as making an outgoing TCP connection.
    def watcher_delegate(proxy_var)
      %w{attach attached? detach enable disable}.each do |method|
        module_eval <<-EOD
          def #{method}(*args)
            if defined? #{proxy_var} and #{proxy_var}
              #{proxy_var}.#{method}(*args)
              return self
            end

            super
          end
        EOD
      end
    end

    # Define callbacks whose behavior can be changed on-the-fly per instance.
    # This is done by giving a block to the callback method, which is captured
    # as a proc and stored for later.  If the method is called without a block,
    # the stored block is executed if present, otherwise it's a noop.
    def event_callback(*methods)
      methods.each do |method|
        module_eval <<-EOD
          remove_method "#{method}"
          def #{method}(*args, &block)
            if block
              @#{method}_callback = block
              return
            end

            if defined? @#{method}_callback and @#{method}_callback
              @#{method}_callback.call(*args)
            end
          end
        EOD
      end
    end
  end
end

Version data entries

38 entries across 38 versions & 6 rubygems

Version Path
cool.io-1.9.0 lib/cool.io/meta.rb
fluent-plugin-nuopenlineage-light-0.1.0 vendor/bundle/ruby/3.3.0/gems/cool.io-1.8.1/lib/cool.io/meta.rb
fluent-plugin-openlineage-light-0.1.4 vendor/bundle/ruby/3.3.0/gems/cool.io-1.8.1/lib/cool.io/meta.rb
fluent-plugin-openlineage-light-0.1.3 vendor/bundle/ruby/3.3.0/gems/cool.io-1.8.1/lib/cool.io/meta.rb
fluent-plugin-openlineage-0.1.0 vendor/bundle/ruby/3.3.0/gems/cool.io-1.8.1/lib/cool.io/meta.rb
cool.io-1.8.0 lib/cool.io/meta.rb
fluent-plugin-google-cloud-logging-on-prem-0.1.0 vendor/ruby/3.1.0/gems/cool.io-1.7.1/lib/cool.io/meta.rb
cool.io-1.7.1-x86-mingw32 lib/cool.io/meta.rb
cool.io-1.7.1-x64-mingw32 lib/cool.io/meta.rb
cool.io-1.7.1 lib/cool.io/meta.rb
cool.io-1.7.0 lib/cool.io/meta.rb
cool.io-1.6.1 lib/cool.io/meta.rb
cool.io-1.6.0-x64-mingw32 lib/cool.io/meta.rb
cool.io-1.6.0-x86-mingw32 lib/cool.io/meta.rb
cool.io-1.6.0 lib/cool.io/meta.rb
cool.io-1.5.4-x64-mingw32 lib/cool.io/meta.rb
cool.io-1.5.4-x86-mingw32 lib/cool.io/meta.rb
cool.io-1.5.4 lib/cool.io/meta.rb
cool.io-1.5.3-x86-mingw32 lib/cool.io/meta.rb
cool.io-1.5.3-x64-mingw32 lib/cool.io/meta.rb