File tree Expand file tree Collapse file tree 10 files changed +69
-26
lines changed
Expand file tree Collapse file tree 10 files changed +69
-26
lines changed Original file line number Diff line number Diff line change 22
33require "zeitwerk"
44
5- require "active_support/all"
6-
75loader = Zeitwerk ::Loader . for_gem
86loader . ignore ( "#{ __dir__ } /stroma/test_kit/rspec" )
97loader . inflector . inflect (
Original file line number Diff line number Diff line change @@ -82,30 +82,14 @@ def included(base)
8282 const_set ( :ClassMethods , class_methods )
8383 end
8484
85- label_module ( mod , "Stroma::DSL(#{ matrix . name } )" )
86- label_module ( class_methods , "Stroma::DSL(#{ matrix . name } )::ClassMethods" )
85+ Utils . name_module ( mod , "Stroma::DSL(#{ matrix . name } )" )
86+ Utils . name_module ( class_methods , "Stroma::DSL(#{ matrix . name } )::ClassMethods" )
8787
8888 mod
8989 end
9090
9191 private
9292
93- # Assigns a descriptive label to an anonymous module for debugging.
94- # Uses set_temporary_name (Ruby 3.3+) when available.
95- #
96- # TODO: Remove the else branch when Ruby 3.2 support is dropped.
97- # The define_singleton_method fallback is a temporary workaround
98- # that only affects #inspect and #to_s. Unlike set_temporary_name,
99- # it does not set #name, so the module remains technically anonymous.
100- def label_module ( mod , label )
101- if mod . respond_to? ( :set_temporary_name )
102- mod . set_temporary_name ( label )
103- else
104- mod . define_singleton_method ( :inspect ) { label }
105- mod . define_singleton_method ( :to_s ) { label }
106- end
107- end
108-
10993 # Builds the ClassMethods module.
11094 #
11195 # @return [Module] The ClassMethods module
Original file line number Diff line number Diff line change @@ -46,7 +46,7 @@ module Hooks
4646 # @param extension [Module] Extension module to include
4747 # @raise [Exceptions::InvalidHookType] If type is invalid
4848 def initialize ( type :, target_key :, extension :)
49- if VALID_HOOK_TYPES . exclude ?( type )
49+ unless VALID_HOOK_TYPES . include ?( type )
5050 raise Exceptions ::InvalidHookType ,
5151 "Invalid hook type: #{ type . inspect } . Valid types: #{ VALID_HOOK_TYPES . map ( &:inspect ) . join ( ', ' ) } "
5252 end
Original file line number Diff line number Diff line change @@ -70,6 +70,7 @@ def finalize!
7070 return if @finalized
7171
7272 @entries . freeze
73+ @keys = @entries . map ( &:key ) . freeze
7374 @finalized = true
7475 end
7576
@@ -88,7 +89,7 @@ def entries
8889 # @return [Array<Symbol>] The registry keys
8990 def keys
9091 ensure_finalized!
91- @entries . map ( & :key )
92+ @keys
9293 end
9394
9495 # Checks if a key is registered.
@@ -98,7 +99,7 @@ def keys
9899 # @return [Boolean] true if the key is registered
99100 def key? ( key )
100101 ensure_finalized!
101- @entries . any? { | e | e . key == key . to_sym }
102+ @keys . include? ( key . to_sym )
102103 end
103104
104105 private
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ module Stroma
4+ # Shared utility methods for the Stroma framework.
5+ #
6+ # ## Purpose
7+ #
8+ # Provides common helper methods used across multiple Stroma components.
9+ # All methods are module functions - callable as both module methods
10+ # and instance methods when included.
11+ module Utils
12+ module_function
13+
14+ # Assigns a temporary name to an anonymous module for debugging clarity.
15+ # Uses set_temporary_name (Ruby 3.3+) when available.
16+ #
17+ # TODO: Remove the else branch when Ruby 3.2 support is dropped.
18+ # The define_singleton_method fallback is a temporary workaround
19+ # that only affects #inspect and #to_s. Unlike set_temporary_name,
20+ # it does not set #name, so the module remains technically anonymous.
21+ #
22+ # @param mod [Module] The module to name
23+ # @param name [String] The temporary name
24+ # @return [void]
25+ def name_module ( mod , name )
26+ if mod . respond_to? ( :set_temporary_name )
27+ mod . set_temporary_name ( name )
28+ else
29+ mod . define_singleton_method ( :inspect ) { name }
30+ mod . define_singleton_method ( :to_s ) { name }
31+ end
32+ end
33+ end
34+ end
Original file line number Diff line number Diff line change @@ -11,8 +11,6 @@ module Stroma
1111
1212 private
1313
14- def label_module : (Module mod, String label) -> void
15-
1614 def build_class_methods : () -> Module
1715 end
1816 end
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ module Stroma
22 class Registry
33 @matrix_name: Symbol
44 @entries: Array[Entry]
5+ @keys: Array[Symbol]
56 @finalized: bool
67
78 attr_reader matrix_name: Symbol
Original file line number Diff line number Diff line change 1+ module Stroma
2+ module Utils
3+ def self.name_module : (Module mod, String name) -> void
4+
5+ private
6+
7+ def name_module : (Module mod, String name) -> void
8+ end
9+ end
Original file line number Diff line number Diff line change 1+ # frozen_string_literal: true
2+
3+ RSpec . describe Stroma ::Utils do
4+ describe ".name_module" do
5+ let ( :mod ) { Module . new }
6+ let ( :name ) { "Stroma::Test(example)" }
7+
8+ before { described_class . name_module ( mod , name ) }
9+
10+ it "sets inspect to the name" do
11+ expect ( mod . inspect ) . to eq ( name )
12+ end
13+
14+ it "sets to_s to the name" do
15+ expect ( mod . to_s ) . to eq ( name )
16+ end
17+ end
18+ end
Original file line number Diff line number Diff line change 11# frozen_string_literal: true
22
33RSpec . describe Stroma ::VERSION do
4- it { expect ( Stroma ::VERSION ::STRING ) . to be_present }
4+ it { expect ( Stroma ::VERSION ::STRING ) . not_to be_nil }
55end
You can’t perform that action at this time.
0 commit comments