Module: Annotation::AnnotationModule
- Defined in:
- lib/scout/annotation/annotation_module.rb
Instance Method Summary collapse
- #annotation(*attrs) ⇒ Object
- #annotations ⇒ Object
- #extended(obj) ⇒ Object
- #included(mod) ⇒ Object
- #setup(*args, &block) ⇒ Object
Instance Method Details
#annotation(*attrs) ⇒ Object
3 4 5 6 7 8 |
# File 'lib/scout/annotation/annotation_module.rb', line 3 def annotation(*attrs) self.instance_variable_get("@annotations").concat attrs attrs.each do |a| self.attr_accessor a end end |
#annotations ⇒ Object
10 11 12 |
# File 'lib/scout/annotation/annotation_module.rb', line 10 def annotations @annotations ||= [] end |
#extended(obj) ⇒ Object
19 20 21 22 23 24 25 26 27 |
# File 'lib/scout/annotation/annotation_module.rb', line 19 def extended(obj) attrs = self.instance_variable_get("@annotations") obj.instance_variable_set(:@annotations, []) unless obj.instance_variables.include?(:@annotations) obj.annotation_types << self annotations = obj.instance_variable_get(:@annotations) annotations.concat attrs end |
#included(mod) ⇒ Object
14 15 16 17 |
# File 'lib/scout/annotation/annotation_module.rb', line 14 def included(mod) mod.instance_variable_set(:@annotations, []) unless mod.instance_variables.include?(:@annotations) mod.instance_variable_get(:@annotations).concat self.instance_variable_get(:@annotations) end |
#setup(*args, &block) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/scout/annotation/annotation_module.rb', line 29 def setup(*args,&block) if block_given? obj, rest = block, args else obj, *rest = args end obj = block if obj.nil? return nil if obj.nil? obj.extend self unless self === obj attrs = self.instance_variable_get("@annotations") return obj if attrs.nil? || attrs.empty? if rest.length == 1 && Hash === (rlast = rest.last) && ((! (rlkey = rlast.keys.first).nil? && attrs.include?(rlkey.to_sym)) || (! attrs.length != 1 )) pairs = rlast else pairs = attrs.zip(rest) end pairs.each do |name,value| next if name.to_sym === :annotation_types obj.instance_variable_set("@#{name}", value) unless value.nil? end obj end |