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

chore(invokers): Refactor callback invokers, add class-callbacks support #541

Merged
merged 2 commits into from
Jul 30, 2018

Conversation

pandomic
Copy link
Contributor

@pandomic pandomic commented Mar 18, 2018

Motivation

While working on a big project we faced with a problem - our models started to grow, we needed to make a huge processing on state/transition/event callbacks, and keeping that logic in procs or in a model methods was not a good solution for us. Currently we are using a monkey-patched version of invoking logic to add a class-callbacks support. But I guess there also might be people who faced the same problem and need this feature supported officially.

While diving into the AASM code we found that invoking logic is mostly duplicated, so we decided to extract duplicated parts and add a class-callbacks support.

Related issue: #503

A few words about PR

PR contains base invoking class and concrete invokers for each subject type (Proc, Literal, Class). Base invoker decides which concrete invoker to use and also takes some additional configuration to support states/events/transitions (as they may have some differences in default return values, options and etc.)

Breaking changes

  • To be convenient, state proc-callbacks are now executed in a record's context as well.

@anilmaurya
Copy link
Member

Hi @pandomic .

Thank you for raising this PR. I will go through changes over the coming weekend.

@anilmaurya
Copy link
Member

@alto Need your review on this. Can you have a look once ?

@alto
Copy link
Member

alto commented Jun 11, 2018

@anilmaurya Sure.

@alto alto self-assigned this Jun 11, 2018
Copy link
Member

@alto alto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pandomic Great pull request with awesome changes (enhancements)! Only thing to change please is the rubocop introduction. Otherwise 👍

I wonder if we need to update the README...

aasm.gemspec Outdated
@@ -23,6 +23,7 @@ Gem::Specification.new do |s|
s.add_development_dependency 'rspec', ">= 3"
s.add_development_dependency 'generator_spec'
s.add_development_dependency 'appraisal'
s.add_development_dependency 'rubocop'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please not. If you really think we benefit from rubocop, feel free to open a pull request just for that. But it's off-topic for this one.

@@ -13,7 +15,13 @@ def initialize(name, klass, state_machine, options={})
def initialize_copy(orig)
super
@options = {}
orig.options.each_pair { |name, setting| @options[name] = setting.is_a?(Hash) || setting.is_a?(Array) ? setting.dup : setting }
orig.options.each_pair do |name, setting|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reformatted to make easier to read 👍

@pandomic
Copy link
Contributor Author

Thank you guys, will try to make some updates during the weekend

@pandomic pandomic force-pushed the chores/refactor-callback-invokers branch from dfb968b to e43b874 Compare June 19, 2018 18:12
@pandomic
Copy link
Contributor Author

Hey @alto, please take a look one more time when you will have some time ;)

@alto
Copy link
Member

alto commented Jul 10, 2018

@pandomic Looks good now. Cheers!

@anilmaurya
Copy link
Member

@pandomic Can you please resolve conflicts ?

@anilmaurya anilmaurya merged commit 89544e5 into aasm:master Jul 30, 2018
@anilmaurya
Copy link
Member

Hi @pandomic ,

Thank you for your contribution.
I have merged your PR and released AASM 5.0.0 .
🏅🏆

@pandomic
Copy link
Contributor Author

Hi @anilmaurya, thank you a lot! Sorry, had no time to resolve conflicts, hope there was not too many

@tisba
Copy link
Contributor

tisba commented Jul 30, 2018

Nice change 👍

Just a quick question: LogRunTime is now defined twice in the readme (https://github.com/aasm/aasm#callbacks). Is this an oversight or is this to show a special behaviour? Sorry if this might be a stupid questions, I'm trying to wrap my head around this :)

@pandomic
Copy link
Contributor Author

oh, yeah, looks like the first one is not needed anymore, as the second one explains behavior a bit more in detail

@anilmaurya
Copy link
Member

anilmaurya commented Jul 31, 2018

@tisba Thanks for pointing it out. 👍
Fixed it.

@pandomic pandomic deleted the chores/refactor-callback-invokers branch September 3, 2018 14:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants