https://github.com/trailblazer/trailblazer-compat
This gem provides a seamless-er™ upgrade from TRB 1.1 to 2.x.
https://github.com/trailblazer/trailblazer-compat
Last synced: 5 months ago
JSON representation
This gem provides a seamless-er™ upgrade from TRB 1.1 to 2.x.
- Host: GitHub
- URL: https://github.com/trailblazer/trailblazer-compat
- Owner: trailblazer
- Created: 2016-10-23T06:13:55.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2018-11-11T18:11:23.000Z (about 7 years ago)
- Last Synced: 2025-05-07T20:42:21.189Z (7 months ago)
- Language: Ruby
- Homepage: http://trailblazer.to/gems/trailblazer/upgrading-1-to-2.html
- Size: 38.1 KB
- Stars: 10
- Watchers: 4
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGES.md
Awesome Lists containing this project
README
# Trailblazer::Compat
[](https://badge.fury.io/rb/trailblazer-compat)
This gem provides a seamless-er™ upgrade from TRB 1.1 to 2.x.
It allows to run both old TRB 1.1 operations along with new or refactored 2.x code in the same application, making it easier to upgrade operation code `step`-wise (no pun intended!) or add new TRB2 operations, workflows, etc. without having to change the old code.
## Installation
Your exisiting application's `Gemfile` should point to the new `trailblazer` gem.
```ruby
gem "trailblazer", ">= 2.0.6"
gem "trailblazer-compat"
```
In a Rails application, you also need to pull the 1.x line of the `trailblazer-rails` gem.
```ruby
gem "trailblazer-rails", ">= 1.0.3"
```
## Upgrade Path / Overview
The complete migration path is [documented here](http://trailblazer.to/gems/trailblazer/upgrading-1-to-2.html).
1. You can keep old TRB1 operations.
```ruby
# /app/concepts/song/create.rb
class Song
class Create < Trailblazer::Operation
model Song, :create
policy Song::Policy, :admin?
contract do
property :id
# ...
end
def process(params)
validate(params[:song]) do |form|
form.save
end
end
end
end
```
2. At any point, you can introduce new TRB2 operations or update old classes by inheriting from `Trailblazer::Operation.version(2)`.
```ruby
# /app/concepts/song/create.rb
class Song
class Create < Trailblazer::Operation.version(2)
class Form < Reform::Form
property :id
# ...
end
class New < Trailblazer::Operation.version(2)
step Model( Song, :new )
step Policy::Pundit( Song::Policy, :admin? )
step Contract::Build( constant: Form )
end
step Nested(New)
step Contract::Validate( key: :admin )
step Contract::Persist()
end
end
```
3. Should you ever be finished updating your application, simply remove the `trailblazer-compat` gem from the `Gemfile`. You can then safely delete `.version(2)` across all files.
## Development Status
The `compat` gem tries to make the transition to newer versions as painless as possible. However, if you run into any problems specific to your application, please [don't hesitate to contact us](https://gitter.im/trailblazer/chat). Pull requests (even ugly hacks) are appreciated in this gem, and this gem only.