Skip to content

Commit 23c3b17

Browse files
authored
fix wrong constant name in chain (#40)
* add spec replicating problem with anonymous constants in chains * replace compact_blank with reject(&:blank?) * add changelog entry
1 parent cd20be0 commit 23c3b17

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## [Unreleased]
22
- Add support for `Interactify.with(queue: 'within_30_seconds', retry: 3)`
3+
- Fix issue with anonymous classes not being able to be used in chains
34

45
## [0.5.0] - 2024-01-01
56
- Add support for `SetA = Interactify { _1.a = 'a' }`, lambda and block class creation syntax

lib/interactify/dsl/unique_klass_name.rb

+3-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ module UniqueKlassName
66
module_function
77

88
def for(namespace, prefix, camelize: true)
9+
prefix = "AnonymousModule" if prefix.is_a?(Module) && prefix.anonymous?
10+
911
prefix = normalize_prefix(prefix:, camelize:)
1012
klass_name = name_with_suffix(namespace, prefix, nil)
1113

@@ -17,7 +19,7 @@ def for(namespace, prefix, camelize: true)
1719
end
1820

1921
def name_with_suffix(namespace, prefix, suffix)
20-
name = [prefix, suffix].compact.join("_")
22+
name = [prefix.to_s, suffix.to_s].reject(&:blank?).join("_")
2123

2224
return nil if namespace.const_defined?(name.to_sym)
2325

spec/integration/all_the_things_integration_spec.rb

+22
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,26 @@
5252
expect(result.heavily_nested_counter).to eq 256
5353
end
5454
end
55+
56+
context "with anonymous classes in chains" do
57+
self::SomeInteractor = Class.new do |klass|
58+
include Interactify
59+
anonymous_thing = Interactify { context.problem = "problem happens here" }
60+
61+
klass::A = Interactify { _1.a = "A" }
62+
klass::B = Interactify { _1.b = "B" }
63+
klass::C = Interactify { _1.c = "C" }
64+
65+
klass::SomeChain = chain(
66+
anonymous_thing,
67+
klass::A,
68+
klass::B,
69+
klass::C
70+
)
71+
end
72+
73+
it "does not raise an error" do
74+
expect { self.class::SomeInteractor::SomeChain.call! }.not_to raise_error
75+
end
76+
end
5577
end

0 commit comments

Comments
 (0)