Module: Ann::ClassMethods
- Defined in:
- lib/ann.rb
Defined Under Namespace
Classes: Descriptor
Instance Method Summary collapse
- #ann(*args) ⇒ Object
- #annotations ⇒ Object
- #annotations_for(name) ⇒ Object
- #inherited(subclass) ⇒ Object
- #method_added(name) ⇒ Object
Instance Method Details
#ann(*args) ⇒ Object
16 17 18 19 20 |
# File 'lib/ann.rb', line 16 def ann(*args) klass, *args = args Thread.current[:ann_descriptors] ||= [] Thread.current[:ann_descriptors] << Descriptor.new(klass, args) end |
#annotations ⇒ Object
22 23 24 |
# File 'lib/ann.rb', line 22 def annotations @annotations ||= Hash.new { |hash, key| hash[key] = [] } end |
#annotations_for(name) ⇒ Object
26 27 28 |
# File 'lib/ann.rb', line 26 def annotations_for(name) annotations[name] end |
#inherited(subclass) ⇒ Object
39 40 41 42 43 44 |
# File 'lib/ann.rb', line 39 def inherited(subclass) parent = self subclass.class_eval do @annotations = Hash[parent.annotations.map { |name, anns| [name, anns.dup] }] end end |
#method_added(name) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/ann.rb', line 30 def method_added(name) method_anns = (Thread.current[:ann_descriptors] || []).map do |desc| desc.klass.new(self, name, *desc.args) end annotations[name].concat(method_anns) Thread.current[:ann_descriptors] = nil end |