-
Notifications
You must be signed in to change notification settings - Fork 13
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
ActiveRecord integration design #1
Comments
@geekq Looks good. I have two comments/suggestions. Dependency ManagementI'd encourage leveraging the built-in dependency management that You can't really support Now users who wish to use This also eliminates the need for the user to specify—redundantly—both A user will have already specified Let me know if I did a poor job of explaining that. ActivationGiven the incredibly simple entry-point for P.S. I recommend snagging |
Gem Dependency ManagementI've created a sample application https://github.com/geekq/workflow-rails-sample Gem/bundler patterns and prerelease support work quite well! I was hesitating Now I am happy with:
And just in case, the developer of an application can still put 2 Gems released as:
Next step: Activation. Currently requires 2 includes, but will try out your suggestion on Thursday @voltechs |
Single `include WorkflowActiverecord` as considered in geekq/workflow-activerecord#1
I am hesitating with a magic workflow activation for every model @voltechs
The Scopes extension would also need to be adjusted since
At least, I've just reduces number of includes from 2 to 1 742b124 |
I totally understand that perspective. I have a couple tricks that I use to keep it relatively clean. Essentially what I do is I include one method onto Anyhow, looks like you're making good progress! Looking forward to module Core
# all your goodies
end
module Base
def self.workflow(*args, &block)
self.prepend(Workflow::Core) unless ancestors.include?(Workflow::Core)
Workflow::Core.workflow(*args, &block)
end
end |
In the real use case, out of, say 10 active model files, a one or two are going to use workflow. I would stick to Please have a look at |
Will stick with |
The goals are:
For that we need
workflow
andworkflow-activerecord
(separation of concerns)Plan is:
workflow
would contain changes to DSL defining the states and events, andworkflow-activerecord
would depend on particular ActiveRecord APIWe have some design options to choose from. Once chosen, it would be hard to change without breaking things. I've highlighted my current preference in bold.
Versioning workflow-activerecord gems
Imagine, Rails 6.0 brings some incompatible API changes. Think something like
protected_attributes
;-) In this case workflow-activerecord for 4.1, 4.2, 5.0, 5.1, 5.2 would be based on the same code base, while workflow-activerecord for ActiveRecord 6.0 would require different implementation.Option 1. Release workflow-activerecord version only when it's code base changes.
Easy to build/release. Harder to reference the right version. If your application is for Rails 5.2, use
Option 2. Release workflow-activerecord version for every ActiveRecord version.
Makes easy for users to reference the right version. If your application is for Rails 5.2, use
But more work to release. Multiple versions, that are binary equal.
Referencing Gems
Option 1. workflow-activerecord defines dependency on workflow itself so user
just needs a single line:
But which version of workflow should workflow-activerecord depend on? Latest? Some particular?
Consider this article about the differences in dependency versions for libraries vs. applications. https://yehudakatz.com/2010/12/16/clarifying-the-roles-of-the-gemspec-and-gemfile/
Option 2. User to write both dependencies in her Gemfile
require
In Rails you do not need to write
require
nowadays since it usesrequire 'bundler/setup'
and always requires everything?include
Option 1. Multiple includes
Option 2. Single
include Workflow
When used in conjunction with workflow-activerecord and used inside a class inheriting from
ApplicationRecord, modify the behaviour of
include Workflow
to also activate the persistence.But this is probably too much magic
Option 3. Single
include WorkflowActiverecord
Probably the best trade-off the explicitness and convinience.
@voltechs What do you think?
The text was updated successfully, but these errors were encountered: