Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Repetetive DSL in some cases with separate after_transition vs. including do: in the transition #15

Open
rosskevin opened this issue Apr 20, 2015 · 3 comments

Comments

@rosskevin
Copy link
Member

It appears that I cannot specify do: on a transition definition such as

      event :expire do
        transition :active => :expired, do: :process_superceded, if: [:has_next?, :ended?]
        transition :trial => :trial_expired, do: :process_trial_expiration, if: :ended?
        transition :active => :grace, do: :process_grace, if: :within_grace_period?
        transition [:active, :grace] => :expired, do: :process_expired, if: :exceeded_grace_period?
      end

If that's the case, I'll have to copy a very similar block to create after_transitions. This appears to be the only way:

      event :expire do
        transition :active => :expired, if: [:has_next?, :ended?]
        transition :trial => :trial_expired, if: :ended?
        transition :active => :grace, if: :within_grace_period?
        transition [:active, :grace] => :expired, if: :exceeded_grace_period?
      end

      after_transition :active => :expired, do: :process_superceded
      after_transition :trial => :trial_expired
      after_transition :active => :grace, do: :process_grace
      after_transition [:active, :grace] => :expired

This seems quite verbose and prone to error upon changes since I'm explicitly mirroring state transitions defined above. Am I correct in my understanding? Is there a reason not to allow do: on the transition?

Actually, there's a nuance that I can capture with the desired syntax, that I haven't with the second syntax: only run process_superceded when [:has_next?, :ended?], so do I need to copy those conditions too? The unexpected behavior comes with the potential for :active => :expired without meeting those conditions.

@rosskevin
Copy link
Member Author

This is a potential enhancement if others like the idea, or we can close this. I'd rather not have the repetetive DSL, yet I'm not too motivated by the issue to dive in and write code to solve it.

@gagalago
Copy link
Contributor

I love this idea.

But for now, I learn this gem syntax. So I will not write a pull request shortly.

@jponc
Copy link

jponc commented Feb 20, 2018

Yeah I think this is a nice idea.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants