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, #connected_classes, #foreign_keys, included, #relation, #relation_names, #subclasses?, #validations, #validators
Constructor Details
#initialize(model) ⇒ Annotations
Returns a new instance of Annotations.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/stratagem/instrumentation/models/annotations.rb', line 111 def initialize(model) puts "initializing stratagem for #{model.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.
51 52 53 |
# File 'lib/stratagem/instrumentation/models/annotations.rb', line 51 def model @model end |
Class Method Details
.configure(model) ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/stratagem/instrumentation/models/annotations.rb', line 56 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) begin puts "#{model.name} supports #{adapter.tracing.name}" model.send(:include, adapter.tracing) rescue Rails.logger.error($!) end end } end |
.detect_adapters(model) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/stratagem/instrumentation/models/annotations.rb', line 86 def detect_adapters(model) @detectors ||= Detect.sg_subclasses @detectors.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
100 101 102 103 104 105 106 |
# File 'lib/stratagem/instrumentation/models/annotations.rb', line 100 def module_class_ref(name) begin module_eval(name) rescue Exception nil end end |
Instance Method Details
#adapters ⇒ Object
141 142 143 144 |
# File 'lib/stratagem/instrumentation/models/annotations.rb', line 141 def adapters # supported adapters may change throughout the lifecycle of a class / object @adapters ||= self.class.detect_adapters(model) end |
#instrument_model(adapter) ⇒ Object
127 128 129 130 |
# File 'lib/stratagem/instrumentation/models/annotations.rb', line 127 def instrument_model(adapter) instrument_model_with(adapter.tracing) instrument_model_with(adapter.instrumentation) end |
#instrument_model_with(instrumentation) ⇒ Object
132 133 134 135 136 137 138 139 |
# File 'lib/stratagem/instrumentation/models/annotations.rb', line 132 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 |