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 9 |
# File 'lib/scout/annotation/annotation_module.rb', line 3 def annotation(*attrs) annotations = self.instance_variable_get("@annotations") annotations.concat attrs - annotations attrs.each do |a| self.attr_accessor a end end |
#annotations ⇒ Object
11 12 13 |
# File 'lib/scout/annotation/annotation_module.rb', line 11 def annotations @annotations ||= [] end |
#extended(obj) ⇒ Object
20 21 22 23 24 25 26 27 28 |
# File 'lib/scout/annotation/annotation_module.rb', line 20 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
15 16 17 18 |
# File 'lib/scout/annotation/annotation_module.rb', line 15 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
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 58 59 60 61 62 |
# File 'lib/scout/annotation/annotation_module.rb', line 30 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? begin obj.extend self unless self === obj rescue TypeError return obj end 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 |