Skip to content

Commit

Permalink
Change protected visibility to private
Browse files Browse the repository at this point in the history
  • Loading branch information
bdewater-thatch committed May 30, 2024
1 parent b009a7b commit 5d0cc6b
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class CreateUser < SorbetOperation::Base
@user_params = user_params
end

protected
private

sig { returns(ValueType) }
def execute
Expand Down Expand Up @@ -71,7 +71,7 @@ An operation is a Ruby class that derives from `SorbetOperation::Base`. `SorbetO
1. define the return type using the `ValueType` generic type member
2. define an `#execute` method that returns a `ValueType`

The `#execute` method should be `protected` or `private`, since it is not meant to be invoked directly; rather, operation callers should use the `#perform` public method to actually perform the operation. (Unfortunately, at this time there is no mechanism to enforce that `#execute` is not a public method on child classes, so it's up to the programmer to be vigilant.)
The `#execute` method should be `private`, since it is not meant to be invoked directly; rather, operation callers should use the `#perform` public method to actually perform the operation. (Unfortunately, at this time there is no mechanism to enforce that `#execute` is not a public method on child classes, so it's up to the programmer to be vigilant.)

The `#execute` method does not take any arguments. Most operations require one or more input values. Input values should be passed to the `#initialize` constructor method and stored as instance variables, which can then be accessed from the `#execute` body.

Expand Down
4 changes: 2 additions & 2 deletions lib/sorbet_operation/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ def perform
sig { params(logger: ::Logger).void }
attr_writer :logger

protected
private

# Implement this method in subclasses to perform the operation.
#
Expand All @@ -70,7 +70,7 @@ def perform
# exception. The exception will not be caught and will be propagated to
# the caller.
#
# This method should be declared as `protected` in subclasses to prevent
# This method should be declared as `private` in subclasses to prevent
# callers from calling it directly. Callers should instead call {#perform}
# to perform the operation and get the result.
sig { abstract.returns(ValueType) }
Expand Down
2 changes: 1 addition & 1 deletion test/sorbet_operation/base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def initialize(dividend, divisor)
@divisor = divisor
end

protected
private

sig { override.returns(Float) }
def execute
Expand Down

0 comments on commit 5d0cc6b

Please sign in to comment.