Module: Rigor::Effects::MethodKey

Defined in:
lib/rigor/effects/method_key.rb

Overview

The spelling of an effect unit's key, in one place (ADR-103 WD14).

Owner#instance_method, Owner.singleton_method, <toplevel>#bare_def. The separator is the FIRST # or . in the string, which is what makes Net::HTTP.get split at the dot rather than inside the namespace — a namespace carries ::, never a bare dot, and a selector carries neither.

This module exists because the split is now written on both sides of a contract: the scanner spells a key, and effects.attribution: in .rigor.yml names one. A key the loader accepts and the scanner would never produce is a table that silently matches nothing.

Class Method Summary collapse

Class Method Details

.owner(key) ⇒ Object

The owner half, or nil. What keys_by_class-shaped groupings ask for.



35
36
37
# File 'lib/rigor/effects/method_key.rb', line 35

def owner(key)
  split(key)&.first
end

.split(key) ⇒ Array(String, String, String)?

Returns [owner, separator, selector], or nil when key is not a method key at all.

Returns:

  • (Array(String, String, String), nil)

    [owner, separator, selector], or nil when key is not a method key at all.



19
20
21
22
23
24
25
# File 'lib/rigor/effects/method_key.rb', line 19

def split(key)
  text = key.to_s
  index = text.index("#") || text.index(".")
  return nil if index.nil? || index.zero? || index == text.length - 1

  [text[0, index], text[index], text[(index + 1)..]]
end

.valid?(key) ⇒ Boolean

Returns:

  • (Boolean)


27
28
29
30
31
32
# File 'lib/rigor/effects/method_key.rb', line 27

def valid?(key)
  parts = split(key)
  return false if parts.nil?

  parts.none? { |part| part.match?(/\s/) }
end