Skip to content

alternative approach to avoid instance variable and success? condition #102

@andriytyurnikov

Description

@andriytyurnikov

Hi guys. Impressive work with mutations
Typical usecase for Command is

outcome = UserSignup.run(params)
if outcome.success?
  user = outcome.result
else
  render outcome.errors
end

...and what we may notice, is the only reason for having boolean attribute success? is to write if for it,
and the only reason to have outcome variable is to call success? on it

UserSignup
  .run(params)
  .on_success { |outcome| @user = outcome.user }
  .on_failure { |outcome| render outcome.errors }

And by using call method syntactical sugar we may get even sexier stuff

UserSignup.(params)
  .on_success { |outcome| @user = outcome.user }
  .on_failure { |outcome| render outcome.errors }

This success procs thing may be in parallel with usual success?
What do you think?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions