Sha256: ad2ce8a4f144bb9af6a15f8c5a39f564fdabb523e677f9405d233d5e0e54c4d1

Contents?: true

Size: 1.48 KB

Versions: 2

Compression:

Stored size: 1.48 KB

Contents

module Aspector
  module ModuleExtension
    Module.send :include, self

    private

    def method_added_aspector method
      return (block_given? and yield) if
        @aspector_creating_method or
        @aspector_instances.nil? or @aspector_instances.empty?

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

      begin
        instance_variable_set(aspects_applied_flag, true)

        @aspector_instances.apply_to_method(method.to_s)

        yield if block_given?
      ensure
        instance_variable_set(aspects_applied_flag, nil)
      end
    end

    def singleton_method_added_aspector 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(:@aspector_creating_method)

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

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

      begin
        eigen_class.instance_variable_set(aspects_applied_flag, true)

        aspect_instances.apply_to_method(method.to_s)

        yield if block_given?
      ensure
        eigen_class.instance_variable_set(aspects_applied_flag, nil)
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
aspector-0.7.1 lib/aspector/module_extension.rb
aspector-0.7.0 lib/aspector/module_extension.rb