Sha256: c7145e5284f12a7441bbacee0c0d374dfbd60b48edd7b067a96fe2e1f1fdf76f

Contents?: true

Size: 1019 Bytes

Versions: 28

Compression:

Stored size: 1019 Bytes

Contents

module Tins::Annotate
  def annotate(name)
    singleton_class.class_eval do
      define_method(name) do |annotation|
        instance_variable_set "@__annotation_#{name}__", annotation
      end

      define_method("#{name}_of") do |method_name|
        __send__("#{name}_annotations")[method_name]
      end

      define_method("#{name}_annotations") do
        if instance_variable_defined?("@__annotation_#{name}_annotations__")
          instance_variable_get "@__annotation_#{name}_annotations__"
        else
          instance_variable_set "@__annotation_#{name}_annotations__", {}
        end
      end

      old_method_added = instance_method(:method_added)
      define_method(:method_added) do |method_name|
        old_method_added.bind(self).call method_name
        if annotation = instance_variable_get("@__annotation_#{name}__")
          __send__("#{name}_annotations")[method_name] = annotation
        end
        instance_variable_set "@__annotation_#{name}__", nil
      end
    end
  end
end

Version data entries

28 entries across 27 versions & 5 rubygems

Version Path
logstash-filter-cache-redis-0.3.1 vendor/bundle/jruby/1.9/gems/tins-1.6.0/lib/tins/annotate.rb
logstash-filter-cache-redis-0.3.0 vendor/bundle/jruby/1.9/gems/tins-1.6.0/lib/tins/annotate.rb
logstash-filter-cache-redis-0.2.0 vendor/bundle/jruby/1.9/gems/tins-1.6.0/lib/tins/annotate.rb
logstash-filter-cache-redis-0.1.0 vendor/bundle/jruby/1.9/gems/tins-1.6.0/lib/tins/annotate.rb
tins-1.7.0 lib/tins/annotate.rb
suzuko-0.1.8 vendor/bundle/ruby/2.0.0/gems/tins-1.6.0/lib/tins/annotate.rb
suzuko-0.1.7 vendor/bundle/ruby/2.0.0/gems/tins-1.6.0/lib/tins/annotate.rb
mastermind_adeybee-0.1.4 vendor/bundle/ruby/2.2.0/gems/tins-1.6.0/lib/tins/annotate.rb
mastermind_adeybee-0.1.3 vendor/bundle/ruby/2.2.0/gems/tins-1.6.0/lib/tins/annotate.rb
mastermind_adeybee-0.1.2 vendor/bundle/ruby/2.2.0/gems/tins-1.6.0/lib/tins/annotate.rb
mastermind_adeybee-0.1.1 vendor/bundle/ruby/2.2.0/gems/tins-1.6.0/lib/tins/annotate.rb
vagrant-cloudstack-1.2.0 vendor/bundle/gems/tins-1.6.0/lib/tins/annotate.rb
tins-1.6.0 lib/tins/annotate.rb
tins-1.5.4 lib/tins/annotate.rb
tins-1.5.3 lib/tins/annotate.rb
vagrant-cloudstack-1.1.0 vendor/bundle/gems/tins-1.5.1/lib/tins/annotate.rb
vagrant-cloudstack-1.1.0 vendor/bundle/gems/tins-1.5.2/lib/tins/annotate.rb
tins-1.5.2 lib/tins/annotate.rb
tins-1.5.1 lib/tins/annotate.rb
tins-1.5.0 lib/tins/annotate.rb