Class: RailsLens::AnnotationPipeline
- Inherits:
-
Object
- Object
- RailsLens::AnnotationPipeline
- Defined in:
- lib/rails_lens/annotation_pipeline.rb
Overview
Manages the pipeline of content providers for generating annotations
Instance Attribute Summary collapse
-
#providers ⇒ Object
readonly
Returns the value of attribute providers.
Class Method Summary collapse
-
.accumulate_result(results, provider, result) ⇒ Object
Route a single provider’s result into the accumulator hash based on the provider’s declared type.
Instance Method Summary collapse
-
#initialize ⇒ AnnotationPipeline
constructor
A new instance of AnnotationPipeline.
- #process(model_class) ⇒ Object
- #register(provider) ⇒ Object
- #unregister(provider_class) ⇒ Object
Constructor Details
#initialize ⇒ AnnotationPipeline
Returns a new instance of AnnotationPipeline.
8 9 10 11 |
# File 'lib/rails_lens/annotation_pipeline.rb', line 8 def initialize @providers = [] register_default_providers end |
Instance Attribute Details
#providers ⇒ Object (readonly)
Returns the value of attribute providers.
6 7 8 |
# File 'lib/rails_lens/annotation_pipeline.rb', line 6 def providers @providers end |
Class Method Details
.accumulate_result(results, provider, result) ⇒ Object
Route a single provider’s result into the accumulator hash based on the provider’s declared type. Shared by the pipeline and AnnotationManager.
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rails_lens/annotation_pipeline.rb', line 25 def self.accumulate_result(results, provider, result) case provider.type when :schema results[:schema] = result when :section results[:sections] << result if result when :notes results[:notes].concat(Array(result)) end end |
Instance Method Details
#process(model_class) ⇒ Object
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 63 64 65 66 67 |
# File 'lib/rails_lens/annotation_pipeline.rb', line 36 def process(model_class) results = { schema: nil, sections: [], notes: [] } # Use the model's connection pool to manage a single connection for all providers model_class.connection_pool.with_connection do |connection| @providers.each do |provider| next unless provider.applicable?(model_class) begin result = provider.process(model_class, connection) self.class.accumulate_result(results, provider, result) rescue ActiveRecord::StatementInvalid => e warn "Provider #{provider.class} database error for #{model_class}: #{e.}" rescue ActiveRecord::ConnectionNotDefined => e warn "Provider #{provider.class} connection error for #{model_class}: #{e.}" rescue NameError, NoMethodError => e warn "Provider #{provider.class} method error for #{model_class}: #{e.}" rescue RailsLens::Error => e warn "Provider #{provider.class} rails_lens error for #{model_class}: #{e.}" rescue StandardError => e warn "Provider #{provider.class} unexpected error for #{model_class}: #{e.}" end end end results end |
#register(provider) ⇒ Object
13 14 15 |
# File 'lib/rails_lens/annotation_pipeline.rb', line 13 def register(provider) @providers << provider end |
#unregister(provider_class) ⇒ Object
17 18 19 |
# File 'lib/rails_lens/annotation_pipeline.rb', line 17 def unregister(provider_class) @providers.reject! { |p| p.is_a?(provider_class) } end |