Sha256: 517cff672625567fa1e61396ef672d9bccee25806b10f5399fe4826e12cbfe1b

Contents?: true

Size: 1.39 KB

Versions: 3

Compression:

Stored size: 1.39 KB

Contents

module Aspector
  module ModuleExtension
    Module.send :include, self

    private

    def aop_method_added method
      return (block_given? and yield) if
        @aop_creating_method or
        @aop_instances.nil? or @aop_instances.empty?

      aop_applied_flag = :"@aop_applied_#{method}"
      return (block_given? and yield) if instance_variable_get(aop_applied_flag)

      begin
        instance_variable_set(aop_applied_flag, true)

        @aop_instances.apply_to_method(method.to_s)

        yield if block_given?
      ensure
        remove_instance_variable aop_applied_flag
      end
    end

    def aop_singleton_method_added method
      # Note: methods involved are on eigen class
      eigen_class = class << self; self; end

      return (block_given? and yield) if eigen_class.instance_variable_get(:@aop_creating_method)

      aop_instances = eigen_class.instance_variable_get(:@aop_instances)
      return (block_given? and yield) if aop_instances.nil? or aop_instances.empty?

      aop_applied_flag = :"@aop_applied_#{method}"
      return (block_given? and yield) if eigen_class.instance_variable_get(aop_applied_flag)

      begin
        eigen_class.instance_variable_set(aop_applied_flag, true)

        aop_instances.apply_to_method(method.to_s)

        yield if block_given?
      ensure
        eigen_class.send :remove_instance_variable, aop_applied_flag
      end
    end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
aspector-0.12.0 lib/aspector/module_extension.rb
aspector-0.11.1 lib/aspector/module_extension.rb
aspector-0.11.0 lib/aspector/module_extension.rb