mercy 1.6.0 → 2.0.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.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +74 -12
  3. data/.claude/agents/architect.md +48 -0
  4. data/.claude/agents/infra.md +36 -0
  5. data/.claude/agents/ruby.md +45 -0
  6. data/.claude/configuration/arcanum-repo-config.json +3 -0
  7. data/.claude/scripts/check_infra.sh +6 -0
  8. data/.claude/scripts/check_ruby.sh +7 -0
  9. data/.claude/settings.json +10 -0
  10. data/.github/commit_message_template-2.0.md +32 -0
  11. data/.github/commit_message_template.md +10 -0
  12. data/.github/copilot-instructions.md +1 -0
  13. data/.github/pull_request_template.md +17 -0
  14. data/.gitignore +3 -0
  15. data/.rubocop.yml +38 -1
  16. data/.rubocop_todo.yml +6 -317
  17. data/AGENTS.md +58 -0
  18. data/CLAUDE.md +1 -0
  19. data/Dockerfile +18 -3
  20. data/Gemfile +26 -1
  21. data/README.md +8 -4
  22. data/Rakefile +3 -0
  23. data/config/check_specs.yml +7 -0
  24. data/config/yardstick.yml +11 -3
  25. data/docs/agents/arcanum-split-issue.md +9 -0
  26. data/docs/agents/architecture.md +61 -0
  27. data/docs/agents/contributing.md +195 -0
  28. data/docs/agents/flow.md +5 -0
  29. data/docs/agents/folder-structure.md +26 -0
  30. data/docs/agents/issue-enhancement.md +10 -0
  31. data/docs/agents/issues/.gitkeep +1 -0
  32. data/docs/agents/plans/.gitkeep +1 -0
  33. data/lib/arstotzka/type_cast_ext.rb +52 -2
  34. data/lib/mercy/class_methods.rb +77 -7
  35. data/lib/mercy/concern.rb +105 -1
  36. data/lib/mercy/period_parser.rb +46 -3
  37. data/lib/mercy/report/active_record.rb +20 -16
  38. data/lib/mercy/report/error.rb +6 -4
  39. data/lib/mercy/report/multiple.rb +26 -22
  40. data/lib/mercy/report/range.rb +6 -4
  41. data/lib/mercy/report.rb +38 -7
  42. data/lib/mercy/report_builder.rb +2 -0
  43. data/lib/mercy/report_config.rb +5 -0
  44. data/lib/mercy/status.rb +7 -1
  45. data/lib/mercy/status_builder.rb +2 -0
  46. data/lib/mercy/version.rb +3 -1
  47. data/lib/mercy.rb +2 -0
  48. data/mercy.gemspec +14 -27
  49. data/scripts/bump_version.sh +62 -0
  50. data/spec/dummy/.ruby-version +1 -0
  51. data/spec/dummy/Rakefile +10 -0
  52. data/spec/dummy/app/channels/application_cable/channel.rb +6 -0
  53. data/spec/dummy/app/channels/application_cable/connection.rb +6 -0
  54. data/spec/dummy/app/controllers/application_controller.rb +4 -0
  55. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  56. data/spec/dummy/app/controllers/document_report_controller.rb +34 -0
  57. data/spec/dummy/app/controllers/example_report_controller.rb +27 -0
  58. data/spec/dummy/app/helpers/application_helper.rb +4 -0
  59. data/spec/dummy/app/jobs/application_job.rb +4 -0
  60. data/spec/dummy/app/mailers/application_mailer.rb +6 -0
  61. data/spec/dummy/app/models/application_record.rb +5 -0
  62. data/spec/dummy/app/models/concerns/.keep +0 -0
  63. data/spec/dummy/app/models/document.rb +9 -0
  64. data/spec/dummy/app/models/dummy_report.rb +6 -0
  65. data/spec/dummy/app/models/mercy/report/doc_type_error.rb +20 -0
  66. data/spec/dummy/app/models/mercy/report/dummy1.rb +19 -0
  67. data/spec/dummy/app/models/mercy/report/dummy_report.rb +11 -0
  68. data/spec/dummy/app/models/mercy/report/multiple/dummy.rb +28 -0
  69. data/spec/dummy/app/models/mercy/report/multiple/successes.rb +28 -0
  70. data/spec/dummy/app/models/mercy/report/success.rb +18 -0
  71. data/spec/dummy/app/views/layouts/application.html.erb +15 -0
  72. data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
  73. data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
  74. data/spec/dummy/bin/bundle +5 -0
  75. data/spec/dummy/bin/rails +6 -0
  76. data/spec/dummy/bin/rake +6 -0
  77. data/spec/dummy/bin/setup +38 -0
  78. data/spec/dummy/bin/update +33 -0
  79. data/spec/dummy/bin/yarn +11 -0
  80. data/spec/dummy/config/application.rb +24 -0
  81. data/spec/dummy/config/boot.rb +7 -0
  82. data/spec/dummy/config/cable.yml +10 -0
  83. data/spec/dummy/config/database.yml +20 -0
  84. data/spec/dummy/config/environment.rb +7 -0
  85. data/spec/dummy/config/environments/development.rb +55 -0
  86. data/spec/dummy/config/environments/production.rb +95 -0
  87. data/spec/dummy/config/environments/test.rb +52 -0
  88. data/spec/dummy/config/initializers/application_controller_renderer.rb +10 -0
  89. data/spec/dummy/config/initializers/backtrace_silencers.rb +9 -0
  90. data/spec/dummy/config/initializers/content_security_policy.rb +27 -0
  91. data/spec/dummy/config/initializers/cookies_serializer.rb +7 -0
  92. data/spec/dummy/config/initializers/filter_parameter_logging.rb +6 -0
  93. data/spec/dummy/config/initializers/inflections.rb +18 -0
  94. data/spec/dummy/config/initializers/mime_types.rb +6 -0
  95. data/spec/dummy/config/initializers/wrap_parameters.rb +16 -0
  96. data/spec/dummy/config/locales/en.yml +33 -0
  97. data/spec/dummy/config/puma.rb +36 -0
  98. data/spec/dummy/config/routes.rb +16 -0
  99. data/spec/dummy/config/spring.rb +8 -0
  100. data/spec/dummy/config/storage.yml +34 -0
  101. data/spec/dummy/config.ru +7 -0
  102. data/spec/dummy/db/migrate/20190508170435_create_documents.rb +13 -0
  103. data/spec/dummy/db/schema.rb +27 -0
  104. data/spec/dummy/log/.keep +0 -0
  105. data/spec/dummy/package.json +5 -0
  106. data/spec/dummy/public/404.html +67 -0
  107. data/spec/dummy/public/422.html +67 -0
  108. data/spec/dummy/public/500.html +66 -0
  109. data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
  110. data/spec/dummy/public/apple-touch-icon.png +0 -0
  111. data/spec/dummy/public/favicon.ico +0 -0
  112. data/spec/dummy/storage/.keep +0 -0
  113. data/spec/dummy/tmp/.keep +0 -0
  114. data/spec/dummy/tmp/storage/.keep +0 -0
  115. data/spec/integration/controller/error_report_controller_spec.rb +196 -0
  116. data/spec/integration/controller/multiple_report_spec.rb +86 -0
  117. data/spec/integration/controller/range_report_spec.rb +194 -0
  118. data/spec/integration/yard/arstotzka/type_cast_spec.rb +43 -0
  119. data/spec/integration/yard/controller/example_report_controller_spec.rb +95 -0
  120. data/spec/integration/yard/mercy/period_parser_spec.rb +21 -0
  121. data/spec/lib/arstotzka/type_cast_spec.rb +10 -9
  122. data/spec/lib/mercy/period_parser_spec.rb +10 -9
  123. data/spec/lib/mercy/report/error_spec.rb +93 -70
  124. data/spec/lib/mercy/report/multiple_spec.rb +9 -57
  125. data/spec/lib/mercy/report/range_spec.rb +70 -41
  126. data/spec/lib/mercy/report_builder_spec.rb +34 -17
  127. data/spec/lib/mercy/report_config_spec.rb +48 -0
  128. data/spec/lib/mercy/report_spec.rb +5 -15
  129. data/spec/lib/mercy/status_builder_spec.rb +33 -22
  130. data/spec/lib/mercy/status_spec.rb +69 -49
  131. data/spec/spec_helper.rb +18 -7
  132. data/spec/support/fixture_helpers.rb +4 -2
  133. data/spec/support/models/arstotzka/type_cast/dummy.rb +9 -0
  134. data/spec/support/shared_contexts/document_setup.rb +31 -0
  135. data/spec/support/shared_examples/time_parser.rb +2 -0
  136. metadata +113 -191
  137. data/spec/lib/mercy/report/report_config_spec.rb +0 -39
  138. data/spec/support/models/document.rb +0 -6
  139. data/spec/support/report/dummy.rb +0 -15
  140. data/spec/support/schema.rb +0 -11
@@ -1,29 +1,33 @@
1
- module Mercy::Report::Multiple
2
- def as_json
3
- {
4
- status: status
5
- }.merge(sub_reports_hash)
6
- end
1
+ # frozen_string_literal: true
7
2
 
8
- def error?
9
- sub_reports.any?(&:error?)
10
- end
3
+ module Mercy
4
+ class Report
5
+ module Multiple
6
+ def as_json
7
+ {
8
+ status: status
9
+ }.merge(sub_reports_hash)
10
+ end
11
11
 
12
- private
12
+ def error?
13
+ sub_reports.any?(&:error?)
14
+ end
13
15
 
14
- def sub_reports_hash
15
- sub_reports.map(&:as_json).as_hash(reports_ids.map(&:to_s))
16
- end
16
+ private
17
17
 
18
- def sub_reports
19
- @sub_reports ||= reports_ids.map do |id|
20
- build_sub_report(id)
21
- end
22
- end
18
+ def sub_reports_hash
19
+ sub_reports.map(&:as_json).as_hash(reports_ids.map(&:to_s))
20
+ end
23
21
 
24
- def build_sub_report(id)
25
- sub_report_class.new(json.merge(key => id))
22
+ def sub_reports
23
+ @sub_reports ||= reports_ids.map do |id|
24
+ build_sub_report(id)
25
+ end
26
+ end
27
+
28
+ def build_sub_report(id)
29
+ sub_report_class.new(json.merge(key => id))
30
+ end
31
+ end
26
32
  end
27
33
  end
28
-
29
-
@@ -1,11 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mercy
2
4
  class Report
3
5
  class Range < Report::ActiveRecord
4
- ALLOWED_PARAMETERS=[:period, :maximum, :minimum]
6
+ ALLOWED_PARAMETERS = %i[period maximum minimum].freeze
5
7
  DEFAULT_OPTION = {
6
8
  period: 1.day,
7
- scope: :all,
8
- }
9
+ scope: :all
10
+ }.freeze
9
11
 
10
12
  expose :scope
11
13
  expose :maximum, type: :infinity_float, default: 'inf'
@@ -41,7 +43,7 @@ module Mercy
41
43
  end
42
44
 
43
45
  def count_in_range?
44
- return range.include?(count)
46
+ range.include?(count)
45
47
  end
46
48
  end
47
49
  end
data/lib/mercy/report.rb CHANGED
@@ -1,12 +1,30 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mercy
4
+ # @api semipublic
5
+ #
6
+ # Class responsible for generating reports
2
7
  class Report
3
8
  include Arstotzka
9
+
4
10
  require 'mercy/report/active_record'
5
11
  require 'mercy/report/error'
6
12
  require 'mercy/report/range'
7
13
  require 'mercy/report/multiple'
8
- ALLOWED_PARAMETERS = []
9
- DEFAULT_OPTION = {}
14
+ ALLOWED_PARAMETERS = [].freeze
15
+ DEFAULT_OPTION = {}.freeze
16
+
17
+ # @private
18
+ # @api private
19
+ #
20
+ # default report options
21
+ #
22
+ # @return [Hash]
23
+ def self.default_options
24
+ return {} if self == Report
25
+
26
+ superclass.default_options.merge(self::DEFAULT_OPTION)
27
+ end
10
28
 
11
29
  attr_reader :json
12
30
 
@@ -16,27 +34,40 @@ module Mercy
16
34
  @json = default_option.merge(options)
17
35
  end
18
36
 
37
+ # Returns status string for report
38
+ #
39
+ # Possible outcomes are +:error+ and +:ok+
40
+ #
41
+ # @return [Symbol]
19
42
  def status
20
43
  @status ||= error? ? :error : :ok
21
44
  end
22
45
 
46
+ # Returns if the report results in error
47
+ #
48
+ # @return [TrueClass,FalseClass]
23
49
  def error?
24
50
  raise 'Not implemented yet'
25
51
  end
26
52
 
53
+ # Returns report hash
54
+ #
55
+ # @return [Hash]
27
56
  def as_json
28
57
  { status: status }
29
58
  end
30
59
 
31
60
  private
32
61
 
62
+ # @private
63
+ #
64
+ # default report options
65
+ #
66
+ # @return [Hash]
67
+ #
68
+ # @see .default_options
33
69
  def default_option
34
70
  self.class.default_options
35
71
  end
36
-
37
- def self.default_options
38
- return {} if self == Report
39
- self.superclass.default_options.merge(self::DEFAULT_OPTION)
40
- end
41
72
  end
42
73
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mercy
2
4
  class ReportBuilder
3
5
  def build(key, parameters = {})
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mercy
2
4
  class ReportConfig
3
5
  attr_accessor :config
@@ -21,10 +23,13 @@ module Mercy
21
23
 
22
24
  def report_class
23
25
  return type if type.is_a?(Class)
26
+
24
27
  @report_class ||= Mercy::Report.const_get(type.to_s.camelize)
25
28
  end
26
29
 
27
30
  def slice_parameters(parameters)
31
+ return parameters.permit(*allowed_parameters) if parameters.respond_to?(:permit)
32
+
28
33
  parameters.slice(*allowed_parameters)
29
34
  end
30
35
 
data/lib/mercy/status.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mercy
2
4
  class Status
3
5
  attr_reader :reports
@@ -7,7 +9,11 @@ module Mercy
7
9
  end
8
10
 
9
11
  def status
10
- reports.any? { |r| r.error? } ? :error : :ok
12
+ reports.any?(&:error?) ? :error : :ok
13
+ end
14
+
15
+ def http_status
16
+ status == :ok ? :ok : :internal_server_error
11
17
  end
12
18
 
13
19
  def as_json
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mercy
2
4
  class StatusBuilder
3
5
  def build(key, parameters = {})
data/lib/mercy/version.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Mercy
2
- VERSION = '1.6.0'
4
+ VERSION = '2.0.0'
3
5
  end
data/lib/mercy.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'darthjee/active_ext'
2
4
  require 'darthjee/core_ext'
3
5
  require 'mercy/period_parser'
data/mercy.gemspec CHANGED
@@ -1,39 +1,26 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
  require 'mercy/version'
5
6
 
6
7
  Gem::Specification.new do |gem|
7
8
  gem.name = 'mercy'
8
9
  gem.version = Mercy::VERSION
9
- gem.authors = ["Darthjee"]
10
- gem.email = ["darthjee@gmail.com"]
10
+ gem.authors = ['Darthjee']
11
+ gem.email = ['darthjee@gmail.com']
11
12
  gem.summary = 'Gem for easy health check'
12
13
  gem.description = 'Gem for easy health check'
13
14
  gem.homepage = 'https://github.com/darthjee/mercy'
14
- gem.required_ruby_version = '>= 2.5.0'
15
-
16
- gem.files = `git ls-files`.split($/)
17
- gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- gem.test_files = gem.files.grep(%r{^(test|gem|features)/})
19
- gem.require_paths = ["lib"]
20
-
21
- gem.add_runtime_dependency 'activesupport', '~> 5.x'
22
- gem.add_runtime_dependency 'darthjee-active_ext', '>= 1.3.1'
23
- gem.add_runtime_dependency 'arstotzka', '>= 1.3.2'
24
- gem.add_runtime_dependency 'darthjee-core_ext', '>= 1.7.4'
15
+ gem.required_ruby_version = '>= 3.4.0'
25
16
 
26
- gem.add_development_dependency 'activerecord', '~> 5.x'
27
- gem.add_development_dependency "sqlite3"
17
+ gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
18
+ gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
19
+ gem.require_paths = ['lib']
20
+ gem.metadata['rubygems_mfa_required'] = 'false'
28
21
 
29
- gem.add_development_dependency 'bundler', '~> 1.16.1'
30
- gem.add_development_dependency 'pry-nav', '~> 0.2.4'
31
- gem.add_development_dependency 'rake', '>= 12.3.1'
32
- gem.add_development_dependency 'rspec', '>= 3.8'
33
- gem.add_development_dependency 'rubocop', '0.58.1'
34
- gem.add_development_dependency 'rubocop-rspec', '1.30.0'
35
- gem.add_development_dependency 'rubycritic', '>= 4.0.2'
36
- gem.add_development_dependency 'simplecov', '~> 0.16.x'
37
- gem.add_development_dependency 'yard', '>= 0.9.18'
38
- gem.add_development_dependency 'yardstick', '>= 0.9.9'
22
+ gem.add_dependency 'activesupport', '~> 7.2.x'
23
+ gem.add_dependency 'arstotzka', '>= 1.6.2'
24
+ gem.add_dependency 'darthjee-active_ext', '>= 1.4.0'
25
+ gem.add_dependency 'darthjee-core_ext', '>= 3.2.0'
39
26
  end
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env bash
2
+ # Usage: scripts/bump_version.sh [major|minor|patch|X.Y.Z]
3
+ # Without arguments, bumps the patch version of the current version.
4
+
5
+ set -euo pipefail
6
+
7
+ ROOT="$(git rev-parse --show-toplevel)"
8
+ README="$ROOT/README.md"
9
+ VERSION_FILE="$ROOT/lib/mercy/version.rb"
10
+ LOCKFILE="$ROOT/Gemfile.lock"
11
+ GEM="mercy"
12
+
13
+ current=$(grep -oE "VERSION = '[0-9]+\.[0-9]+\.[0-9]+'" "$VERSION_FILE" | grep -oE '[0-9]+\.[0-9]+\.[0-9]+')
14
+ IFS='.' read -r cmajor cminor cpatch <<< "$current"
15
+
16
+ arg="${1:-patch}"
17
+
18
+ case "$arg" in
19
+ major) new_version="$((cmajor + 1)).0.0" ;;
20
+ minor) new_version="${cmajor}.$((cminor + 1)).0" ;;
21
+ patch) new_version="${cmajor}.${cminor}.$((cpatch + 1))" ;;
22
+ *) new_version="$arg" ;;
23
+ esac
24
+
25
+ # Validate semver format
26
+ if ! echo "$new_version" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then
27
+ echo "Error: version must be major, minor, patch or X.Y.Z" >&2
28
+ exit 1
29
+ fi
30
+
31
+ # Next release: following minor
32
+ IFS='.' read -r major minor _patch <<< "$new_version"
33
+ next_release="${major}.$((minor + 1)).0"
34
+
35
+ echo "Current version: $current"
36
+ echo "New version: $new_version"
37
+ echo "Next release: $next_release"
38
+
39
+ # version.rb
40
+ sed -i '' "s|VERSION = '[0-9.]*'|VERSION = '${new_version}'|" "$VERSION_FILE"
41
+
42
+ # README: YARD docs link
43
+ sed -i '' \
44
+ "s|rubydoc.info/gems/${GEM}/[0-9.]*|rubydoc.info/gems/${GEM}/${new_version}|g" \
45
+ "$README"
46
+
47
+ # README: Current Release line
48
+ sed -i '' \
49
+ "s|\*\*Current Release\*\*: \[[0-9.]*\](https://github.com/darthjee/mercy/tree/[0-9.]*)|**Current Release**: [${new_version}](https://github.com/darthjee/mercy/tree/${new_version})|" \
50
+ "$README"
51
+
52
+ # README: Next release line
53
+ sed -i '' \
54
+ "s|\*\*Next release\*\*: \[[0-9.]*\](https://github.com/darthjee/mercy/compare/[0-9.]*\.\.\.main)|**Next release**: [${next_release}](https://github.com/darthjee/mercy/compare/${new_version}...main)|" \
55
+ "$README"
56
+
57
+ # Gemfile.lock
58
+ if [ -f "$LOCKFILE" ]; then
59
+ sed -i '' "s|^\( *${GEM} (\)[0-9.]*)|\1${new_version})|" "$LOCKFILE"
60
+ fi
61
+
62
+ echo "Done."
@@ -0,0 +1 @@
1
+ 2.5.0
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Add your own tasks in files placed in lib/tasks
4
+ # ending in .rake,
5
+ # for example lib/tasks/capistrano.rake, and they
6
+ # will automatically be available to Rake.
7
+
8
+ require_relative 'config/application'
9
+
10
+ Rails.application.load_tasks
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ApplicationCable
4
+ class Channel < ActionCable::Channel::Base
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ApplicationCable
4
+ class Connection < ActionCable::Connection::Base
5
+ end
6
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ApplicationController < ActionController::Base
4
+ end
File without changes
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ class DocumentReportController < ApplicationController
4
+ include Mercy
5
+
6
+ status_report :error_a, base_scope: :type_a, clazz: Document
7
+ status_report :error_b, scope: :'type_b.with_error', clazz: Document
8
+ status_report :error_c, clazz: Document, threshold: 0.5,
9
+ scope: "status = 'error'",
10
+ base_scope: "doc_type = 'c'",
11
+ external_key: :external_id
12
+
13
+ status_report :total, type: :range, minimum: 1,
14
+ clazz: Document, on: :range
15
+ status_report :error, type: :range, maximum: 10,
16
+ scope: :with_error,
17
+ clazz: Document, on: :range
18
+
19
+ status_report :errors, on: :multiple,
20
+ type: Mercy::Report::Multiple::Dummy,
21
+ doc_type: %i[a b c]
22
+
23
+ def error_status
24
+ render_status
25
+ end
26
+
27
+ def range_status
28
+ render_status(:range)
29
+ end
30
+
31
+ def multiple_status
32
+ render_status(:multiple)
33
+ end
34
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ExampleReportController < ApplicationController
4
+ include Mercy
5
+
6
+ status_report :errors_a, base_scope: :type_a,
7
+ scope: :with_error,
8
+ clazz: Document,
9
+ external_key: :external_id
10
+ status_report :errors_b, base_scope: :type_b,
11
+ scope: :with_error,
12
+ clazz: Document,
13
+ external_key: :external_id
14
+
15
+ status_report :successes, on: :successes,
16
+ clazz: Document,
17
+ type: Mercy::Report::Multiple::Successes,
18
+ minimum: 10
19
+
20
+ def status
21
+ render_status
22
+ end
23
+
24
+ def count_status
25
+ render_status(:successes)
26
+ end
27
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ApplicationHelper
4
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ApplicationJob < ActiveJob::Base
4
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ApplicationMailer < ActionMailer::Base
4
+ default from: 'from@example.com'
5
+ layout 'mailer'
6
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ class ApplicationRecord < ActiveRecord::Base
4
+ self.abstract_class = true
5
+ end
File without changes
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Document < ActiveRecord::Base
4
+ scope :with_error, -> { where(status: :error) }
5
+ scope :with_success, -> { where(status: :success) }
6
+ scope :type_a, -> { where(doc_type: :a) }
7
+ scope :type_b, -> { where(doc_type: :b) }
8
+ scope :type_c, -> { where(doc_type: :c) }
9
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ class DummyReport
4
+ ALLOWED_PARAMETERS = %i[period threshold].freeze
5
+ def initialize(options); end
6
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mercy
4
+ class Report
5
+ class DocTypeError < Mercy::Report::Error
6
+ ALLOWED_PARAMETERS = %i[period threshold].freeze
7
+ DEFAULT_OPTION = {
8
+ threshold: 0.25,
9
+ clazz: Document,
10
+ external_key: :external_id
11
+ }.freeze
12
+
13
+ expose :doc_type, case: :snake
14
+
15
+ def base
16
+ super.where(doc_type: doc_type)
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mercy
4
+ class Report
5
+ class Dummy1 < Mercy::Report
6
+ DEFAULT_OPTION = {
7
+ option_value: 1,
8
+ other_option: 10
9
+ }.freeze
10
+ expose :option_value, :other_option, case: :snake
11
+ end
12
+
13
+ class Dummy2 < Dummy1; end
14
+
15
+ class Dummy3 < Dummy1
16
+ DEFAULT_OPTION = { option_value: 5 }.freeze
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mercy
4
+ class Report
5
+ class DummyReport < Report
6
+ ALLOWED_PARAMETERS = %i[period threshold].freeze
7
+ def initialize(options) # rubocop:disable Lint/MissingSuper
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mercy
4
+ class Report
5
+ module Multiple
6
+ class Dummy < Mercy::Report
7
+ include Mercy::Report::Multiple
8
+
9
+ DEFAULT_OPTION = {
10
+ doc_type: %i[a b]
11
+ }.freeze
12
+ expose :doc_type, case: :snake
13
+
14
+ def reports_ids
15
+ [doc_type].flatten
16
+ end
17
+
18
+ def sub_report_class
19
+ Mercy::Report::DocTypeError
20
+ end
21
+
22
+ def key
23
+ :doc_type
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mercy
4
+ class Report
5
+ module Multiple
6
+ class Successes < Mercy::Report
7
+ include Mercy::Report::Multiple
8
+
9
+ DEFAULT_OPTION = {
10
+ doc_type: %i[a b]
11
+ }.freeze
12
+ expose :doc_type, case: :snake
13
+
14
+ def reports_ids
15
+ [doc_type].flatten
16
+ end
17
+
18
+ def sub_report_class
19
+ Mercy::Report::Success
20
+ end
21
+
22
+ def key
23
+ :doc_type
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mercy
4
+ class Report
5
+ class Success < Mercy::Report::Range
6
+ ALLOWED_PARAMETERS = %i[period minimum maximum].freeze
7
+ DEFAULT_OPTION = {
8
+ clazz: Document
9
+ }.freeze
10
+
11
+ expose :doc_type, case: :snake
12
+
13
+ def base
14
+ super.with_success.where(doc_type: doc_type)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,15 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= csrf_meta_tags %>
6
+ <%= csp_meta_tag %>
7
+
8
+ <%= stylesheet_link_tag 'application', media: 'all' %>
9
+ <%= javascript_include_tag 'application' %>
10
+ </head>
11
+
12
+ <body>
13
+ <%= yield %>
14
+ </body>
15
+ </html>
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
5
+ <style>
6
+ /* Email styles need to be inline */
7
+ </style>
8
+ </head>
9
+
10
+ <body>
11
+ <%= yield %>
12
+ </body>
13
+ </html>
@@ -0,0 +1 @@
1
+ <%= yield %>
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__)
5
+ load Gem.bin_path('bundler', 'bundle')