rails_why 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/rails_why.rb ADDED
@@ -0,0 +1,86 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "rails_why/version"
4
+ require_relative "rails_why/configuration"
5
+ require_relative "rails_why/node"
6
+ require_relative "rails_why/redactor"
7
+ require_relative "rails_why/condition_analyzer"
8
+ require_relative "rails_why/diagnostic_engine"
9
+ require_relative "rails_why/tracer"
10
+ require_relative "rails_why/report"
11
+ require_relative "rails_why/text_formatter"
12
+
13
+ require_relative "rails_why/rails_integration"
14
+
15
+ module RailsWhy
16
+ class Error < StandardError; end
17
+
18
+ class << self
19
+ attr_writer :configuration
20
+
21
+ def configuration
22
+ @configuration ||= Configuration.new
23
+ end
24
+
25
+ def configure
26
+ yield(configuration) if block_given?
27
+ end
28
+
29
+ def reset_configuration!
30
+ @configuration = Configuration.new
31
+ end
32
+
33
+ def explain(root: nil, expected: :not_specified, output: nil, &block)
34
+ raise ArgumentError, "Block required for RailsWhy.explain" unless block_given?
35
+
36
+ config = configuration
37
+ if root
38
+ # Create a transient configuration with modified root
39
+ config = config.dup
40
+ config.root = root
41
+ end
42
+
43
+ tracer = Tracer.new(config)
44
+ trace_data = tracer.trace(&block)
45
+
46
+ diagnostic_engine = DiagnosticEngine.new(config)
47
+ diagnostic_engine.diagnose(
48
+ trace_data[:root_nodes],
49
+ trace_data[:result],
50
+ expected_result: expected,
51
+ raised_exception: trace_data[:raised_exception]
52
+ )
53
+
54
+ # Cleanup thread-level Rails diagnostics after diagnosis
55
+ Thread.current[:__rails_why_ar_errors] = nil
56
+ Thread.current[:__rails_why_sql_queries] = nil
57
+
58
+ report = Report.new(
59
+ result: trace_data[:result],
60
+ raised_exception: trace_data[:raised_exception],
61
+ root_nodes: trace_data[:root_nodes],
62
+ total_events: trace_data[:total_events],
63
+ duration_ms: trace_data[:duration_ms],
64
+ expected_result: expected,
65
+ config: config
66
+ )
67
+
68
+ format = output || config.output_format
69
+ case format
70
+ when :text
71
+ puts TextFormatter.new(report, config).format
72
+ when :json
73
+ puts report.to_json
74
+ when :quiet
75
+ # Do not print to stdout
76
+ end
77
+
78
+ # If an exception was raised, re-raise it to preserve original semantics
79
+ if trace_data[:raised_exception]
80
+ raise trace_data[:raised_exception]
81
+ end
82
+
83
+ report
84
+ end
85
+ end
86
+ end
data/sig/rails_why.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module RailsWhy
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails_why
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nabeel Akram
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2026-11-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: prism
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '3.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '1.0'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '3.0'
33
+ description: RailsWhy helps developers understand why business logic succeeds or fails
34
+ by tracing conditions, method results, and source locations.
35
+ email:
36
+ - akramnabeel999@gmail.com
37
+ executables: []
38
+ extensions: []
39
+ extra_rdoc_files: []
40
+ files:
41
+ - ".github/workflows/ci.yml"
42
+ - CHANGELOG.md
43
+ - CODE_OF_CONDUCT.md
44
+ - DOCKER_INTEGRATION.md
45
+ - LICENSE.txt
46
+ - README.md
47
+ - Rakefile
48
+ - lib/rails_why.rb
49
+ - lib/rails_why/condition_analyzer.rb
50
+ - lib/rails_why/configuration.rb
51
+ - lib/rails_why/diagnostic_engine.rb
52
+ - lib/rails_why/node.rb
53
+ - lib/rails_why/rails_integration.rb
54
+ - lib/rails_why/redactor.rb
55
+ - lib/rails_why/report.rb
56
+ - lib/rails_why/text_formatter.rb
57
+ - lib/rails_why/tracer.rb
58
+ - lib/rails_why/version.rb
59
+ - sig/rails_why.rbs
60
+ homepage: https://github.com/Akram-8888/rails_why
61
+ licenses:
62
+ - MIT
63
+ metadata:
64
+ homepage_uri: https://github.com/Akram-8888/rails_why
65
+ source_code_uri: https://github.com/Akram-8888/rails_why
66
+ changelog_uri: https://github.com/Akram-8888/rails_why/blob/main/CHANGELOG.md
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 3.2.0
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubygems_version: 3.4.1
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Explain business logic decisions in Ruby and Rails applications.
86
+ test_files: []