Skip to content

ActiveRecord integration design #1

Closed
@geekq

Description

@geekq

The goals are:

  • to support different ActiveRecord versions at the same time
  • to enable further development without regressions (without breaking applications using different versions of ActiveRecord)
  • convenience

For that we need

  • to have clear responsibilities for workflow and workflow-activerecord (separation of concerns)
  • single direction for dependencies

Plan is: workflow would contain changes to DSL defining the states and events, and workflow-activerecord would depend on particular ActiveRecord API

+------------------+     +-----------------------+
|    workflow      <-----+ workflow-activerecord |
+------------------+     +------+----------------+
                                |
                                |
+------------------+            |
| ActiveRecord     <------------+
+------------------+

We 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

gem 'workflow-activerecord', '>= 4.1', '< 6.0'

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

gem 'workflow-activerecord', '~> 5.2'

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:

gem 'workflow-activerecord', '>= 4.2', '< 6.0'

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

gem 'workflow', '~> 2.0'
gem 'workflow-activerecord', '>= 4.2', '< 6.0'

require

In Rails you do not need to write require nowadays since it uses require 'bundler/setup' and always requires everything?

include

Option 1. Multiple includes

class Article < ApplicationRecord
  include Workflow
  include WorkflowActiverecord
  workflow do
    # list states and transitions here
  end

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?

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