From f4a3a037908ce452197451ac521e57bc51684074 Mon Sep 17 00:00:00 2001 From: Sunny Ripert Date: Sun, 10 Mar 2024 22:13:29 +0100 Subject: [PATCH] RuboCop linting --- .github/workflows/lint.yml | 2 +- .rubocop.yml | 22 ++ .rubocop_gradual.lock | 307 ------------------ Gemfile.lock | 19 +- README.md | 4 +- lib/service_actor/attributable.rb | 18 +- lib/service_actor/base.rb | 22 +- lib/service_actor/checkable.rb | 10 +- lib/service_actor/checks/base.rb | 6 +- lib/service_actor/checks/default_check.rb | 22 +- lib/service_actor/checks/inclusion_check.rb | 22 +- lib/service_actor/checks/must_check.rb | 18 +- lib/service_actor/checks/nil_check.rb | 36 +- lib/service_actor/checks/type_check.rb | 38 ++- lib/service_actor/configurable.rb | 6 +- lib/service_actor/core.rb | 8 +- lib/service_actor/defaultable.rb | 6 +- lib/service_actor/failable.rb | 8 +- lib/service_actor/playable.rb | 8 +- lib/service_actor/result.rb | 21 +- service_actor.gemspec | 21 +- spec/actor_spec.rb | 62 ++-- .../check_must_advanced_no_message.rb | 4 +- .../examples/check_nil_advanced_no_message.rb | 4 +- .../disallow_nil_on_input_advanced.rb | 2 +- .../double_with_type_as_string_advanced.rb | 4 +- ...ail_in_must_when_type_is_first_advanced.rb | 4 +- ...fail_in_must_when_type_is_last_advanced.rb | 4 +- spec/examples/pay_with_provider_advanced.rb | 2 +- ..._provider_advanced_but_no_default_value.rb | 4 +- .../pay_with_provider_advanced_no_message.rb | 2 +- .../pay_with_provider_inclusion_advanced.rb | 2 +- .../examples/set_name_with_input_condition.rb | 2 +- .../set_name_with_input_condition_advanced.rb | 4 +- .../set_wrong_type_of_output_advanced.rb | 4 +- spec/examples/validate_weekdays.rb | 2 +- spec/service_actor_spec.rb | 2 +- 37 files changed, 244 insertions(+), 488 deletions(-) delete mode 100644 .rubocop_gradual.lock diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 05087ea..cf30177 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -17,4 +17,4 @@ jobs: bundler-cache: true - name: RuboCop - run: bin/rubocop-gradual --check + run: NO_GRADUAL=1 bin/rubocop --format github diff --git a/.rubocop.yml b/.rubocop.yml index 0756d3f..8061bf0 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -29,6 +29,9 @@ Gemspec/RequiredRubyVersion: # Layout +Layout/ArgumentAlignment: + EnforcedStyle: with_first_argument + # Errors out on Ruby 3.1.3 Layout/BlockAlignment: Enabled: false @@ -98,18 +101,37 @@ Style/Documentation: Style/ExponentialNotation: Enabled: true +Layout/IndentationConsistency: + Exclude: + - README.md + +Style/MethodCallWithArgsParentheses: + Enabled: false + # Allow using the second parameter as a boolean. Style/OptionalBooleanParameter: Enabled: false +Style/SingleLineMethods: + AllowIfMethodIsEmpty: true + Style/StringLiterals: EnforcedStyle: double_quotes Style/TrailingCommaInArguments: EnforcedStyleForMultiline: comma +Style/TrailingCommaInHashLiteral: + Exclude: + - README.md + Style/DoubleNegation: Enabled: false Style/StabbyLambdaParentheses: EnforcedStyle: require_no_parentheses + +# ThreadSafety + +ThreadSafety/InstanceVariableInClassMethod: + Enabled: false diff --git a/.rubocop_gradual.lock b/.rubocop_gradual.lock deleted file mode 100644 index 7223715..0000000 --- a/.rubocop_gradual.lock +++ /dev/null @@ -1,307 +0,0 @@ -{ - "README.md:2602930312": [ - [160, 7, 22, "Style/MethodCallWithArgsParentheses: Use parentheses for method calls with arguments.", 1551357039], - [162, 7, 32, "Style/MethodCallWithArgsParentheses: Use parentheses for method calls with arguments.", 3469907736], - [176, 8, 8, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 4105624451], - [177, 8, 21, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 2691788792], - [178, 8, 12, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 2495065882], - [223, 8, 13, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 1108718747], - [224, 8, 18, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 2622843996], - [225, 8, 56, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 3970094193], - [236, 8, 13, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 1108718747], - [237, 8, 18, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 2622843996], - [238, 8, 12, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 1366428542], - [274, 8, 3, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 193467149], - [288, 8, 22, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 1738946304], - [289, 8, 29, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 1219683598], - [290, 8, 15, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 4242720324], - [306, 9, 66, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 2785965385], - [306, 31, 29, "Performance/RegexpMatch: Use `match?` instead of `=~` when `MatchData` is not used.", 531562169], - [306, 31, 42, "Style/TernaryParentheses: Use parentheses for ternary expressions with complex conditions.", 983975250], - [306, 63, 4, "Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.", 2085185578], - [306, 70, 3, "Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.", 193337892], - [354, 9, 64, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 1370821485], - [355, 11, 36, "Style/TrailingCommaInHashLiteral: Put a comma after the last item of a multiline hash.", 2463160531], - [395, 9, 151, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 159557776], - [398, 13, 43, "Style/TrailingCommaInHashLiteral: Put a comma after the last item of a multiline hash.", 1702907271], - [399, 11, 1, "Style/TrailingCommaInHashLiteral: Put a comma after the last item of a multiline hash.", 177624], - [411, 9, 162, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 4154785019], - [415, 11, 4, "Style/TrailingCommaInHashLiteral: Put a comma after the last item of a multiline hash.", 2087421027], - [428, 3, 252, "Layout/IndentationConsistency: Inconsistent indentation detected.", 1514570218], - [430, 11, 197, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 2873145833], - [434, 13, 4, "Style/TrailingCommaInHashLiteral: Put a comma after the last item of a multiline hash.", 2087421027], - [442, 3, 308, "Layout/IndentationConsistency: Inconsistent indentation detected.", 3549722644], - [444, 11, 253, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 1276577734], - [449, 15, 4, "Style/TrailingCommaInHashLiteral: Put a comma after the last item of a multiline hash.", 2087421027], - [450, 13, 1, "Style/TrailingCommaInHashLiteral: Put a comma after the last item of a multiline hash.", 177624], - [458, 3, 242, "Layout/IndentationConsistency: Inconsistent indentation detected.", 797844092], - [460, 11, 175, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 143054877], - [464, 13, 4, "Style/TrailingCommaInHashLiteral: Put a comma after the last item of a multiline hash.", 2087421027], - [472, 3, 346, "Layout/IndentationConsistency: Inconsistent indentation detected.", 2362110773], - [474, 11, 272, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 2479339385], - [478, 15, 32, "Layout/LineEndStringConcatenationIndentation: Indent the first part of a string concatenated with backslash.", 1736409949], - [479, 13, 4, "Style/TrailingCommaInHashLiteral: Put a comma after the last item of a multiline hash.", 2087421027], - [487, 3, 230, "Layout/IndentationConsistency: Inconsistent indentation detected.", 3044721939], - [489, 11, 172, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 477446663], - [493, 13, 4, "Style/TrailingCommaInHashLiteral: Put a comma after the last item of a multiline hash.", 2087421027] - ], - "lib/service_actor/attributable.rb:2914630637": [ - [10, 3, 59, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 1204933570], - [30, 7, 23, "Style/MethodCallWithArgsParentheses: Use parentheses for method calls with arguments.", 2016420703], - [32, 7, 14, "Style/MethodCallWithArgsParentheses: Use parentheses for method calls with arguments.", 1420767272], - [36, 7, 7, "ThreadSafety/InstanceVariableInClassMethod: Avoid instance variables in class methods.", 722036864], - [46, 21, 10, "Performance/StringIdentifierArgument: Use `:\"#{name}=\"` instead of `\"#{name}=\"`.", 2987775322], - [50, 7, 26, "Style/MethodCallWithArgsParentheses: Use parentheses for method calls with arguments.", 1106956795], - [50, 23, 10, "Performance/StringIdentifierArgument: Use `:\"#{name}=\"` instead of `\"#{name}=\"`.", 2987775322], - [54, 7, 8, "ThreadSafety/InstanceVariableInClassMethod: Avoid instance variables in class methods.", 1735899849] - ], - "lib/service_actor/base.rb:1384601898": [ - [6, 3, 372, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 1859694145] - ], - "lib/service_actor/checkable.rb:1371441970": [ - [4, 3, 64, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 3862627531], - [14, 7, 34, "Style/TrailingCommaInArrayLiteral: Put a comma after the last item of a multiline array.", 1744210091], - [33, 30, 12, "Performance/StringIdentifierArgument: Use `:\"#{origin}s\"` instead of `\"#{origin}s\"`.", 2481531303], - [59, 13, 35, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 3019920128] - ], - "lib/service_actor/checks/base.rb:124451405": [ - [4, 3, 54, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 853011185] - ], - "lib/service_actor/checks/default_check.rb:315716200": [ - [29, 3, 65, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 720136416], - [33, 3, 196, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 329234138] - ], - "lib/service_actor/checks/inclusion_check.rb:3443106288": [ - [25, 9, 29, "Layout/LineEndStringConcatenationIndentation: Align parts of a string concatenated with backslash.", 2400253882], - [30, 3, 369, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 2767559325] - ], - "lib/service_actor/checks/must_check.rb:2959929121": [ - [36, 3, 293, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 1940412977] - ], - "lib/service_actor/checks/nil_check.rb:1408021727": [ - [38, 3, 357, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 1874231255] - ], - "lib/service_actor/checks/type_check.rb:2396679417": [ - [37, 3, 368, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 1749704976] - ], - "lib/service_actor/configurable.rb:2379152505": [ - [4, 3, 59, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 1204933570], - [21, 7, 21, "ThreadSafety/InstanceVariableInClassMethod: Avoid instance variables in class methods.", 240420736], - [27, 7, 14, "ThreadSafety/InstanceVariableInClassMethod: Avoid instance variables in class methods.", 2923095860] - ], - "lib/service_actor/core.rb:3246954327": [ - [4, 3, 59, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 1204933570], - [19, 21, 9, "Performance/StringIdentifierArgument: Use `:\"#{key}=\"` instead of `\"#{key}=\"`.", 1022841802], - [42, 3, 13, "Style/SingleLineMethods: Avoid single-line method definitions.", 622651540], - [45, 3, 17, "Style/SingleLineMethods: Avoid single-line method definitions.", 2825890304] - ], - "lib/service_actor/defaultable.rb:3257396550": [ - [29, 3, 64, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 3862627531] - ], - "lib/service_actor/failable.rb:3481571367": [ - [10, 3, 94, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 4021822177], - [31, 7, 9, "ThreadSafety/InstanceVariableInClassMethod: Avoid instance variables in class methods.", 319259018] - ], - "lib/service_actor/playable.rb:3511078507": [ - [12, 3, 94, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 4021822177], - [31, 7, 12, "ThreadSafety/InstanceVariableInClassMethod: Avoid instance variables in class methods.", 798044166] - ], - "lib/service_actor/result.rb:1828502347": [ - [8, 3, 86, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 3727597697], - [79, 50, 2, "Style/RedundantLineContinuation: Redundant line continuation.", 5862675], - [80, 20, 45, "Layout/MultilineOperationIndentation: Use 2 (not 15) spaces for indenting a condition in an `if` statement spanning multiple lines.", 888429576], - [88, 8, 51, "Layout/MultilineOperationIndentation: Use 4 (not 3) spaces for indenting a condition in an `if` statement spanning multiple lines.", 2035554402], - [103, 7, 61, "Layout/LineEndStringConcatenationIndentation: Indent the first part of a string concatenated with backslash.", 1446933026] - ], - "service_actor.gemspec:3176990543": [ - [32, 5, 21, "Style/CommandLiteral: Use `%x` around command string.", 2340001096], - [38, 3, 38, "Gemspec/DependencyVersion: Dependency version specification is required.", 2799546261], - [38, 3, 38, "Style/MethodCallWithArgsParentheses: Use parentheses for method calls with arguments.", 2799546261], - [41, 3, 39, "Gemspec/DependencyVersion: Dependency version specification is required.", 4007245444], - [41, 3, 39, "Style/MethodCallWithArgsParentheses: Use parentheses for method calls with arguments.", 4007245444], - [44, 3, 38, "Gemspec/DependencyVersion: Dependency version specification is required.", 1032140206], - [44, 3, 38, "Style/MethodCallWithArgsParentheses: Use parentheses for method calls with arguments.", 1032140206], - [47, 3, 37, "Gemspec/DependencyVersion: Dependency version specification is required.", 1202442760], - [47, 3, 37, "Style/MethodCallWithArgsParentheses: Use parentheses for method calls with arguments.", 1202442760], - [52, 3, 56, "Style/MethodCallWithArgsParentheses: Use parentheses for method calls with arguments.", 1496057722], - [56, 3, 67, "Style/MethodCallWithArgsParentheses: Use parentheses for method calls with arguments.", 3352209572], - [59, 3, 59, "Style/MethodCallWithArgsParentheses: Use parentheses for method calls with arguments.", 4236915618], - [62, 3, 47, "Gemspec/DependencyVersion: Dependency version specification is required.", 3367389567], - [62, 3, 47, "Style/MethodCallWithArgsParentheses: Use parentheses for method calls with arguments.", 3367389567], - [65, 3, 53, "Gemspec/DependencyVersion: Dependency version specification is required.", 4157127408], - [65, 3, 53, "Style/MethodCallWithArgsParentheses: Use parentheses for method calls with arguments.", 4157127408], - [68, 3, 46, "Gemspec/DependencyVersion: Dependency version specification is required.", 2185074421], - [68, 3, 46, "Style/MethodCallWithArgsParentheses: Use parentheses for method calls with arguments.", 2185074421], - [71, 3, 44, "Gemspec/DependencyVersion: Dependency version specification is required.", 664785788], - [71, 3, 44, "Style/MethodCallWithArgsParentheses: Use parentheses for method calls with arguments.", 664785788] - ], - "spec/actor_spec.rb:1274419012": [ - [8, 29, 10, "RSpec/ClassCheck: Prefer `be_a` over `be_kind_of`.", 3679076707], - [287, 13, 38, "Layout/LineEndStringConcatenationIndentation: Indent the first part of a string concatenated with backslash.", 2685815861], - [310, 17, 40, "Layout/LineEndStringConcatenationIndentation: Align parts of a string concatenated with backslash.", 288459521], - [326, 17, 38, "Layout/LineEndStringConcatenationIndentation: Align parts of a string concatenated with backslash.", 70974863], - [327, 19, 52, "Layout/LineEndStringConcatenationIndentation: Align parts of a string concatenated with backslash.", 890422367], - [372, 13, 50, "Layout/LineEndStringConcatenationIndentation: Indent the first part of a string concatenated with backslash.", 1973930778], - [416, 15, 43, "Layout/LineEndStringConcatenationIndentation: Align parts of a string concatenated with backslash.", 3157936006], - [458, 15, 18, "Layout/LineEndStringConcatenationIndentation: Indent the first part of a string concatenated with backslash.", 3660717167], - [510, 13, 27, "Layout/LineEndStringConcatenationIndentation: Indent the first part of a string concatenated with backslash.", 4216326503], - [560, 13, 65, "Layout/LineEndStringConcatenationIndentation: Indent the first part of a string concatenated with backslash.", 3674211185], - [618, 13, 56, "Layout/LineEndStringConcatenationIndentation: Indent the first part of a string concatenated with backslash.", 2597977143], - [675, 11, 41, "Layout/LineEndStringConcatenationIndentation: Indent the first part of a string concatenated with backslash.", 2149743579], - [701, 11, 22, "Layout/LineEndStringConcatenationIndentation: Indent the first part of a string concatenated with backslash.", 3999235946], - [713, 65, 1, "Layout/LineContinuationSpacing: Use one space in front of backslash.", 177657], - [714, 11, 27, "Layout/LineEndStringConcatenationIndentation: Indent the first part of a string concatenated with backslash.", 4216326503], - [822, 29, 10, "RSpec/ClassCheck: Prefer `be_a` over `be_kind_of`.", 3679076707], - [830, 29, 10, "RSpec/ClassCheck: Prefer `be_a` over `be_kind_of`.", 3679076707] - ], - "spec/examples/allow_nil_on_input_with_type_and_default_nil.rb:2686481601": [ - [6, 3, 13, "Style/SingleLineMethods: Avoid single-line method definitions.", 622651540] - ], - "spec/examples/check_must_advanced_no_message.rb:2884490080": [ - [5, 9, 90, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 3523591900], - [7, 13, 24, "Style/TrailingCommaInHashLiteral: Put a comma after the last item of a multiline hash.", 1406265369], - [8, 11, 1, "Style/TrailingCommaInHashLiteral: Put a comma after the last item of a multiline hash.", 177624] - ], - "spec/examples/check_nil_advanced_no_message.rb:416179994": [ - [5, 9, 42, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 1771439028], - [6, 11, 9, "Style/TrailingCommaInHashLiteral: Put a comma after the last item of a multiline hash.", 3503157816] - ], - "spec/examples/disallow_nil_on_input.rb:3740165182": [ - [6, 3, 13, "Style/SingleLineMethods: Avoid single-line method definitions.", 622651540] - ], - "spec/examples/disallow_nil_on_input_advanced.rb:509249881": [ - [5, 9, 12, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 2723323794], - [6, 9, 160, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 2100001966], - [10, 11, 4, "Style/TrailingCommaInHashLiteral: Put a comma after the last item of a multiline hash.", 2087421027], - [13, 3, 13, "Style/SingleLineMethods: Avoid single-line method definitions.", 622651540] - ], - "spec/examples/double_with_type_as_string_advanced.rb:739256910": [ - [5, 9, 249, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 207083684], - [9, 13, 30, "Layout/LineEndStringConcatenationIndentation: Indent the first part of a string concatenated with backslash.", 1768855069], - [10, 11, 4, "Style/TrailingCommaInHashLiteral: Put a comma after the last item of a multiline hash.", 2087421027] - ], - "spec/examples/expected_fail_in_must_when_type_is_first_advanced.rb:2223775489": [ - [5, 9, 13, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 1315691617], - [6, 9, 187, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 731834095], - [9, 13, 56, "Style/TrailingCommaInHashLiteral: Put a comma after the last item of a multiline hash.", 1705794194], - [10, 11, 1, "Style/TrailingCommaInHashLiteral: Put a comma after the last item of a multiline hash.", 177624], - [13, 3, 13, "Style/SingleLineMethods: Avoid single-line method definitions.", 622651540] - ], - "spec/examples/expected_fail_in_must_when_type_is_last_advanced.rb:1483201713": [ - [5, 9, 187, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 731834095], - [8, 13, 56, "Style/TrailingCommaInHashLiteral: Put a comma after the last item of a multiline hash.", 1705794194], - [9, 11, 1, "Style/TrailingCommaInHashLiteral: Put a comma after the last item of a multiline hash.", 177624], - [11, 9, 13, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 1315691617], - [13, 3, 13, "Style/SingleLineMethods: Avoid single-line method definitions.", 622651540] - ], - "spec/examples/fail_on_argument_error.rb:293171180": [ - [8, 3, 13, "Style/SingleLineMethods: Avoid single-line method definitions.", 622651540] - ], - "spec/examples/fail_playing_actions.rb:3571891913": [ - [8, 8, 14, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 1752191311], - [9, 8, 13, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 4185087645], - [10, 8, 14, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 1752191311] - ], - "spec/examples/fail_playing_actions_with_rollback.rb:534289229": [ - [9, 8, 26, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 2729114843], - [10, 8, 26, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 2729114843], - [11, 8, 13, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 4185087645], - [12, 8, 26, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 2729114843] - ], - "spec/examples/lambda_default_with_reference.rb:3956284590": [ - [6, 9, 53, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 3679552011], - [7, 9, 12, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 2723323794] - ], - "spec/examples/pay_with_provider_advanced.rb:3733645434": [ - [5, 9, 181, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 3327147720], - [9, 11, 4, "Style/TrailingCommaInHashLiteral: Put a comma after the last item of a multiline hash.", 2087421027], - [11, 9, 17, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 3882274685] - ], - "spec/examples/pay_with_provider_advanced_but_no_default_value.rb:2075574223": [ - [5, 9, 181, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 3327147720], - [9, 11, 4, "Style/TrailingCommaInHashLiteral: Put a comma after the last item of a multiline hash.", 2087421027], - [11, 9, 158, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 587357307], - [15, 11, 4, "Style/TrailingCommaInHashLiteral: Put a comma after the last item of a multiline hash.", 2087421027] - ], - "spec/examples/pay_with_provider_advanced_no_message.rb:1205082075": [ - [5, 9, 63, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 455523157], - [6, 11, 30, "Style/TrailingCommaInHashLiteral: Put a comma after the last item of a multiline hash.", 3272115698] - ], - "spec/examples/pay_with_provider_inclusion_advanced.rb:3052716636": [ - [5, 9, 181, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 3327147720], - [9, 11, 4, "Style/TrailingCommaInHashLiteral: Put a comma after the last item of a multiline hash.", 2087421027], - [11, 9, 17, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 3882274685] - ], - "spec/examples/play_actors.rb:656555927": [ - [5, 8, 9, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 487726163], - [6, 8, 16, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 937575143], - [7, 8, 17, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 609533437], - [8, 8, 20, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 504381186], - [9, 8, 14, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 1752191311] - ], - "spec/examples/play_alias_input.rb:3344810070": [ - [7, 8, 58, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 13049230], - [8, 8, 29, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 3949406103], - [9, 8, 17, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 609533437] - ], - "spec/examples/play_error_and_catch_it_in_rollback.rb:60599370": [ - [5, 8, 13, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 4185087645] - ], - "spec/examples/play_instance_methods.rb:1422933624": [ - [8, 8, 14, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 1752191311], - [9, 8, 9, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 502519717], - [10, 8, 11, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 390222454], - [11, 8, 17, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 609533437] - ], - "spec/examples/play_interactor.rb:2713064580": [ - [8, 8, 28, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 1699636162] - ], - "spec/examples/play_lambdas.rb:1207822101": [ - [7, 8, 14, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 1752191311], - [8, 8, 53, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 523568898], - [9, 8, 31, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 253042036], - [10, 8, 17, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 609533437] - ], - "spec/examples/play_multiple_times.rb:872706559": [ - [9, 8, 9, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 487726163], - [12, 8, 17, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 609533437] - ], - "spec/examples/play_multiple_times_with_conditions.rb:825715212": [ - [9, 8, 36, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 161410530], - [12, 8, 40, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 1545791047], - [15, 8, 18, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 3994784039], - [18, 8, 21, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 2822850897] - ], - "spec/examples/play_multiple_times_with_evaluated_conditions.rb:3904291159": [ - [8, 8, 29, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 4003272498], - [9, 8, 29, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 4003272498], - [10, 8, 36, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 1446841775] - ], - "spec/examples/set_name_with_input_condition.rb:3642601476": [ - [5, 9, 12, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 2723323794], - [6, 9, 74, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 2525232760], - [7, 11, 46, "Style/TrailingCommaInHashLiteral: Put a comma after the last item of a multiline hash.", 244115462] - ], - "spec/examples/set_name_with_input_condition_advanced.rb:811520118": [ - [5, 9, 12, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 2723323794], - [6, 9, 220, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 4284749010], - [11, 13, 4, "Style/TrailingCommaInHashLiteral: Put a comma after the last item of a multiline hash.", 2087421027], - [12, 11, 1, "Style/TrailingCommaInHashLiteral: Put a comma after the last item of a multiline hash.", 177624] - ], - "spec/examples/set_wrong_type_of_output_advanced.rb:2495824050": [ - [5, 10, 243, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 1327104653], - [9, 14, 30, "Layout/LineEndStringConcatenationIndentation: Indent the first part of a string concatenated with backslash.", 1768855069], - [10, 12, 4, "Style/TrailingCommaInHashLiteral: Put a comma after the last item of a multiline hash.", 2087421027] - ], - "spec/examples/validate_weekdays.rb:2080152618": [ - [7, 9, 11, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 2804726046], - [8, 9, 15, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 2088918180], - [9, 9, 25, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 584488467], - [10, 9, 147, "Layout/ArgumentAlignment: Use one level of indentation for arguments following the first line of a multi-line method call.", 492344559], - [13, 11, 3, "Style/TrailingCommaInHashLiteral: Put a comma after the last item of a multiline hash.", 193405706], - [16, 3, 13, "Style/SingleLineMethods: Avoid single-line method definitions.", 622651540] - ], - "spec/service_actor_spec.rb:1116266777": [ - [4, 3, 78, "RSpec/NoExpectationExample: No expectation found in this example.", 1244393217] - ] -} diff --git a/Gemfile.lock b/Gemfile.lock index cc82426..cbd8c41 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,12 +2,14 @@ PATH remote: . specs: service_actor (3.7.0) - zeitwerk + zeitwerk (>= 1.0) GEM remote: https://rubygems.org/ specs: ast (2.4.2) + code-scanning-rubocop (0.6.1) + rubocop (~> 1.0) coderay (1.1.3) diff-lcs (1.5.1) diffy (3.4.2) @@ -118,16 +120,17 @@ PLATFORMS ruby DEPENDENCIES - interactor - pry - rake - rspec + code-scanning-rubocop + interactor (>= 3.0) + pry (>= 0.12) + rake (>= 13.0) + rspec (>= 3.0) rspec-block_is_expected (>= 1.0) rubocop-gradual (>= 0.3) rubocop-lts (~> 18.2) - rubocop-performance - rubocop-rake - rubocop-rspec + rubocop-performance (>= 1.0) + rubocop-rake (>= 0.1) + rubocop-rspec (>= 2.0) service_actor! BUNDLED WITH diff --git a/README.md b/README.md index a051586..0d8ac67 100644 --- a/README.md +++ b/README.md @@ -303,7 +303,7 @@ class BuildGreeting < Actor input :adjective, default: "wonderful" input :length_of_time, default: -> { ["day", "week", "month"].sample } input :article, - default: -> context { context.adjective =~ /^aeiou/ ? 'an' : 'a' } + default: -> context { context.adjective.match?(/^aeiou/) ? "an" : "a" } output :greeting @@ -475,7 +475,7 @@ end is: [TrueClass, FalseClass], message: (lambda do |input_key:, expected_type:, given_type:, **| "Wrong type \"#{given_type}\" for \"#{input_key}\". " \ - "Expected: \"#{expected_type}\"" + "Expected: \"#{expected_type}\"" end) } end diff --git a/lib/service_actor/attributable.rb b/lib/service_actor/attributable.rb index 7bc4458..213180a 100644 --- a/lib/service_actor/attributable.rb +++ b/lib/service_actor/attributable.rb @@ -7,8 +7,10 @@ # output :name # end module ServiceActor::Attributable - def self.included(base) - base.extend(ClassMethods) + class << self + def included(base) + base.extend(ClassMethods) + end end module ClassMethods @@ -26,10 +28,8 @@ def input(name, **arguments) result[name] end - # For avoid method redefined warning messages. - alias_method name, name if method_defined?(name) - - protected name + # To avoid method redefined warning messages. + protected alias_method(name, name) if method_defined?(name) end def inputs @@ -42,12 +42,12 @@ def output(name, **arguments) define_method(name) do result[name] end + protected name - define_method("#{name}=") do |value| + define_method(:"#{name}=") do |value| result[name] = value end - - protected name, "#{name}=" + protected :"#{name}=" end def outputs diff --git a/lib/service_actor/base.rb b/lib/service_actor/base.rb index e072e16..567eb16 100644 --- a/lib/service_actor/base.rb +++ b/lib/service_actor/base.rb @@ -3,16 +3,18 @@ require "service_actor/support/loader" module ServiceActor::Base - def self.included(base) - # Essential mechanics - base.include(ServiceActor::Core) - base.include(ServiceActor::Configurable) - base.include(ServiceActor::Attributable) - base.include(ServiceActor::Playable) + class << self + def included(base) + # Essential mechanics + base.include(ServiceActor::Core) + base.include(ServiceActor::Configurable) + base.include(ServiceActor::Attributable) + base.include(ServiceActor::Playable) - # Extra concerns - base.include(ServiceActor::Checkable) - base.include(ServiceActor::Defaultable) - base.include(ServiceActor::Failable) + # Extra concerns + base.include(ServiceActor::Checkable) + base.include(ServiceActor::Defaultable) + base.include(ServiceActor::Failable) + end end end diff --git a/lib/service_actor/checkable.rb b/lib/service_actor/checkable.rb index c8bfdb0..5ca5513 100644 --- a/lib/service_actor/checkable.rb +++ b/lib/service_actor/checkable.rb @@ -1,8 +1,10 @@ # frozen_string_literal: true module ServiceActor::Checkable - def self.included(base) - base.prepend(PrependedMethods) + class << self + def included(base) + base.prepend(PrependedMethods) + end end module PrependedMethods @@ -11,7 +13,7 @@ module PrependedMethods ServiceActor::Checks::MustCheck, ServiceActor::Checks::InclusionCheck, ServiceActor::Checks::NilCheck, - ServiceActor::Checks::DefaultCheck + ServiceActor::Checks::DefaultCheck, ].freeze private_constant :CHECK_CLASSES @@ -30,7 +32,7 @@ def _call # rubocop:disable Metrics/MethodLength def service_actor_checks_for(origin) check_classes = CHECK_CLASSES.select { _1.applicable_to_origin?(origin) } - self.class.public_send("#{origin}s").each do |input_key, input_options| + self.class.public_send(:"#{origin}s").each do |input_key, input_options| input_options.each do |check_name, check_conditions| check_classes.each do |check_class| argument_errors = check_class.check( diff --git a/lib/service_actor/checks/base.rb b/lib/service_actor/checks/base.rb index 7ae43f2..552866c 100644 --- a/lib/service_actor/checks/base.rb +++ b/lib/service_actor/checks/base.rb @@ -1,8 +1,10 @@ # frozen_string_literal: true class ServiceActor::Checks::Base - def self.applicable_to_origin?(_origin) - true + class << self + def applicable_to_origin?(_origin) + true + end end def initialize diff --git a/lib/service_actor/checks/default_check.rb b/lib/service_actor/checks/default_check.rb index c21e797..fb95522 100644 --- a/lib/service_actor/checks/default_check.rb +++ b/lib/service_actor/checks/default_check.rb @@ -26,17 +26,19 @@ # } # end class ServiceActor::Checks::DefaultCheck < ServiceActor::Checks::Base - def self.applicable_to_origin?(origin) - origin == :input - end + class << self + def applicable_to_origin?(origin) + origin == :input + end - def self.check(result:, input_key:, input_options:, actor:, **) - new( - result: result, - input_key: input_key, - input_options: input_options, - actor: actor, - ).check + def check(result:, input_key:, input_options:, actor:, **) + new( + result: result, + input_key: input_key, + input_options: input_options, + actor: actor, + ).check + end end def initialize(result:, input_key:, input_options:, actor:) diff --git a/lib/service_actor/checks/inclusion_check.rb b/lib/service_actor/checks/inclusion_check.rb index e1a11c4..910f502 100644 --- a/lib/service_actor/checks/inclusion_check.rb +++ b/lib/service_actor/checks/inclusion_check.rb @@ -22,21 +22,23 @@ class ServiceActor::Checks::InclusionCheck < ServiceActor::Checks::Base DEFAULT_MESSAGE = lambda do |input_key:, actor:, inclusion_in:, value:| "The \"#{input_key}\" input must be included " \ "in #{inclusion_in.inspect} on \"#{actor}\" " \ - "instead of #{value.inspect}" + "instead of #{value.inspect}" end private_constant :DEFAULT_MESSAGE - def self.check(check_name:, input_key:, actor:, conditions:, result:, **) # rubocop:disable Metrics/ParameterLists - # DEPRECATED: `in` is deprecated in favor of `inclusion`. - return unless %i[inclusion in].include?(check_name) + class << self + def check(check_name:, input_key:, actor:, conditions:, result:, **) + # DEPRECATED: `in` is deprecated in favor of `inclusion`. + return unless %i[inclusion in].include?(check_name) - new( - input_key: input_key, - actor: actor, - inclusion: conditions, - value: result[input_key], - ).check + new( + input_key: input_key, + actor: actor, + inclusion: conditions, + value: result[input_key], + ).check + end end def initialize(input_key:, actor:, inclusion:, value:) diff --git a/lib/service_actor/checks/must_check.rb b/lib/service_actor/checks/must_check.rb index 8840b81..0971a58 100644 --- a/lib/service_actor/checks/must_check.rb +++ b/lib/service_actor/checks/must_check.rb @@ -33,15 +33,17 @@ class ServiceActor::Checks::MustCheck < ServiceActor::Checks::Base private_constant :DEFAULT_MESSAGE - def self.check(check_name:, input_key:, actor:, conditions:, result:, **) # rubocop:disable Metrics/ParameterLists - return unless check_name == :must + class << self + def check(check_name:, input_key:, actor:, conditions:, result:, **) + return unless check_name == :must - new( - input_key: input_key, - actor: actor, - nested_checks: conditions, - value: result[input_key], - ).check + new( + input_key: input_key, + actor: actor, + nested_checks: conditions, + value: result[input_key], + ).check + end end def initialize(input_key:, actor:, nested_checks:, value:) diff --git a/lib/service_actor/checks/nil_check.rb b/lib/service_actor/checks/nil_check.rb index 990c948..8401f9c 100644 --- a/lib/service_actor/checks/nil_check.rb +++ b/lib/service_actor/checks/nil_check.rb @@ -35,23 +35,25 @@ class ServiceActor::Checks::NilCheck < ServiceActor::Checks::Base private_constant :DEFAULT_MESSAGE - def self.check( # rubocop:disable Metrics/ParameterLists - origin:, - input_key:, - input_options:, - actor:, - conditions:, - result:, - ** - ) # do - new( - origin: origin, - input_key: input_key, - input_options: input_options, - actor: actor, - allow_nil: conditions, - value: result[input_key], - ).check + class << self + def check( + origin:, + input_key:, + input_options:, + actor:, + conditions:, + result:, + ** + ) # do + new( + origin: origin, + input_key: input_key, + input_options: input_options, + actor: actor, + allow_nil: conditions, + value: result[input_key], + ).check + end end def initialize( # rubocop:disable Metrics/ParameterLists diff --git a/lib/service_actor/checks/type_check.rb b/lib/service_actor/checks/type_check.rb index 33f0e4f..126cdeb 100644 --- a/lib/service_actor/checks/type_check.rb +++ b/lib/service_actor/checks/type_check.rb @@ -34,24 +34,26 @@ class ServiceActor::Checks::TypeCheck < ServiceActor::Checks::Base private_constant :DEFAULT_MESSAGE - def self.check( # rubocop:disable Metrics/ParameterLists - check_name:, - origin:, - input_key:, - actor:, - conditions:, - result:, - ** - ) # do - return unless check_name == :type - - new( - origin: origin, - input_key: input_key, - actor: actor, - type_definition: conditions, - given_type: result[input_key], - ).check + class << self + def check( + check_name:, + origin:, + input_key:, + actor:, + conditions:, + result:, + ** + ) # do + return unless check_name == :type + + new( + origin: origin, + input_key: input_key, + actor: actor, + type_definition: conditions, + given_type: result[input_key], + ).check + end end def initialize(origin:, input_key:, actor:, type_definition:, given_type:) diff --git a/lib/service_actor/configurable.rb b/lib/service_actor/configurable.rb index ef9ba49..5acd033 100644 --- a/lib/service_actor/configurable.rb +++ b/lib/service_actor/configurable.rb @@ -1,8 +1,10 @@ # frozen_string_literal: true module ServiceActor::Configurable - def self.included(base) - base.extend(ClassMethods) + class << self + def included(base) + base.extend(ClassMethods) + end end module ClassMethods diff --git a/lib/service_actor/core.rb b/lib/service_actor/core.rb index 263eaa6..2afc8d3 100644 --- a/lib/service_actor/core.rb +++ b/lib/service_actor/core.rb @@ -1,8 +1,10 @@ # frozen_string_literal: true module ServiceActor::Core - def self.included(base) - base.extend(ClassMethods) + class << self + def included(base) + base.extend(ClassMethods) + end end module ClassMethods @@ -16,7 +18,7 @@ def call(result = nil, **arguments) instance._call outputs.each_key do |key| - result.send("#{key}=", nil) unless result.respond_to?(key) + result.send(:"#{key}=", nil) unless result.respond_to?(key) end result diff --git a/lib/service_actor/defaultable.rb b/lib/service_actor/defaultable.rb index e254c66..bcc1112 100644 --- a/lib/service_actor/defaultable.rb +++ b/lib/service_actor/defaultable.rb @@ -26,8 +26,10 @@ # } # end module ServiceActor::Defaultable - def self.included(base) - base.prepend(PrependedMethods) + class << self + def included(base) + base.prepend(PrependedMethods) + end end module PrependedMethods diff --git a/lib/service_actor/failable.rb b/lib/service_actor/failable.rb index 8a429be..58a2188 100644 --- a/lib/service_actor/failable.rb +++ b/lib/service_actor/failable.rb @@ -7,9 +7,11 @@ # fail_on ServiceActor::ArgumentError # end module ServiceActor::Failable - def self.included(base) - base.extend(ClassMethods) - base.prepend(PrependedMethods) + class << self + def included(base) + base.extend(ClassMethods) + base.prepend(PrependedMethods) + end end module ClassMethods diff --git a/lib/service_actor/playable.rb b/lib/service_actor/playable.rb index 9002be7..d080195 100644 --- a/lib/service_actor/playable.rb +++ b/lib/service_actor/playable.rb @@ -9,9 +9,11 @@ # SendWelcomeEmail # end module ServiceActor::Playable - def self.included(base) - base.extend(ClassMethods) - base.prepend(PrependedMethods) + class << self + def included(base) + base.extend(ClassMethods) + base.prepend(PrependedMethods) + end end module ClassMethods diff --git a/lib/service_actor/result.rb b/lib/service_actor/result.rb index 346eca9..f2e5ab4 100644 --- a/lib/service_actor/result.rb +++ b/lib/service_actor/result.rb @@ -5,10 +5,12 @@ # Represents the context of an actor, holding the data from both its inputs # and outputs. class ServiceActor::Result - def self.to_result(data) - return data if data.is_a?(self) + class << self + def to_result(data) + return data if data.is_a?(self) - new(data.to_h) + new(data.to_h) + end end def initialize(data = {}) @@ -76,8 +78,11 @@ def display def respond_to_missing?(method_name, _include_private = false) return true if method_name.end_with?("=") - return true if method_name.end_with?("?") && \ - data.key?(method_name.to_s.chomp("?").to_sym) + if method_name.end_with?("?") && + data.key?(method_name.to_s.chomp("?").to_sym) + return true + end + return true if data.key?(method_name) false @@ -85,7 +90,7 @@ def respond_to_missing?(method_name, _include_private = false) def method_missing(method_name, *args) # rubocop:disable Metrics/AbcSize if method_name.end_with?("?") && - data.key?(key = method_name.to_s.chomp("?").to_sym) + data.key?(key = method_name.to_s.chomp("?").to_sym) value = data[key] value.respond_to?(:empty?) ? !value.empty? : !!value elsif method_name.end_with?("=") @@ -100,8 +105,8 @@ def method_missing(method_name, *args) # rubocop:disable Metrics/AbcSize def warn_on_undefined_method_invocation(message) Kernel.warn( "DEPRECATED: Invoking undefined methods on `ServiceActor::Result` will " \ - "lead to runtime errors in the next major release of Actor. " \ - "Invoked method: `#{message}`", + "lead to runtime errors in the next major release of Actor. " \ + "Invoked method: `#{message}`", ) end end diff --git a/service_actor.gemspec b/service_actor.gemspec index 2818b3f..2a011ff 100644 --- a/service_actor.gemspec +++ b/service_actor.gemspec @@ -29,22 +29,22 @@ Gem::Specification.new do |spec| ] spec.files = Dir.chdir(File.expand_path(__dir__)) do - `git ls-files -z lib`.split("\x0") + %x(git ls-files -z lib).split("\x0") end spec.required_ruby_version = [">= 2.7"] # Loader - spec.add_runtime_dependency "zeitwerk" + spec.add_runtime_dependency "zeitwerk", ">= 1.0" # Tests - spec.add_development_dependency "rspec" + spec.add_development_dependency "rspec", ">= 3.0" # Development Tasks - spec.add_development_dependency "rake" + spec.add_development_dependency "rake", ">= 13.0" # Debugger - spec.add_development_dependency "pry" + spec.add_development_dependency "pry", ">= 0.12" # Linting rubocop-lts is a RuboCop wrapper for Ruby # and should only be bumped when dropping old Ruby support @@ -59,14 +59,17 @@ Gem::Specification.new do |spec| spec.add_development_dependency "rubocop-gradual", ">= 0.3" # Lint RSpec code - spec.add_development_dependency "rubocop-rspec" + spec.add_development_dependency "rubocop-rspec", ">= 2.0" # Add performance linting - spec.add_development_dependency "rubocop-performance" + spec.add_development_dependency "rubocop-performance", ">= 1.0" # Add Rakefile linting - spec.add_development_dependency "rubocop-rake" + spec.add_development_dependency "rubocop-rake", ">= 0.1" + + # Formatter for GitHub’s code scanning + spec.add_development_dependency "code-scanning-rubocop" # For testing Interactor migration support - spec.add_development_dependency "interactor" + spec.add_development_dependency "interactor", ">= 3.0" end diff --git a/spec/actor_spec.rb b/spec/actor_spec.rb index 8419d6f..40f28b9 100644 --- a/spec/actor_spec.rb +++ b/spec/actor_spec.rb @@ -5,7 +5,7 @@ context "when fail! is not called" do let(:actor) { DoNothing.call } - it { expect(actor).to be_kind_of(ServiceActor::Result) } + it { expect(actor).to be_a(ServiceActor::Result) } it { expect(actor).to be_a_success } it { expect(actor).not_to be_a_failure } end @@ -284,7 +284,7 @@ it "raises" do expected_error = "The \"name\" input on \"SetNameWithInputCondition\" " \ - "must \"be_lowercase\" but was \"42\"" + "must \"be_lowercase\" but was \"42\"" expect { SetNameWithInputCondition.call(name: "42") } .to raise_error(ServiceActor::ArgumentError, expected_error) @@ -307,7 +307,7 @@ let(:expected_message) do "The \"per_page\" input on " \ "\"ExpectedFailInMustWhenTypeIsFirstAdvanced\" must be " \ - "of type \"Integer\" but was \"String\"" + "of type \"Integer\" but was \"String\"" end it "raises" do @@ -323,8 +323,8 @@ let(:expected_message) do "The \"per_page\" input on " \ "\"ExpectedFailInMustWhenTypeIsLastAdvanced\" has an error " \ - "in the code inside \"be_in_range\": " \ - "[ArgumentError] comparison of String with 3 failed" + "in the code inside \"be_in_range\": " \ + "[ArgumentError] comparison of String with 3 failed" end it "raises" do @@ -369,7 +369,7 @@ it "does not allow other types" do expected_error = "The \"value\" input on \"DoubleWithTypeAsString\" must " \ - "be of type \"Integer, Float\" but was \"String\"" + "be of type \"Integer, Float\" but was \"String\"" expect { DoubleWithTypeAsString.call(value: "2.0") } .to raise_error(ServiceActor::ArgumentError, expected_error) end @@ -413,7 +413,7 @@ let(:expected_message) do "The \"name\" output on " \ "\"SetWrongTypeOfOutputWithCustomArgumentErrorClass\" must " \ - "be of type \"String\" but was \"Integer\"" + "be of type \"String\" but was \"Integer\"" end it "raises" do @@ -455,7 +455,7 @@ it "fails" do expected_error = "The \"name\" input on \"DisallowNilOnInput\" does not " \ - "allow nil values" + "allow nil values" expect { DisallowNilOnInput.call(name: nil) } .to raise_error(ServiceActor::ArgumentError, expected_error) @@ -507,7 +507,7 @@ it "fails" do expected_error = "The \"name\" output on \"DisallowNilOnOutput\" " \ - "does not allow nil values" + "does not allow nil values" expect { DisallowNilOnOutput.call(test_without_output: true) } .to raise_error(ServiceActor::ArgumentError, expected_error) @@ -557,8 +557,8 @@ context "when given an incorrect value" do let(:expected_alert) do 'The "provider" input must be included in ' \ - '["MANGOPAY", "PayPal", "Stripe"] on "PayWithProviderInclusion" ' \ - 'instead of "Paypal"' + '["MANGOPAY", "PayPal", "Stripe"] on ' \ + '"PayWithProviderInclusion" instead of "Paypal"' end it "fails" do @@ -615,8 +615,8 @@ context "when given an incorrect value" do let(:expected_alert) do 'The "provider" input must be included in ' \ - '["MANGOPAY", "PayPal", "Stripe"] on "PayWithProvider" ' \ - 'instead of "Paypal"' + '["MANGOPAY", "PayPal", "Stripe"] on "PayWithProvider" ' \ + 'instead of "Paypal"' end it "fails" do @@ -672,9 +672,9 @@ context "when using inclusion check" do let(:expected_alert) do 'The "provider" input must be included ' \ - 'in ["MANGOPAY", "PayPal", "Stripe"] on ' \ - '"PayWithProviderAdvancedNoMessage" ' \ - 'instead of "Paypal2"' + 'in ["MANGOPAY", "PayPal", "Stripe"] on ' \ + '"PayWithProviderAdvancedNoMessage" ' \ + 'instead of "Paypal2"' end it "returns the default message" do @@ -698,8 +698,8 @@ context "when using must check" do let(:expected_error) do "The \"num\" input on \"CheckMustAdvancedNoMessage\" " \ - "must \"be_smaller\" " \ - "but was 6" + "must \"be_smaller\" " \ + "but was 6" end it "returns the default message" do @@ -710,8 +710,8 @@ context "when using nil check" do let(:expected_error) do - "The \"name\" input on \"CheckNilAdvancedNoMessage\" "\ - "does not allow nil values" + "The \"name\" input on \"CheckNilAdvancedNoMessage\" " \ + "does not allow nil values" end it "returns the default message" do @@ -739,7 +739,8 @@ it do expect { actor }.to raise_error( - ArgumentError, "Expected 1 to be a subclass of Exception" + ArgumentError, + "Expected 1 to be a subclass of Exception", ) end end @@ -753,7 +754,8 @@ it do expect { actor }.to raise_error( - ArgumentError, /Expected .+ to be a subclass of Exception/ + ArgumentError, + /Expected .+ to be a subclass of Exception/, ) end end @@ -767,7 +769,8 @@ it do expect { actor }.to raise_error( - ArgumentError, "Expected 1 to be a subclass of Exception" + ArgumentError, + "Expected 1 to be a subclass of Exception", ) end end @@ -781,7 +784,8 @@ it do expect { actor }.to raise_error( - ArgumentError, /Expected .+ to be a subclass of Exception/ + ArgumentError, + /Expected .+ to be a subclass of Exception/, ) end end @@ -795,7 +799,8 @@ it do expect { actor }.to raise_error( - ArgumentError, "Expected Some string to be a subclass of Exception" + ArgumentError, + "Expected Some string to be a subclass of Exception", ) end end @@ -809,7 +814,8 @@ it do expect { actor }.to raise_error( - ArgumentError, /Expected .+ to be a subclass of Exception/ + ArgumentError, + /Expected .+ to be a subclass of Exception/, ) end end @@ -819,7 +825,7 @@ context "when fail! is not called" do let(:actor) { DoNothing.result } - it { expect(actor).to be_kind_of(ServiceActor::Result) } + it { expect(actor).to be_a(ServiceActor::Result) } it { expect(actor).to be_a_success } it { expect(actor).not_to be_a_failure } end @@ -827,7 +833,7 @@ context "when fail! is called" do let(:actor) { FailWithError.result } - it { expect(actor).to be_kind_of(ServiceActor::Result) } + it { expect(actor).to be_a(ServiceActor::Result) } it { expect(actor).to be_a_failure } it { expect(actor).not_to be_a_success } it { expect(actor.error).to eq("Ouch") } diff --git a/spec/examples/check_must_advanced_no_message.rb b/spec/examples/check_must_advanced_no_message.rb index c317f44..5b1d6cb 100644 --- a/spec/examples/check_must_advanced_no_message.rb +++ b/spec/examples/check_must_advanced_no_message.rb @@ -4,7 +4,7 @@ class CheckMustAdvancedNoMessage < Actor input :num, must: { be_smaller: { - is: -> name { name < 5 } - } + is: -> name { name < 5 }, + }, } end diff --git a/spec/examples/check_nil_advanced_no_message.rb b/spec/examples/check_nil_advanced_no_message.rb index a68a61c..3caa371 100644 --- a/spec/examples/check_nil_advanced_no_message.rb +++ b/spec/examples/check_nil_advanced_no_message.rb @@ -2,7 +2,5 @@ class CheckNilAdvancedNoMessage < Actor input :name, - allow_nil: { - is: false - } + allow_nil: {is: false} end diff --git a/spec/examples/disallow_nil_on_input_advanced.rb b/spec/examples/disallow_nil_on_input_advanced.rb index a84cef8..bd2f196 100644 --- a/spec/examples/disallow_nil_on_input_advanced.rb +++ b/spec/examples/disallow_nil_on_input_advanced.rb @@ -7,7 +7,7 @@ class DisallowNilOnInputAdvanced < Actor is: false, message: (lambda do |input_key:, **| "The value `#{input_key}` cannot be empty" - end) + end), } def call; end diff --git a/spec/examples/double_with_type_as_string_advanced.rb b/spec/examples/double_with_type_as_string_advanced.rb index e38b50f..635b11b 100644 --- a/spec/examples/double_with_type_as_string_advanced.rb +++ b/spec/examples/double_with_type_as_string_advanced.rb @@ -6,8 +6,8 @@ class DoubleWithTypeAsStringAdvanced < Actor is: [Integer, "Float"], message: (lambda do |input_key:, expected_type:, given_type:, **| "Wrong type `#{given_type}` for `#{input_key}`. " \ - "Expected: `#{expected_type}`" - end) + "Expected: `#{expected_type}`" + end), } output :double diff --git a/spec/examples/expected_fail_in_must_when_type_is_first_advanced.rb b/spec/examples/expected_fail_in_must_when_type_is_first_advanced.rb index 06d02cb..ec3c78b 100644 --- a/spec/examples/expected_fail_in_must_when_type_is_first_advanced.rb +++ b/spec/examples/expected_fail_in_must_when_type_is_first_advanced.rb @@ -6,8 +6,8 @@ class ExpectedFailInMustWhenTypeIsFirstAdvanced < Actor must: { be_in_range: { is: -> per_page { per_page >= 3 && per_page <= 9 }, - message: -> value:, ** { "Wrong range (3-9): #{value}" } - } + message: -> value:, ** { "Wrong range (3-9): #{value}" }, + }, } def call; end diff --git a/spec/examples/expected_fail_in_must_when_type_is_last_advanced.rb b/spec/examples/expected_fail_in_must_when_type_is_last_advanced.rb index be47a5b..3ad9782 100644 --- a/spec/examples/expected_fail_in_must_when_type_is_last_advanced.rb +++ b/spec/examples/expected_fail_in_must_when_type_is_last_advanced.rb @@ -5,8 +5,8 @@ class ExpectedFailInMustWhenTypeIsLastAdvanced < Actor must: { be_in_range: { is: -> per_page { per_page >= 3 && per_page <= 9 }, - message: -> value:, ** { "Wrong range (3-9): #{value}" } - } + message: -> value:, ** { "Wrong range (3-9): #{value}" }, + }, }, type: Integer diff --git a/spec/examples/pay_with_provider_advanced.rb b/spec/examples/pay_with_provider_advanced.rb index 547ed83..e18eb74 100644 --- a/spec/examples/pay_with_provider_advanced.rb +++ b/spec/examples/pay_with_provider_advanced.rb @@ -6,7 +6,7 @@ class PayWithProviderAdvanced < Actor in: %w[MANGOPAY PayPal Stripe], message: (lambda do |value:, **| "Payment system \"#{value}\" is not supported" - end) + end), }, default: "Stripe" diff --git a/spec/examples/pay_with_provider_advanced_but_no_default_value.rb b/spec/examples/pay_with_provider_advanced_but_no_default_value.rb index 59118ea..a2c0cbf 100644 --- a/spec/examples/pay_with_provider_advanced_but_no_default_value.rb +++ b/spec/examples/pay_with_provider_advanced_but_no_default_value.rb @@ -6,13 +6,13 @@ class PayWithProviderAdvancedButNoDefaultValue < Actor in: %w[MANGOPAY PayPal Stripe], message: (lambda do |value:, **| "Payment system \"#{value}\" is not supported" - end) + end), }, default: { # value: "Stripe", message: (lambda do |input_key:, **| "Input `#{input_key}` is required" - end) + end), } output :message, type: String diff --git a/spec/examples/pay_with_provider_advanced_no_message.rb b/spec/examples/pay_with_provider_advanced_no_message.rb index 5b824cc..360adfe 100644 --- a/spec/examples/pay_with_provider_advanced_no_message.rb +++ b/spec/examples/pay_with_provider_advanced_no_message.rb @@ -3,6 +3,6 @@ class PayWithProviderAdvancedNoMessage < Actor input :provider, inclusion: { - in: %w[MANGOPAY PayPal Stripe] + in: %w[MANGOPAY PayPal Stripe], } end diff --git a/spec/examples/pay_with_provider_inclusion_advanced.rb b/spec/examples/pay_with_provider_inclusion_advanced.rb index c4a4d29..636a957 100644 --- a/spec/examples/pay_with_provider_inclusion_advanced.rb +++ b/spec/examples/pay_with_provider_inclusion_advanced.rb @@ -6,7 +6,7 @@ class PayWithProviderInclusionAdvanced < Actor in: %w[MANGOPAY PayPal Stripe], message: (lambda do |value:, **| "Payment system \"#{value}\" is not supported" - end) + end), }, default: "Stripe" diff --git a/spec/examples/set_name_with_input_condition.rb b/spec/examples/set_name_with_input_condition.rb index 6ef9d6d..df81d77 100644 --- a/spec/examples/set_name_with_input_condition.rb +++ b/spec/examples/set_name_with_input_condition.rb @@ -4,7 +4,7 @@ class SetNameWithInputCondition < Actor input :name, type: String, must: { - be_lowercase: -> name { name =~ /\A[a-z]+\z/ } + be_lowercase: -> name { name =~ /\A[a-z]+\z/ }, } output :name diff --git a/spec/examples/set_name_with_input_condition_advanced.rb b/spec/examples/set_name_with_input_condition_advanced.rb index 8d10ced..fcf07dc 100644 --- a/spec/examples/set_name_with_input_condition_advanced.rb +++ b/spec/examples/set_name_with_input_condition_advanced.rb @@ -8,8 +8,8 @@ class SetNameWithInputConditionAdvanced < Actor is: -> name { name =~ /\A[a-z]+\z/ }, message: (lambda do |check_name:, **| "Failed to apply `#{check_name}`" - end) - } + end), + }, } output :name diff --git a/spec/examples/set_wrong_type_of_output_advanced.rb b/spec/examples/set_wrong_type_of_output_advanced.rb index 7ec53a0..d459bcb 100644 --- a/spec/examples/set_wrong_type_of_output_advanced.rb +++ b/spec/examples/set_wrong_type_of_output_advanced.rb @@ -6,8 +6,8 @@ class SetWrongTypeOfOutputAdvanced < Actor is: String, message: (lambda do |input_key:, expected_type:, given_type:, **| "Wrong type `#{given_type}` for `#{input_key}`. " \ - "Expected: `#{expected_type}`" - end) + "Expected: `#{expected_type}`" + end), } def call self.name = 42 diff --git a/spec/examples/validate_weekdays.rb b/spec/examples/validate_weekdays.rb index d2aff9c..01adc24 100644 --- a/spec/examples/validate_weekdays.rb +++ b/spec/examples/validate_weekdays.rb @@ -10,7 +10,7 @@ class ValidateWeekdays < Actor must: { be_valid: lambda do |numbers| numbers.nil? || numbers.all? { |number| (0..6).cover?(number) } - end + end, } def call; end diff --git a/spec/service_actor_spec.rb b/spec/service_actor_spec.rb index c6e6540..202eb43 100644 --- a/spec/service_actor_spec.rb +++ b/spec/service_actor_spec.rb @@ -2,6 +2,6 @@ RSpec.describe ServiceActor do it "does not raise on eager load" do - Zeitwerk::Loader.eager_load_all + expect { Zeitwerk::Loader.eager_load_all }.not_to raise_error end end