liquid_error_handler 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 2c2f877a4f4bb8dda9fa31a02e6379255a62cbdf0abd94cdfb9d56ac52024c96
4
+ data.tar.gz: d6245aa709c100c2942ee6967ee3fb2f6e57a5d04433a1bbd24449a858dd2053
5
+ SHA512:
6
+ metadata.gz: 0af81abdc2d35a7d4012b4784457b3d3ddac044cbb4f69bca9d009e46b33c51d1d70228ec9b4a35aa07d16fcf4550b609bdb2efa378082176a8a7e2fae952e5b
7
+ data.tar.gz: 24eefd0375962acc527add6faff82456ddfa6d677b2b878c68423a47a70c7537b4014f3fe11c096f236028b015a88a150376b539b41be23c8c1de1ea0ed81403
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,8 @@
1
+ AllCops:
2
+ NewCops: enable
3
+ Exclude:
4
+ - 'bin/**/*'
5
+
6
+ Metrics/BlockLength:
7
+ Exclude:
8
+ - 'spec/**/*_spec.rb'
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 2.6.6
data/Gemfile ADDED
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
6
+
7
+ gem 'rake', '~> 13.0'
8
+
9
+ gem 'devpack', '~> 0.3.3'
10
+ gem 'rspec', '~> 3.10'
11
+ gem 'rspec-file_fixtures', '~> 0.1.4'
12
+ gem 'rubocop', '~> 1.23'
13
+ gem 'rubocop-rake', '~> 0.6.0'
14
+ gem 'rubocop-rspec', '~> 2.6'
15
+ gem 'strong_versions', '~> 0.4.5'
data/Gemfile.lock ADDED
@@ -0,0 +1,76 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ liquid_error_handler (0.1.0)
5
+ liquid (~> 5.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ ast (2.4.2)
11
+ concurrent-ruby (1.1.9)
12
+ devpack (0.3.3)
13
+ diff-lcs (1.4.4)
14
+ i18n (1.8.11)
15
+ concurrent-ruby (~> 1.0)
16
+ liquid (5.1.0)
17
+ paint (2.2.1)
18
+ parallel (1.21.0)
19
+ parser (3.0.3.2)
20
+ ast (~> 2.4.1)
21
+ rainbow (3.0.0)
22
+ rake (13.0.6)
23
+ regexp_parser (2.2.0)
24
+ rexml (3.2.5)
25
+ rspec (3.10.0)
26
+ rspec-core (~> 3.10.0)
27
+ rspec-expectations (~> 3.10.0)
28
+ rspec-mocks (~> 3.10.0)
29
+ rspec-core (3.10.1)
30
+ rspec-support (~> 3.10.0)
31
+ rspec-expectations (3.10.1)
32
+ diff-lcs (>= 1.2.0, < 2.0)
33
+ rspec-support (~> 3.10.0)
34
+ rspec-file_fixtures (0.1.4)
35
+ rspec (~> 3.0)
36
+ rspec-mocks (3.10.2)
37
+ diff-lcs (>= 1.2.0, < 2.0)
38
+ rspec-support (~> 3.10.0)
39
+ rspec-support (3.10.3)
40
+ rubocop (1.23.0)
41
+ parallel (~> 1.10)
42
+ parser (>= 3.0.0.0)
43
+ rainbow (>= 2.2.2, < 4.0)
44
+ regexp_parser (>= 1.8, < 3.0)
45
+ rexml
46
+ rubocop-ast (>= 1.12.0, < 2.0)
47
+ ruby-progressbar (~> 1.7)
48
+ unicode-display_width (>= 1.4.0, < 3.0)
49
+ rubocop-ast (1.15.0)
50
+ parser (>= 3.0.1.1)
51
+ rubocop-rake (0.6.0)
52
+ rubocop (~> 1.0)
53
+ rubocop-rspec (2.6.0)
54
+ rubocop (~> 1.19)
55
+ ruby-progressbar (1.11.0)
56
+ strong_versions (0.4.5)
57
+ i18n (>= 0.5)
58
+ paint (~> 2.0)
59
+ unicode-display_width (2.1.0)
60
+
61
+ PLATFORMS
62
+ x86_64-linux
63
+
64
+ DEPENDENCIES
65
+ devpack (~> 0.3.3)
66
+ liquid_error_handler!
67
+ rake (~> 13.0)
68
+ rspec (~> 3.10)
69
+ rspec-file_fixtures (~> 0.1.4)
70
+ rubocop (~> 1.23)
71
+ rubocop-rake (~> 0.6.0)
72
+ rubocop-rspec (~> 2.6)
73
+ strong_versions (~> 0.4.5)
74
+
75
+ BUNDLED WITH
76
+ 2.2.33
data/Makefile ADDED
@@ -0,0 +1,4 @@
1
+ .PHONY test:
2
+ bundle exec rspec
3
+ bundle exec rubocop
4
+ bundle exec strong_versions
data/README.md ADDED
@@ -0,0 +1,53 @@
1
+ # LiquidErrorHandler
2
+
3
+ Configure error handling hooks for the [Liquid](https://shopify.github.io/liquid/) templating language for [Ruby](https://www.ruby-lang.org/en/).
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'liquid_error_handler', '~> 0.1.0'
11
+ ```
12
+
13
+ ## Usage
14
+
15
+ Register an error handler, for example in a _Rails_ initializer. Error handlers should be callable and will receive the error as an argument.
16
+
17
+ ```ruby
18
+ # config/initializers/liquid_error_handler.rb
19
+
20
+ LiquidErrorHandler.register_handler do |error|
21
+ Rails.logger.error("Liquid Error: #{error} #{error.backtrace}")
22
+ end
23
+ ```
24
+
25
+ Use with libraries like [Airbrake](https://github.com/airbrake/airbrake) to send all _Liquid_ errors to your error aggregation platform:
26
+
27
+ ```ruby
28
+ # config/initializers/liquid_error_handler.rb
29
+
30
+ LiquidErrorHandler.register_handler do |error|
31
+ Airbrake.notify(error) unless Rails.env.development? || Rails.env.test?
32
+ end
33
+ ```
34
+
35
+ ### Disabling
36
+
37
+ _LiquidErrorHandler_ can be disabled by setting the environment variable `LIQUID_ERROR_HANDLER_DISABLE` to any value:
38
+
39
+ ```console
40
+ LIQUID_ERROR_HANDLER_DISABLE=1 rails server
41
+ ```
42
+
43
+ ### Resetting
44
+
45
+ All error handlers can be removed by calling `LiquidErrorHandler.reset`:
46
+
47
+ ```ruby
48
+ LiquidErrorHandler.reset
49
+ ```
50
+
51
+ ## License
52
+
53
+ [MIT License](LICENSE)
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'bundler/gem_tasks'
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task default: :spec
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "liquid_error_handler"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LiquidErrorHandler
4
+ # Prepended to Liquid context to handle any errors that take place during render.
5
+ module Context
6
+ def handle_error(error, *_args)
7
+ return super if LiquidErrorHandler.disabled?
8
+
9
+ LiquidErrorHandler.hooks.each { |hook| hook.call(error.cause.nil? ? error : error.cause) }
10
+ super
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LiquidErrorHandler
4
+ VERSION = '0.1.0'
5
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'liquid'
4
+
5
+ require_relative 'liquid_error_handler/version'
6
+ require_relative 'liquid_error_handler/context'
7
+
8
+ # Configures Liquid error handlers.
9
+ module LiquidErrorHandler
10
+ class Error < StandardError; end
11
+
12
+ @hooks = []
13
+
14
+ def self.reset
15
+ @hooks = []
16
+ end
17
+
18
+ def self.register_handler(&block)
19
+ @hooks << block
20
+ end
21
+
22
+ def self.disabled?
23
+ ENV.key?('LIQUID_ERROR_HANDLER_DISABLE')
24
+ end
25
+
26
+ class << self
27
+ attr_reader :hooks
28
+ end
29
+ end
30
+
31
+ Liquid::Context.prepend LiquidErrorHandler::Context unless LiquidErrorHandler.disabled?
metadata ADDED
@@ -0,0 +1,71 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: liquid_error_handler
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Bob Farrell
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-12-20 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: liquid
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.0'
27
+ description: Configure error handling hooks for Liquid.
28
+ email:
29
+ - git@bob.frl
30
+ executables: []
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - ".rspec"
35
+ - ".rubocop.yml"
36
+ - ".ruby-version"
37
+ - Gemfile
38
+ - Gemfile.lock
39
+ - Makefile
40
+ - README.md
41
+ - Rakefile
42
+ - bin/console
43
+ - bin/setup
44
+ - lib/liquid_error_handler.rb
45
+ - lib/liquid_error_handler/context.rb
46
+ - lib/liquid_error_handler/version.rb
47
+ homepage: https://github.com/bobf/liquid_error_handler
48
+ licenses:
49
+ - MIT
50
+ metadata:
51
+ rubygems_mfa_required: 'true'
52
+ post_install_message:
53
+ rdoc_options: []
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 2.6.0
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ requirements:
63
+ - - ">="
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ requirements: []
67
+ rubygems_version: 3.0.3
68
+ signing_key:
69
+ specification_version: 4
70
+ summary: Error handling for Liquid templating language.
71
+ test_files: []