Sha256: aee33df6154419cddc7924b0bca16262ffc474b30b5aa205697170d30f68378a

Contents?: true

Size: 1 KB

Versions: 17

Compression:

Stored size: 1 KB

Contents

module Tins::Annotate
  def annotate(name)
    class << self; self; end.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

17 entries across 16 versions & 3 rubygems

Version Path
tdiary-5.1.2 vendor/bundle/ruby/2.6.0/gems/tins-0.13.2/lib/tins/annotate.rb
tdiary-5.1.1 vendor/bundle/ruby/2.6.0/gems/tins-0.13.2/lib/tins/annotate.rb
tdiary-5.0.8 vendor/bundle/ruby/2.5.0/gems/tins-0.13.2/lib/tins/annotate.rb
tdiary-5.0.8 vendor/bundle/gems/tins-0.13.2/lib/tins/annotate.rb
tins-1.3.0 lib/tins/annotate.rb
tins-1.2.0 lib/tins/annotate.rb
tins-1.1.0 lib/tins/annotate.rb
tins-1.0.1 lib/tins/annotate.rb
tins-1.0.0 lib/tins/annotate.rb
tins-0.13.2 lib/tins/annotate.rb
social_url_stats-0.0.1 vendor/ruby/1.9.1/gems/tins-0.13.1/lib/tins/annotate.rb
tins-0.13.1 lib/tins/annotate.rb
tins-0.13.0 lib/tins/annotate.rb
tins-0.12.0 lib/tins/annotate.rb
tins-0.11.0 lib/tins/annotate.rb
tins-0.10.0 lib/tins/annotate.rb
tins-0.9.0 lib/tins/annotate.rb