Class: Stratagem::ApplicationExtensions::Models::Annotations

Inherits:
Object
  • Object
show all
Includes:
Metadata, Tracing
Defined in:
lib/stratagem/framework_extensions/models/annotations.rb

Defined Under Namespace

Classes: AdapterDescriptor

Constant Summary

Constants included from Metadata

Metadata::INSTANCE_ENTITY_METHODS, Metadata::INSTANCE_ENUMERATION_METHODS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Tracing

#add_invocation, #clear_invocations, #controller_trace, #invocation, #invocations_audit, invocations_audit, #parse_trace_line, #read_invocation, #read_invocations, #validator_called, #write_invocation, #write_invocations

Methods included from Metadata

#callbacks, #foreign_keys, included, #relation, #relation_names, #validations, #validators

Constructor Details

#initialize(model) ⇒ Annotations

Returns a new instance of Annotations.



65
66
67
68
# File 'lib/stratagem/framework_extensions/models/annotations.rb', line 65

def initialize(model)
  puts "initializing stratagem for #{model.name}"
  @model = model
end

Instance Attribute Details

#modelObject (readonly)

Returns the value of attribute model.



21
22
23
# File 'lib/stratagem/framework_extensions/models/annotations.rb', line 21

def model
  @model
end

Class Method Details

.configure(model) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/stratagem/framework_extensions/models/annotations.rb', line 26

def configure(model)
  puts "configuring #{model.name}"
  
  # add the stratagem namespace
  model.class_eval do 
    def self.stratagem
      # one stratagem instance per subclass
      @@stratagem ||= {}
      @@stratagem[self] ||= Stratagem::ApplicationExtensions::Models::Annotations.new(self)
    end


    def stratagem
      @stratagem ||= Stratagem::ApplicationExtensions::Models::InstanceAnnotations.new(self)
    end
  end

  # connect the adapters
  detect_adapters(model).each {|adapter|
    if adapter.detector.supports?(model)
      model.send(:include, adapter.tracing) 
    end
  }
end

.detect_adapters(model) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/stratagem/framework_extensions/models/annotations.rb', line 51

def detect_adapters(model)
  Detect.subclasses.map do |detector|
    namespace = detector.name.split('::')
    namespace.pop
    namespace = namespace.join('::')

    tracing = module_eval(namespace+"::Tracing")
     = module_eval(namespace+"::Metadata").new(model)
    
    AdapterDescriptor.new(tracing, , detector)
  end
end

Instance Method Details

#adaptersObject



70
71
72
73
# File 'lib/stratagem/framework_extensions/models/annotations.rb', line 70

def adapters
  # supported adapters may change throughout the lifecycle of a class / object
  @adapters ||= self.class.detect_adapters(model)
end