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.
- checksums.yaml +4 -4
- data/.circleci/config.yml +74 -12
- data/.claude/agents/architect.md +48 -0
- data/.claude/agents/infra.md +36 -0
- data/.claude/agents/ruby.md +45 -0
- data/.claude/configuration/arcanum-repo-config.json +3 -0
- data/.claude/scripts/check_infra.sh +6 -0
- data/.claude/scripts/check_ruby.sh +7 -0
- data/.claude/settings.json +10 -0
- data/.github/commit_message_template-2.0.md +32 -0
- data/.github/commit_message_template.md +10 -0
- data/.github/copilot-instructions.md +1 -0
- data/.github/pull_request_template.md +17 -0
- data/.gitignore +3 -0
- data/.rubocop.yml +38 -1
- data/.rubocop_todo.yml +6 -317
- data/AGENTS.md +58 -0
- data/CLAUDE.md +1 -0
- data/Dockerfile +18 -3
- data/Gemfile +26 -1
- data/README.md +8 -4
- data/Rakefile +3 -0
- data/config/check_specs.yml +7 -0
- data/config/yardstick.yml +11 -3
- data/docs/agents/arcanum-split-issue.md +9 -0
- data/docs/agents/architecture.md +61 -0
- data/docs/agents/contributing.md +195 -0
- data/docs/agents/flow.md +5 -0
- data/docs/agents/folder-structure.md +26 -0
- data/docs/agents/issue-enhancement.md +10 -0
- data/docs/agents/issues/.gitkeep +1 -0
- data/docs/agents/plans/.gitkeep +1 -0
- data/lib/arstotzka/type_cast_ext.rb +52 -2
- data/lib/mercy/class_methods.rb +77 -7
- data/lib/mercy/concern.rb +105 -1
- data/lib/mercy/period_parser.rb +46 -3
- data/lib/mercy/report/active_record.rb +20 -16
- data/lib/mercy/report/error.rb +6 -4
- data/lib/mercy/report/multiple.rb +26 -22
- data/lib/mercy/report/range.rb +6 -4
- data/lib/mercy/report.rb +38 -7
- data/lib/mercy/report_builder.rb +2 -0
- data/lib/mercy/report_config.rb +5 -0
- data/lib/mercy/status.rb +7 -1
- data/lib/mercy/status_builder.rb +2 -0
- data/lib/mercy/version.rb +3 -1
- data/lib/mercy.rb +2 -0
- data/mercy.gemspec +14 -27
- data/scripts/bump_version.sh +62 -0
- data/spec/dummy/.ruby-version +1 -0
- data/spec/dummy/Rakefile +10 -0
- data/spec/dummy/app/channels/application_cable/channel.rb +6 -0
- data/spec/dummy/app/channels/application_cable/connection.rb +6 -0
- data/spec/dummy/app/controllers/application_controller.rb +4 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/controllers/document_report_controller.rb +34 -0
- data/spec/dummy/app/controllers/example_report_controller.rb +27 -0
- data/spec/dummy/app/helpers/application_helper.rb +4 -0
- data/spec/dummy/app/jobs/application_job.rb +4 -0
- data/spec/dummy/app/mailers/application_mailer.rb +6 -0
- data/spec/dummy/app/models/application_record.rb +5 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/models/document.rb +9 -0
- data/spec/dummy/app/models/dummy_report.rb +6 -0
- data/spec/dummy/app/models/mercy/report/doc_type_error.rb +20 -0
- data/spec/dummy/app/models/mercy/report/dummy1.rb +19 -0
- data/spec/dummy/app/models/mercy/report/dummy_report.rb +11 -0
- data/spec/dummy/app/models/mercy/report/multiple/dummy.rb +28 -0
- data/spec/dummy/app/models/mercy/report/multiple/successes.rb +28 -0
- data/spec/dummy/app/models/mercy/report/success.rb +18 -0
- data/spec/dummy/app/views/layouts/application.html.erb +15 -0
- data/spec/dummy/app/views/layouts/mailer.html.erb +13 -0
- data/spec/dummy/app/views/layouts/mailer.text.erb +1 -0
- data/spec/dummy/bin/bundle +5 -0
- data/spec/dummy/bin/rails +6 -0
- data/spec/dummy/bin/rake +6 -0
- data/spec/dummy/bin/setup +38 -0
- data/spec/dummy/bin/update +33 -0
- data/spec/dummy/bin/yarn +11 -0
- data/spec/dummy/config/application.rb +24 -0
- data/spec/dummy/config/boot.rb +7 -0
- data/spec/dummy/config/cable.yml +10 -0
- data/spec/dummy/config/database.yml +20 -0
- data/spec/dummy/config/environment.rb +7 -0
- data/spec/dummy/config/environments/development.rb +55 -0
- data/spec/dummy/config/environments/production.rb +95 -0
- data/spec/dummy/config/environments/test.rb +52 -0
- data/spec/dummy/config/initializers/application_controller_renderer.rb +10 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +9 -0
- data/spec/dummy/config/initializers/content_security_policy.rb +27 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +7 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +6 -0
- data/spec/dummy/config/initializers/inflections.rb +18 -0
- data/spec/dummy/config/initializers/mime_types.rb +6 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +16 -0
- data/spec/dummy/config/locales/en.yml +33 -0
- data/spec/dummy/config/puma.rb +36 -0
- data/spec/dummy/config/routes.rb +16 -0
- data/spec/dummy/config/spring.rb +8 -0
- data/spec/dummy/config/storage.yml +34 -0
- data/spec/dummy/config.ru +7 -0
- data/spec/dummy/db/migrate/20190508170435_create_documents.rb +13 -0
- data/spec/dummy/db/schema.rb +27 -0
- data/spec/dummy/log/.keep +0 -0
- data/spec/dummy/package.json +5 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/apple-touch-icon-precomposed.png +0 -0
- data/spec/dummy/public/apple-touch-icon.png +0 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/storage/.keep +0 -0
- data/spec/dummy/tmp/.keep +0 -0
- data/spec/dummy/tmp/storage/.keep +0 -0
- data/spec/integration/controller/error_report_controller_spec.rb +196 -0
- data/spec/integration/controller/multiple_report_spec.rb +86 -0
- data/spec/integration/controller/range_report_spec.rb +194 -0
- data/spec/integration/yard/arstotzka/type_cast_spec.rb +43 -0
- data/spec/integration/yard/controller/example_report_controller_spec.rb +95 -0
- data/spec/integration/yard/mercy/period_parser_spec.rb +21 -0
- data/spec/lib/arstotzka/type_cast_spec.rb +10 -9
- data/spec/lib/mercy/period_parser_spec.rb +10 -9
- data/spec/lib/mercy/report/error_spec.rb +93 -70
- data/spec/lib/mercy/report/multiple_spec.rb +9 -57
- data/spec/lib/mercy/report/range_spec.rb +70 -41
- data/spec/lib/mercy/report_builder_spec.rb +34 -17
- data/spec/lib/mercy/report_config_spec.rb +48 -0
- data/spec/lib/mercy/report_spec.rb +5 -15
- data/spec/lib/mercy/status_builder_spec.rb +33 -22
- data/spec/lib/mercy/status_spec.rb +69 -49
- data/spec/spec_helper.rb +18 -7
- data/spec/support/fixture_helpers.rb +4 -2
- data/spec/support/models/arstotzka/type_cast/dummy.rb +9 -0
- data/spec/support/shared_contexts/document_setup.rb +31 -0
- data/spec/support/shared_examples/time_parser.rb +2 -0
- metadata +113 -191
- data/spec/lib/mercy/report/report_config_spec.rb +0 -39
- data/spec/support/models/document.rb +0 -6
- data/spec/support/report/dummy.rb +0 -15
- data/spec/support/schema.rb +0 -11
|
@@ -1,29 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
def as_json
|
|
3
|
-
{
|
|
4
|
-
status: status
|
|
5
|
-
}.merge(sub_reports_hash)
|
|
6
|
-
end
|
|
1
|
+
# frozen_string_literal: true
|
|
7
2
|
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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
|
-
|
|
12
|
+
def error?
|
|
13
|
+
sub_reports.any?(&:error?)
|
|
14
|
+
end
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
sub_reports.map(&:as_json).as_hash(reports_ids.map(&:to_s))
|
|
16
|
-
end
|
|
16
|
+
private
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
25
|
-
|
|
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
|
-
|
data/lib/mercy/report/range.rb
CHANGED
|
@@ -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=[
|
|
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
|
-
|
|
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
|
data/lib/mercy/report_builder.rb
CHANGED
data/lib/mercy/report_config.rb
CHANGED
|
@@ -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?
|
|
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
|
data/lib/mercy/status_builder.rb
CHANGED
data/lib/mercy/version.rb
CHANGED
data/lib/mercy.rb
CHANGED
data/mercy.gemspec
CHANGED
|
@@ -1,39 +1,26 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
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 = [
|
|
10
|
-
gem.email = [
|
|
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 = '>=
|
|
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.
|
|
27
|
-
gem.
|
|
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.
|
|
30
|
-
gem.
|
|
31
|
-
gem.
|
|
32
|
-
gem.
|
|
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
|
data/spec/dummy/Rakefile
ADDED
|
@@ -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
|
|
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
|
|
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,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,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 @@
|
|
|
1
|
+
<%= yield %>
|