sunny / actor

Composable Ruby service objects
MIT License
714 stars 29 forks source link

Actor's output names collision with `Object`'s instance methods #137

Closed viralpraxis closed 7 months ago

viralpraxis commented 8 months ago
class OutputWithBlacklistedName < Actor
  input :value, type: Integer

  output :object_id, type: Integer

  play -> actor { actor.object_id = actor.value.succ }
end

OutputWithBlacklistedName.call(value: 1).object_id != 2

Before https://github.com/sunny/actor/pull/127 object_id would be correctly set (I doubt that overriding object_id is a good idea though).

One possible solution is to inherit Result from BasicObject and explicitly disallow output names that collide with Result.instance_methods

viralpraxis commented 8 months ago

Inheriting from BasicObject might be a bit too much šŸ™‚ I guess we can simply raise (on class loading) if someone defines input :object_id or similiar @sunny ?

sunny commented 8 months ago

Yeah it would add a bit of safety to prevent things we think might be a dangerous name to override now (success, failure for example), fails for now (object_id for example), or that we know will cause chaos today (overriding call or any other internal method).

Iā€™d be happy to accept a PR for that šŸ‘šŸ»