breakfalls 0.0.2.alpha

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2d4211b87bfa47104d17ec238068830d3e46e44ccb1fe59d7f3b1310de1ad0cd
4
+ data.tar.gz: bdd3e51080a5eaa22b842e763f3944fa97242e99f23ed67962f08af5da09373b
5
+ SHA512:
6
+ metadata.gz: 32224dfdb64aceacfe69bc34369fb62859c38782032e910f132c4f91856fbc495cfe2048839546173d681196eb9da00a78adc10fa272de225b8b0420b500e96f
7
+ data.tar.gz: 2f4a27905a399dce2b5501d2ed635da8ce5b893c7e004357f98d5389a31ae1c76f22a05f1326b053a007d3780f5e0dfcc6249a62c759dfb08368ca2ee27a697f
data/CHANGELOG.md ADDED
@@ -0,0 +1,11 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.0.2.alpha] - 2025-09-21
4
+
5
+ - Pre-release (alpha): polish README and gemspec; document handler execution order
6
+ - CI: add GitHub Actions to run `rake test` (Ruby 3.1/3.2/3.3)
7
+ - Metadata: set homepage/source/changelog/issues URLs to `atolix/breakfalls`
8
+
9
+ ## [0.1.0] - 2025-09-18
10
+
11
+ - Initial release
@@ -0,0 +1,132 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our
6
+ community a harassment-free experience for everyone, regardless of age, body
7
+ size, visible or invisible disability, ethnicity, sex characteristics, gender
8
+ identity and expression, level of experience, education, socio-economic status,
9
+ nationality, personal appearance, race, caste, color, religion, or sexual
10
+ identity and orientation.
11
+
12
+ We pledge to act and interact in ways that contribute to an open, welcoming,
13
+ diverse, inclusive, and healthy community.
14
+
15
+ ## Our Standards
16
+
17
+ Examples of behavior that contributes to a positive environment for our
18
+ community include:
19
+
20
+ * Demonstrating empathy and kindness toward other people
21
+ * Being respectful of differing opinions, viewpoints, and experiences
22
+ * Giving and gracefully accepting constructive feedback
23
+ * Accepting responsibility and apologizing to those affected by our mistakes,
24
+ and learning from the experience
25
+ * Focusing on what is best not just for us as individuals, but for the overall
26
+ community
27
+
28
+ Examples of unacceptable behavior include:
29
+
30
+ * The use of sexualized language or imagery, and sexual attention or advances of
31
+ any kind
32
+ * Trolling, insulting or derogatory comments, and personal or political attacks
33
+ * Public or private harassment
34
+ * Publishing others' private information, such as a physical or email address,
35
+ without their explicit permission
36
+ * Other conduct which could reasonably be considered inappropriate in a
37
+ professional setting
38
+
39
+ ## Enforcement Responsibilities
40
+
41
+ Community leaders are responsible for clarifying and enforcing our standards of
42
+ acceptable behavior and will take appropriate and fair corrective action in
43
+ response to any behavior that they deem inappropriate, threatening, offensive,
44
+ or harmful.
45
+
46
+ Community leaders have the right and responsibility to remove, edit, or reject
47
+ comments, commits, code, wiki edits, issues, and other contributions that are
48
+ not aligned to this Code of Conduct, and will communicate reasons for moderation
49
+ decisions when appropriate.
50
+
51
+ ## Scope
52
+
53
+ This Code of Conduct applies within all community spaces, and also applies when
54
+ an individual is officially representing the community in public spaces.
55
+ Examples of representing our community include using an official email address,
56
+ posting via an official social media account, or acting as an appointed
57
+ representative at an online or offline event.
58
+
59
+ ## Enforcement
60
+
61
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
+ reported to the community leaders responsible for enforcement at
63
+ [INSERT CONTACT METHOD].
64
+ All complaints will be reviewed and investigated promptly and fairly.
65
+
66
+ All community leaders are obligated to respect the privacy and security of the
67
+ reporter of any incident.
68
+
69
+ ## Enforcement Guidelines
70
+
71
+ Community leaders will follow these Community Impact Guidelines in determining
72
+ the consequences for any action they deem in violation of this Code of Conduct:
73
+
74
+ ### 1. Correction
75
+
76
+ **Community Impact**: Use of inappropriate language or other behavior deemed
77
+ unprofessional or unwelcome in the community.
78
+
79
+ **Consequence**: A private, written warning from community leaders, providing
80
+ clarity around the nature of the violation and an explanation of why the
81
+ behavior was inappropriate. A public apology may be requested.
82
+
83
+ ### 2. Warning
84
+
85
+ **Community Impact**: A violation through a single incident or series of
86
+ actions.
87
+
88
+ **Consequence**: A warning with consequences for continued behavior. No
89
+ interaction with the people involved, including unsolicited interaction with
90
+ those enforcing the Code of Conduct, for a specified period of time. This
91
+ includes avoiding interactions in community spaces as well as external channels
92
+ like social media. Violating these terms may lead to a temporary or permanent
93
+ ban.
94
+
95
+ ### 3. Temporary Ban
96
+
97
+ **Community Impact**: A serious violation of community standards, including
98
+ sustained inappropriate behavior.
99
+
100
+ **Consequence**: A temporary ban from any sort of interaction or public
101
+ communication with the community for a specified period of time. No public or
102
+ private interaction with the people involved, including unsolicited interaction
103
+ with those enforcing the Code of Conduct, is allowed during this period.
104
+ Violating these terms may lead to a permanent ban.
105
+
106
+ ### 4. Permanent Ban
107
+
108
+ **Community Impact**: Demonstrating a pattern of violation of community
109
+ standards, including sustained inappropriate behavior, harassment of an
110
+ individual, or aggression toward or disparagement of classes of individuals.
111
+
112
+ **Consequence**: A permanent ban from any sort of public interaction within the
113
+ community.
114
+
115
+ ## Attribution
116
+
117
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
+ version 2.1, available at
119
+ [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
+
121
+ Community Impact Guidelines were inspired by
122
+ [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
+
124
+ For answers to common questions about this code of conduct, see the FAQ at
125
+ [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
+ [https://www.contributor-covenant.org/translations][translations].
127
+
128
+ [homepage]: https://www.contributor-covenant.org
129
+ [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
+ [Mozilla CoC]: https://github.com/mozilla/diversity
131
+ [FAQ]: https://www.contributor-covenant.org/faq
132
+ [translations]: https://www.contributor-covenant.org/translations
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 atolix
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,80 @@
1
+ # Breakfalls
2
+
3
+ Breakfalls is a tiny Rails helper that lets you register error-handling hooks for your controllers. It installs an around_action wrapper for selected controllers, catches any StandardError, invokes your registered handlers (global and per-controller), and then re-raises the error so your existing error reporting still works.
4
+
5
+ ## Installation
6
+
7
+ Add to your application's Gemfile and bundle:
8
+
9
+ ```bash
10
+ bundle add breakfalls
11
+ ```
12
+
13
+ Or install directly:
14
+
15
+ ```bash
16
+ gem install breakfalls
17
+ ```
18
+
19
+ Pre-release builds (alpha/beta/rc):
20
+
21
+ ```bash
22
+ # RubyGems
23
+ gem install breakfalls --pre
24
+
25
+ # Bundler (explicit version pin)
26
+ bundle add breakfalls --version "0.0.2.alpha"
27
+ ```
28
+
29
+ ## Usage
30
+
31
+ 1) Tell Breakfalls which controllers to wrap. In an initializer (e.g. `config/initializers/breakfalls.rb`):
32
+
33
+ ```ruby
34
+ # Wrap these controllers with Breakfalls' around_action
35
+ Rails.application.config.breakfalls.controllers = [
36
+ 'UsersController',
37
+ 'Admin::BaseController'
38
+ ]
39
+ ```
40
+
41
+ 2) Register one or more handlers. Handlers receive `(exception, request, user, params)` in that order.
42
+
43
+ ```ruby
44
+ # Global handler (runs for any wrapped controller)
45
+ Breakfalls.on_error do |exception, request, user, params|
46
+ Rails.logger.error("[Global] #{exception.class}: #{exception.message} path=#{request&.path}")
47
+ end
48
+
49
+ # Controller-specific handler (runs before global handlers)
50
+ Breakfalls.on_error_for('UsersController') do |exception, request, user, params|
51
+ Rails.logger.warn("[UsersController] #{exception.class} at #{request&.path}")
52
+ end
53
+ ```
54
+
55
+ Order of execution: controller-specific handlers (in registration order) then global handlers (in registration order). After handlers run, the exception is re-raised so your existing error handling/reporting still applies.
56
+
57
+ ## Handler order
58
+
59
+ - Controller-specific first: If the current controller matches, its handlers run before any global handlers.
60
+ - Registration order: Within each group, handlers run in the order they were registered (FIFO).
61
+ - Match scope: Only handlers registered for the exact controller class name run for that controller.
62
+ - Handler failure: If a handler itself raises, remaining handlers are skipped and that exception bubbles up.
63
+
64
+ ## Development
65
+
66
+ After checking out the repo, run `bundle install` to install dependencies. Then run `rake test` to execute the test suite.
67
+
68
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `lib/breakfalls/version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push the tag/commits, and push the `.gem` file to rubygems.org.
69
+
70
+ ## Contributing
71
+
72
+ Bug reports and pull requests are welcome on GitHub at https://github.com/atolix/breakfalls. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
73
+
74
+ ## License
75
+
76
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
77
+
78
+ ## Code of Conduct
79
+
80
+ Everyone interacting in the Breakfalls project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/atolix/breakfalls/blob/main/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'minitest/test_task'
5
+
6
+ Minitest::TestTask.create
7
+
8
+ task default: :test
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'rails/railtie'
4
+
5
+ module Breakfalls
6
+ class Railtie < ::Rails::Railtie
7
+ config.breakfalls = ActiveSupport::OrderedOptions.new
8
+
9
+ config.to_prepare do
10
+ controllers = Array(Rails.application.config.breakfalls.controllers)
11
+ next if controllers.empty?
12
+
13
+ controllers.each do |controller|
14
+ ActiveSupport.on_load(:action_controller) do
15
+ klass = controller.to_s.safe_constantize
16
+ klass.class_eval do
17
+ unless method_defined?(:dispatch_breakfalls)
18
+ def dispatch_breakfalls
19
+ yield
20
+ rescue StandardError => e
21
+ Breakfalls.run_error_handlers(
22
+ e,
23
+ request:,
24
+ user: (respond_to?(:current_user) ? current_user : nil),
25
+ params:,
26
+ controller: self.class.name
27
+ )
28
+ raise e
29
+ end
30
+ end
31
+ end
32
+
33
+ klass.send(:around_action, :dispatch_breakfalls)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Breakfalls
4
+ VERSION = '0.0.2.alpha'
5
+ end
data/lib/breakfalls.rb ADDED
@@ -0,0 +1,64 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'breakfalls/version'
4
+ require 'breakfalls/railtie' if defined?(Rails)
5
+
6
+ module Breakfalls
7
+ class << self
8
+ def error_handlers
9
+ @error_handlers ||= []
10
+ end
11
+
12
+ # Registry for controller-specific handlers.
13
+ # Key: controller class name (String); Value: Array<Proc>.
14
+ def controller_error_handlers
15
+ @controller_error_handlers ||= Hash.new { |h, k| h[k] = [] }
16
+ end
17
+
18
+ # Register a global error handler (applies to all controllers).
19
+ # Called in the order they were registered.
20
+ # Example:
21
+ # Breakfalls.on_error do |exception, request, user, params|
22
+ # Rails.logger.error("[Global] #{exception.message} path=#{request&.path}")
23
+ # end
24
+ def on_error(&block)
25
+ error_handlers << block
26
+ end
27
+
28
+ # Register a controller-specific error handler.
29
+ # The controller argument should be a class name (String or Symbol).
30
+ # Invocation order at runtime is: controller-specific handlers first, then global handlers.
31
+ # Within a controller, handlers run in the order they were registered.
32
+ # Example:
33
+ # Breakfalls.on_error_for('UsersController') do |exception, request, user, params|
34
+ # Rails.logger.warn("[UsersController] #{exception.class} at #{request&.path}")
35
+ # end
36
+ def on_error_for(controller, &block)
37
+ key = controller.to_s
38
+ controller_error_handlers[key] << block
39
+ end
40
+
41
+ # Execute error handlers.
42
+ # Call order: controller-specific (when controller matches) → global.
43
+ # Returns: Array of invoked handler Procs.
44
+ # Example (manual invocation):
45
+ # Breakfalls.run_error_handlers(
46
+ # RuntimeError.new('boom'),
47
+ # request: req,
48
+ # user: current_user,
49
+ # params: params,
50
+ # controller: 'UsersController'
51
+ # )
52
+ def run_error_handlers(exception, request: nil, user: nil, params: nil, controller: nil)
53
+ handlers = []
54
+ controller && handlers.concat(controller_error_handlers[controller.to_s])
55
+ handlers.concat(error_handlers)
56
+
57
+ handlers.each do |eh|
58
+ eh.call(exception, request, user, params)
59
+ end
60
+
61
+ handlers
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,4 @@
1
+ module Breakfalls
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,98 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: breakfalls
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2.alpha
5
+ platform: ruby
6
+ authors:
7
+ - atolix
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 2025-09-21 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: actionpack
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '6.0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">="
24
+ - !ruby/object:Gem::Version
25
+ version: '6.0'
26
+ - !ruby/object:Gem::Dependency
27
+ name: railties
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '6.0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '6.0'
40
+ - !ruby/object:Gem::Dependency
41
+ name: rails
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '6.0'
47
+ type: :development
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: '6.0'
54
+ description: Breakfalls provides a small Railtie that wraps selected controllers with
55
+ an around_action. When a StandardError is raised, it invokes your registered handlers
56
+ (global and per-controller) with (exception, request, user, params), then re-raises
57
+ so existing error handling continues.
58
+ email:
59
+ - 82761106+atolix@users.noreply.github.com
60
+ executables: []
61
+ extensions: []
62
+ extra_rdoc_files: []
63
+ files:
64
+ - CHANGELOG.md
65
+ - CODE_OF_CONDUCT.md
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - lib/breakfalls.rb
70
+ - lib/breakfalls/railtie.rb
71
+ - lib/breakfalls/version.rb
72
+ - sig/breakfalls.rbs
73
+ homepage: https://github.com/atolix/breakfalls
74
+ licenses:
75
+ - MIT
76
+ metadata:
77
+ homepage_uri: https://github.com/atolix/breakfalls
78
+ source_code_uri: https://github.com/atolix/breakfalls
79
+ changelog_uri: https://github.com/atolix/breakfalls/blob/main/CHANGELOG.md
80
+ bug_tracker_uri: https://github.com/atolix/breakfalls/issues
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: 3.1.0
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubygems_version: 3.6.2
96
+ specification_version: 4
97
+ summary: Rails controller error-handling hooks (global and per-controller).
98
+ test_files: []