Class: RailsLens::ModelSource
- Inherits:
-
Object
- Object
- RailsLens::ModelSource
- Defined in:
- lib/rails_lens/model_source.rb
Overview
Base class for model sources Model sources provide pluggable discovery of different model types (e.g., ActiveRecord, ActiveCypher, etc.)
Gems can register their own model source by defining:
GemName::RailsLensModelSource < RailsLens::ModelSource
Example:
module MyOrm
class ModelSource < ::RailsLens::ModelSource
def self.models( = {})
# Return array of model classes
end
def self.file_patterns
['app/my_models/**/*.rb']
end
def self.annotate_model(model, = {})
# Return { status: :annotated/:skipped/:failed, model: name, ... }
end
def self.remove_annotation(model)
# Return { status: :removed/:skipped, model: name, ... }
end
end
RailsLensModelSource = ModelSource
end
Direct Known Subclasses
Class Method Summary collapse
-
.annotate_model(_model, _options = {}) ⇒ Hash
Annotate a single model.
-
.file_patterns ⇒ Array<String>
Return file patterns for annotation removal Used when removing annotations by filesystem scan.
-
.models(_options = {}) ⇒ Array<Class>
Return array of model classes to annotate.
-
.remove_annotation(_model) ⇒ Hash
Remove annotation from a single model.
-
.source_name ⇒ String
Human-readable name for this source (used in logging).
Class Method Details
.annotate_model(_model, _options = {}) ⇒ Hash
Annotate a single model
54 55 56 |
# File 'lib/rails_lens/model_source.rb', line 54 def annotate_model(_model, = {}) raise NotImplementedError, "#{name} must implement .annotate_model" end |
.file_patterns ⇒ Array<String>
Return file patterns for annotation removal Used when removing annotations by filesystem scan
46 47 48 |
# File 'lib/rails_lens/model_source.rb', line 46 def file_patterns raise NotImplementedError, "#{name} must implement .file_patterns" end |
.models(_options = {}) ⇒ Array<Class>
Return array of model classes to annotate
39 40 41 |
# File 'lib/rails_lens/model_source.rb', line 39 def models( = {}) raise NotImplementedError, "#{name} must implement .models" end |
.remove_annotation(_model) ⇒ Hash
Remove annotation from a single model
61 62 63 |
# File 'lib/rails_lens/model_source.rb', line 61 def remove_annotation(_model) raise NotImplementedError, "#{name} must implement .remove_annotation" end |
.source_name ⇒ String
Human-readable name for this source (used in logging)
67 68 69 |
# File 'lib/rails_lens/model_source.rb', line 67 def source_name name.demodulize.sub(/Source$/, '').underscore.humanize end |