Skip to content

Commit

Permalink
🎨 Disambiguated class method log output call separator
Browse files Browse the repository at this point in the history
- `.` => `::`, because `.` is ambiguous; same call syntax used for instance method calls
  • Loading branch information
pboling committed Feb 28, 2024
1 parent 26199d3 commit e69c848
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 52 deletions.
1 change: 1 addition & 0 deletions .github/workflows/heads.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ jobs:
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile
runs-on: ubuntu-latest
strategy:
fail-fast: true
matrix:
rubygems:
- latest
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
rubocop:
name: RuboCop
strategy:
fail-fast: falsebest
fail-fast: false
matrix:
experimental: [true]
rubygems:
Expand Down
10 changes: 5 additions & 5 deletions .rubocop_gradual.lock
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"README.md:2883386112": [
"README.md:3009712128": [
[240, 10, 27, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 2226893134],
[243, 3, 37, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 4163348045],
[247, 3, 37, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 2420123939],
Expand Down Expand Up @@ -38,7 +38,7 @@
[62, 9, 5, "Style/IdenticalConditionalBranches: Move `proxy` out of the conditional.", 187023241],
[77, 9, 5, "Style/IdenticalConditionalBranches: Move `proxy` out of the conditional.", 187023241]
],
"lib/simple_debug_logging.rb:1392172319": [
"lib/simple_debug_logging.rb:1035783295": [
[71, 5, 688, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 790702810]
],
"spec/debug_logging/argument_printer_spec.rb:2145628744": [
Expand All @@ -48,7 +48,7 @@
[111, 9, 193, "RSpec/VerifiedDoubles: Prefer using verifying doubles over normal doubles.", 3607462793],
[128, 9, 189, "RSpec/VerifiedDoubles: Prefer using verifying doubles over normal doubles.", 449370282]
],
"spec/debug_logging/class_logger_spec.rb:989837610": [
"spec/debug_logging/class_logger_spec.rb:1162338474": [
[4, 11, 14, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 3715557109],
[6, 53, 7, "RSpec/MessageSpies: Prefer `have_received` for setting message expectations. Setup `complete_logged_klass.debug_config` as a spy using `allow` or `instance_spy`.", 1384559950],
[16, 14, 7, "RSpec/MessageSpies: Prefer `have_received` for setting message expectations. Setup `complete_logged_klass.instance_variable_get(DebugLogging::Configuration.config_pointer(\n \"kl\",\n :k_with_dsplat,\n ))` as a spy using `allow` or `instance_spy`.", 1384559950],
Expand Down Expand Up @@ -85,7 +85,7 @@
[251, 14, 7, "RSpec/InstanceVariable: Avoid instance variables - use let, a method call, or a local variable (if possible).", 289916282],
[292, 14, 7, "RSpec/InstanceVariable: Avoid instance variables - use let, a method call, or a local variable (if possible).", 289916282]
],
"spec/debug_logging/configuration_spec.rb:318728313": [
"spec/debug_logging/configuration_spec.rb:126485881": [
[7, 11, 8, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 4105806927],
[8, 13, 25, "RSpec/ContextWording: Context description should match /^when\\b/, /^with\\b/, or /^without\\b/.", 3996754496],
[9, 7, 20, "RSpec/NestedGroups: Maximum example group nesting exceeded [4/3].", 1551745841],
Expand Down Expand Up @@ -227,7 +227,7 @@
[248, 7, 11, "RSpec/InstanceVariable: Avoid instance variables - use let, a method call, or a local variable (if possible).", 2247037282],
[257, 7, 11, "RSpec/InstanceVariable: Avoid instance variables - use let, a method call, or a local variable (if possible).", 2247037282]
],
"spec/debug_logging/instance_logger_spec.rb:242382582": [
"spec/debug_logging/instance_logger_spec.rb:1603668164": [
[101, 31, 7, "RSpec/MessageSpies: Prefer `have_received` for setting message expectations. Setup `output` as a spy using `allow` or `instance_spy`.", 1384559950],
[200, 27, 7, "RSpec/MessageSpies: Prefer `have_received` for setting message expectations. Setup `logger` as a spy using `allow` or `instance_spy`.", 1384559950]
],
Expand Down
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- `notifies` => `notified`
- Instance method DSL renamed:
- `i_notifies` => `i_notified`
- Disambiguated class method log output send message separator:
- `.` => `::`, because `.` is ambiguous; same call syntax used for instance method calls
### Fixed
- Per method config for every decorated method
### Removed
Expand Down
2 changes: 1 addition & 1 deletion lib/debug_logging/class_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def logged(*methods_to_log)
paydirt = DebugLogging::Util.payload_instance_variable_hydration(scope: self, payload: method_payload)
log_prefix = debug_invocation_to_s(
klass: to_s,
separator: ".",
separator: "::",
method_to_log: method_to_log,
config_proxy: config_proxy,
)
Expand Down
4 changes: 2 additions & 2 deletions lib/simple_debug_logging.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ def logged(*methods_to_log)
define_method(method_to_log.to_sym) do |*args|
method_return_value = nil
invocation_id = " ~#{args.object_id}@#{Time.now.to_i}~" if args
puts "#{self}.#{method_to_log}(#{args.map(&:inspect).join(", ")})#{invocation_id}"
puts "#{self}::#{method_to_log}(#{args.map(&:inspect).join(", ")})#{invocation_id}"
elapsed = Benchmark.realtime do
method_return_value = original_method.call(*args)
end
puts "#{self}.#{method_to_log} ~#{args.hash}~ complete in #{elapsed}s#{invocation_id}"
puts "#{self}::#{method_to_log} ~#{args.hash}~ complete in #{elapsed}s#{invocation_id}"
method_return_value
end
end
Expand Down
12 changes: 6 additions & 6 deletions spec/debug_logging/class_logger_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
output = capture("stdout") do
complete_logged_klass.k_with_dsplat(a: "a")
end
expect(output).to match(/.*\.k_with_dsplat/)
expect(output).to match(/.*::k_with_dsplat/)
# Can't set an expectation on the per class method config until after the method has been called once, as that is when the ivar gets set.
# Without an options hash the class config is the same config object as the per method config
expect(complete_logged_klass.instance_variable_get(DebugLogging::Configuration.config_pointer(
Expand All @@ -23,7 +23,7 @@
output = capture("stdout") do
complete_logged_klass.k_with_dsplat_i(a: "a")
end
expect(output).to match(/\.k_with_dsplat_i\(LOLiii\)/)
expect(output).to match(/::k_with_dsplat_i\(LOLiii\)/)
# Can't set an expectation on the per class method config until after the method has been called once, as that is when the ivar gets set.
expect(complete_logged_klass.instance_variable_get(DebugLogging::Configuration.config_pointer(
"kl",
Expand All @@ -38,7 +38,7 @@
output = capture("stdout") do
complete_logged_klass.k_with_dsplat_e(a: "a")
end
expect(output).to match(/.*0;31;49m#<Class.*0m\.k_with_dsplat_e\(LOLeee\)/)
expect(output).to match(/.*0;31;49m#<Class.*0m::k_with_dsplat_e\(LOLeee\)/)
# Can't set an expectation on the per class method config until after the method has been called once, as that is when the ivar gets set.
expect(complete_logged_klass.instance_variable_get(DebugLogging::Configuration.config_pointer(
"kl",
Expand All @@ -65,9 +65,9 @@
expect(output).to match(/#i\(\*\*{}\)/)
expect(output).to match(/#i_with_ssplat\(\*\*{}\)/)
expect(output).to match(/#.*0;31;49mi_with_dsplat.*0m\(\*\*{}\)/)
expect(output).to match(/\.k\(\)/)
expect(output).to match(/\.k_with_ssplat\(\)/)
expect(output).to match(/\.k_with_dsplat\(\)/)
expect(output).to match(/::k\(\)/)
expect(output).to match(/::k_with_ssplat\(\)/)
expect(output).to match(/::k_with_dsplat\(\)/)
end

it "has correct return value" do
Expand Down
Loading

0 comments on commit e69c848

Please sign in to comment.