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_graphviz(model_class, expand: false) ⇒ String
Runs the full pipeline (collect -> parse -> [expand] -> build -> render) for a model and returns a Graphviz DOT language string.
-
.render_html(model_class, expand: false) ⇒ String
Runs the full pipeline (collect -> parse -> [expand] -> build) for a model and returns a self-contained HTML report via HtmlRenderer.
-
.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.
97 98 99 |
# File 'lib/activerecord_callback_lens/tasks/callback_lens_helpers.rb', line 97 def (value) value.to_s.strip.downcase == "true" end |
.render_graphviz(model_class, expand: false) ⇒ String
Runs the full pipeline (collect -> parse -> [expand] -> build -> render) for
a model and returns a Graphviz DOT language string. Mirrors render_mermaid
but uses the GraphvizRenderer; expand is threaded through identically so
the EXPAND=true rake convention applies to the graphviz task too.
57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/activerecord_callback_lens/tasks/callback_lens_helpers.rb', line 57 def render_graphviz(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::GraphvizRenderer.render(graph, expand: ) end |
.render_html(model_class, expand: false) ⇒ String
Runs the full pipeline (collect -> parse -> [expand] -> build) for a model and
returns a self-contained HTML report via HtmlRenderer. Mirrors
render_mermaid / render_graphviz but passes both the parsed definitions
and the assembled graph to the HtmlRenderer, which needs the definitions to
build the callback table, execution flow, and dependency tree. expand is
threaded through identically so the EXPAND=true rake convention applies.
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/activerecord_callback_lens/tasks/callback_lens_helpers.rb', line 79 def render_html(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::HtmlRenderer.render(graph, definitions: definitions, expand: ) 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, expand: ) 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 |