Sha256: 1d3f90147a116440778d3eb16a331e34ee4708eccd8fa8969d6d702248479dc9
Contents?: true
Size: 1.6 KB
Versions: 13
Compression:
Stored size: 1.6 KB
Contents
# ReactiveTags provide an easy way to specify how a class deals with # reactive events and method calls.als module ReactiveTags class MethodTags attr_accessor :destructive, :pass_reactive, :reacts_with end class MethodTagger attr_reader :method_tags def initialize @method_tags = MethodTags.new end def destructive!(&block) @method_tags.destructive = block || true end def pass_reactive! @method_tags.pass_reactive = true end end module ClassMethods def tag_method(method_name, &block) tagger = MethodTagger.new tagger.instance_eval(&block) @reactive_method_tags ||= {} @reactive_method_tags[method_name.to_sym] = tagger.method_tags end def tag_all_methods(&block) tagger = MethodTagger.new tagger.instance_eval(&block) @reactive_method_tags ||= {} @reactive_method_tags[:__all_methods] = tagger.method_tags end end # Returns a reference to the tags on a method def reactive_method_tag(method_name, tag_name, klass=self.class) # Check to make sure we haven't gone above a class that has included # ReactiveTags return nil if !klass || !klass.method_defined?(:reactive_method_tag) tags = klass.instance_variable_get('@reactive_method_tags') if tags && (tag = tags[method_name.to_sym]) && (tag = tag.send(tag_name)) return tag end return self.reactive_method_tag(method_name, tag_name, klass.superclass) end def self.included(base) base.send(:extend, ClassMethods) base.send(:include, Events) end end
Version data entries
13 entries across 13 versions & 1 rubygems