Module: Annotation

Included in:
NamedArray, Path, Resource
Defined in:
lib/scout/annotation.rb,
lib/scout/annotation/annotated_object.rb,
lib/scout/annotation/annotation_module.rb

Defined Under Namespace

Modules: AnnotatedObject, AnnotationModule

Class Method Summary collapse

Class Method Details

.extended(base) ⇒ Object



18
19
20
21
22
# File 'lib/scout/annotation.rb', line 18

def self.extended(base)
  base.instance_variable_set(:@annotations, []) unless base.instance_variables.include?(:@annotations)
  base.include Annotation::AnnotatedObject
  base.extend Annotation::AnnotationModule
end

.is_annotated?(obj) ⇒ Boolean

Returns:

  • (Boolean)


24
25
26
# File 'lib/scout/annotation.rb', line 24

def self.is_annotated?(obj)
  obj.instance_variables.include?(:@annotation_types)
end

.purge(obj) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/scout/annotation.rb', line 28

def self.purge(obj)
  case obj
  when nil
    nil
  when Array
    obj = obj.purge if is_annotated?(obj)
    obj.collect{|e| purge(e) }
  when Hash
    new = {}
    obj.each do |k,v|
      new[purge(k)] = purge(v)
    end
    new
  else
    is_annotated?(obj) ? obj.purge : obj
  end
end

.setup(obj, annotation_types, annotation_hash) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/scout/annotation.rb', line 7

def self.setup(obj, annotation_types, annotation_hash)
  return nil if obj.nil?
  annotation_types = annotation_types.split("|") if String === annotation_types
  annotation_types = [annotation_types] unless Array === annotation_types
  annotation_types.each do |type|
    type = Kernel.const_get(type) if String === type
    type.setup(obj, annotation_hash)
  end
  obj
end