Module: CallbackLensRakeHelpers
- Defined in:
- lib/activerecord_callback_lens/tasks/callback_lens_helpers.rb
Overview
Helpers backing the callback_lens Rake tasks. Extracted into a plain Ruby module (rather than task-local methods) so the logic is namespaced and unit testable without loading Rake or invoking a task.
Class Method Summary collapse
-
.expand?(value) ⇒ Boolean
Parses the EXPAND environment variable using the strict truthy rule: only the exact string “true” (case-insensitive, surrounding whitespace stripped) enables expansion.
-
.render_mermaid(model_class, expand: false) ⇒ String
Runs the full pipeline (collect -> parse -> [expand] -> build -> render) for a model.
-
.resolve_model!(name) ⇒ Class
Resolves an ActiveRecord model class from its name, raising a descriptive error when MODEL is missing or the constant cannot be found.
Class Method Details
.expand?(value) ⇒ Boolean
Parses the EXPAND environment variable using the strict truthy rule: only the exact string “true” (case-insensitive, surrounding whitespace stripped) enables expansion. Any other value (“1”, “yes”, “”, nil) leaves it off.
55 56 57 |
# File 'lib/activerecord_callback_lens/tasks/callback_lens_helpers.rb', line 55 def (value) value.to_s.strip.downcase == "true" end |
.render_mermaid(model_class, expand: false) ⇒ String
Runs the full pipeline (collect -> parse -> [expand] -> build -> render) for a model.
When expand is true, every parsed definition’s condition_tree has its MethodRefNodes resolved into ConditionTree sub-trees via MethodResolver, matching the CLI’s --expand behaviour. When false (the default), the pipeline is identical to v0.1 output. Threading expand through this single helper keeps every rake task that delegates here uniform.
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/activerecord_callback_lens/tasks/callback_lens_helpers.rb', line 37 def render_mermaid(model_class, expand: false) definitions = ActiverecordCallbackLens::Collector::CallbackCollector.collect(model_class) definitions = definitions.map { |definition| ActiverecordCallbackLens::Parser::ConditionParser.parse(definition) } if definitions = definitions.map do |definition| ActiverecordCallbackLens::Resolver::MethodResolver.(definition, model_class) end end graph = ActiverecordCallbackLens::Graph::GraphBuilder.build(definitions) ActiverecordCallbackLens::Renderer::MermaidRenderer.render(graph) end |
.resolve_model!(name) ⇒ Class
Resolves an ActiveRecord model class from its name, raising a descriptive error when MODEL is missing or the constant cannot be found.
17 18 19 20 21 22 23 |
# File 'lib/activerecord_callback_lens/tasks/callback_lens_helpers.rb', line 17 def resolve_model!(name) raise "MODEL is required. Usage: rake callback_lens:analyze MODEL=User" if name.nil? || name.empty? Object.const_get(name) rescue NameError raise "Cannot find model class '#{name}'. Make sure it is loaded." end |