Class: Stratagem::Instrumentation::Models::Annotations
- Defined in:
- lib/stratagem/instrumentation/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
-
#model ⇒ Object
readonly
Returns the value of attribute model.
Class Method Summary collapse
Instance Method Summary collapse
- #adapters ⇒ Object
-
#initialize(model) ⇒ Annotations
constructor
A new instance of Annotations.
- #instrument_model(adapter) ⇒ Object
- #instrument_model_with(instrumentation) ⇒ Object
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, #subclasses?, #validations, #validators
Constructor Details
#initialize(model) ⇒ Annotations
Returns a new instance of Annotations.
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/stratagem/instrumentation/models/annotations.rb', line 76 def initialize(model) puts "initializing stratagem for #{model.name} - #{self.class.name}" @model = model self.class.detect_adapters(model).each do |adapter| if adapter.detector.supports?(model) # puts "\t#{model.name} supports #{adapter.detector.name}" instrument_model(adapter) # else # puts "#{model.name} does not support #{adapter.detector.name}" end end rescue puts $!. puts $!.backtrace end |
Instance Attribute Details
#model ⇒ Object (readonly)
Returns the value of attribute model.
21 22 23 |
# File 'lib/stratagem/instrumentation/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 50 |
# File 'lib/stratagem/instrumentation/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::Instrumentation::Models::Annotations.new(self) end def stratagem @stratagem ||= Stratagem::Instrumentation::Models::InstanceAnnotations.new(self) end end # connect the adapters detect_adapters(model).each {|adapter| if adapter.detector.supports?(model) puts "#{model.name} supports #{adapter.tracing.name}" model.send(:include, adapter.tracing) end } end |
.detect_adapters(model) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/stratagem/instrumentation/models/annotations.rb', line 52 def detect_adapters(model) Detect.sg_subclasses.map do |detector| namespace = detector.name.split('::') namespace.pop namespace = namespace.join('::') instrumentation = module_class_ref(namespace+"::Instrumentation") tracing = module_class_ref(namespace+"::Tracing") = module_class_ref(namespace+"::Metadata") = .new(model) if AdapterDescriptor.new(, detector, tracing, instrumentation) end end |
.module_class_ref(name) ⇒ Object
65 66 67 68 69 70 71 |
# File 'lib/stratagem/instrumentation/models/annotations.rb', line 65 def module_class_ref(name) begin module_eval(name) rescue Exception nil end end |
Instance Method Details
#adapters ⇒ Object
106 107 108 109 |
# File 'lib/stratagem/instrumentation/models/annotations.rb', line 106 def adapters # supported adapters may change throughout the lifecycle of a class / object @adapters ||= self.class.detect_adapters(model) end |
#instrument_model(adapter) ⇒ Object
92 93 94 95 |
# File 'lib/stratagem/instrumentation/models/annotations.rb', line 92 def instrument_model(adapter) instrument_model_with(adapter.tracing) instrument_model_with(adapter.instrumentation) end |
#instrument_model_with(instrumentation) ⇒ Object
97 98 99 100 101 102 103 104 |
# File 'lib/stratagem/instrumentation/models/annotations.rb', line 97 def instrument_model_with(instrumentation) return if instrumentation.nil? unless model.ancestors.include?(instrumentation) puts "including #{instrumentation.name} in #{model.name}" model.send(:include, instrumentation) end end |