Skip to content

Commit

Permalink
Allow chainable actor-like objects to be basic
Browse files Browse the repository at this point in the history
  • Loading branch information
viralpraxis committed Nov 28, 2024
1 parent 5071274 commit 438a578
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/service_actor/playable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,15 @@ def callable_actor?(options)
end

def play_actor(actor)
if actor.is_a?(Symbol)
actor_includes_kernel = begin
actor.respond_to?(:is_a?)
rescue NoMethodError
false
end

if !actor_includes_kernel
actor.call(result)
elsif actor.is_a?(Symbol)
send(actor)
elsif actor.is_a?(Class) && actor.ancestors.include?(ServiceActor::Core)
play_service_actor(actor)
Expand Down
33 changes: 33 additions & 0 deletions spec/actor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1491,4 +1491,37 @@ def match_result(result)
expect(result.error).to start_with('The "value" input on')
end
end

context "when actor inherits from `BasicObject`" do
t = Class.new(BasicObject) do
class << self
def [](attribute, value)
new(attribute, value)
end
end

def initialize(attribute, value)
@attribute, @value = attribute, value
end

def call(actor)
actor.__send__(:"#{@attribute}=", @value)
end
end

let(:actor) do
Class.new(Actor) do
output :value, type: Integer

play t[:value, 42]
end
end

it "does not raise" do
result = actor.result

expect(result).to be_a_success
expect(result.value).to eq(42)
end
end
end

0 comments on commit 438a578

Please sign in to comment.