Class: Purrrge::Registry
- Inherits:
-
Object
- Object
- Purrrge::Registry
- Defined in:
- lib/purrrge/registry.rb
Overview
Registry tracks models that include the Scrubbable concern. It provides methods for registration and discovery of scrubbable models.
This is used by automatic discovery mechanisms to find models that can be scrubbed without requiring explicit configuration.
Class Method Summary collapse
-
.clear ⇒ Array
Clear the registry (mainly for testing).
-
.discover_models ⇒ Array<Class>
Discover all models that include Scrubbable in a Rails application This method eager loads all models in the Rails app and finds those that include the Scrubbable concern.
-
.register(model_class) ⇒ Array<Class>
Register a model class with the registry.
-
.scrubbable_models ⇒ Array<Class>
Get all registered scrubbable models.
Class Method Details
.clear ⇒ Array
Clear the registry (mainly for testing)
30 31 32 |
# File 'lib/purrrge/registry.rb', line 30 def clear @scrubbable_models = [] end |
.discover_models ⇒ Array<Class>
Discover all models that include Scrubbable in a Rails application This method eager loads all models in the Rails app and finds those that include the Scrubbable concern.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/purrrge/registry.rb', line 39 def discover_models return [] unless defined?(Rails) # Eager load all models if not in production (where eager loading is the default) Rails.application.eager_load! unless Rails.application.config.eager_load # Find all ActiveRecord models that include Purrrge::Scrubbable if defined?(ActiveRecord::Base) # Get all models that include Scrubbable scrubbable = ActiveRecord::Base.descendants.select do |model| model.included_modules.include?(Purrrge::Scrubbable) end # Register each one scrubbable.each do |model| register(model) end end scrubbable_models end |
.register(model_class) ⇒ Array<Class>
Register a model class with the registry
22 23 24 25 |
# File 'lib/purrrge/registry.rb', line 22 def register(model_class) scrubbable_models << model_class unless scrubbable_models.include?(model_class) scrubbable_models end |
.scrubbable_models ⇒ Array<Class>
Get all registered scrubbable models
14 15 16 |
# File 'lib/purrrge/registry.rb', line 14 def scrubbable_models @scrubbable_models ||= [] end |