- Fix what we broke in 2.0.5, where
Wrap
would always use the current operation subclass and not the emptyTrailblazer::Operation
. Thanks to @mensfeld.
- In Wrap, use
self
instead of a hard class reference. This allows using Wrap in the compat gem.
- When using
Nested(X)
, the automatic:name
option is now"Nested(X)"
instead of the cryptic proc string.
Guard
now allows kw args for its option.- Fix a bug where
Nested( ->{} )
wouldn't_call
the nested operation and did too much work on re-nested the already nested params. Thanks to @eliranf for spotting this. - Add
Nested(..., input: )
to dynamically decide the input to the nested operation. http://trailblazer.to/gems/operation/2.0/api.html#nested-input - Add
Nested(..., output: )
: http://trailblazer.to/gems/operation/2.0/api.html#nested-output
-
Remove
uber
dependency as we use our ownOption::KW
now. -
In
Contract::Build( builder: )
you now also have access to thename:
keyword. Note that you need to double-splat in builders.```ruby Contract::Build( builder: ->(options, constant:, **) ) ```
Same for
:method
andCallable
. -
Policy::Guard( :method )
now works.
-
Add
fail_fast: true
forstep
andfailure
to short-circuit the pipe. Note that more "eloquent" semantics are coming intrailblazer-bpmn
. -
Add
fail!
,fail_fast!
,pass!
, andpass_fast!
. Note that they are all experimental API and not documented, yet. -
Remove Builder and allow dynamic
Nested
.step Nested( ->(options, params:) { params[:type] == "moderated" ? Moderated : Comment } )
-
Remove
override
in favor ofstep .., override: true
. Note that this method wasn't documented. -
Numerous internal simplifications documented here.
All old semantics will be available via trailblazer-compat.
-
Removed
Operation::run
as it was a bad decision. Raising an exception on invalid is a very test-specific scenario and shouldn't have been handled in the core doce. -
Removed
Operation::present
, since you can simply callOperation::new
(without builders) orOperation::build_operation
(with builders). -
Removed
Operation::valid?
. This is in the result object viaresult.success?
. -
Removed
Operation#errors
. This is in the result object viaresult[:errors]
if the operation was invalid. -
Removed the private option
:raise_on_invalid
. UseContract::Raise
instead, if you need it in tests. -
Removed
Operation::contract
(without args). Please useOperation::["contract.default.class"]
. -
Removed
Operation::callbacks
(without args). Please useOperation::["callback.<name>.class"]
. -
Removed
Operation::contract_class
. Please useOperation::["contract.default.class"]
. -
Removed
Operation::contract_class=
. Please useOperation::["contract.default.class"]=
. Doesn't inherit.
- The
model
method doesn't exist anymore, useself["model"]
or write your own. :find_by
diverts to left track.:create
is:new
now.
- It's
include Builder
now, notextend Builder
. builds
now receives one options hash.
- No exception anymore, but
Operation#["policy.result"]
. - Access the current user via
self["current_user"]
now. Policy
isPolicy::Pundit
now asPolicy
is Trailblazer's (upcoming) authorization style.
- Removed
Operation::representer_class
. Please useOperation::["representer.class"]
. - Removed
Operation::representer_class=
. Please useOperation::["representer.class"]=
. - You can now have any number of named representers:
Operation.representer :parser, ParsingRepresenter
. - Automatic infering of the representer from a
contract
is not so automatic anymore. This feature was barely used and is now available viainclude Representer::InferFromContract
. - Reform 2.0 is not supported in
Representer
anymore, meaning you can't automatically infer representers from 2.0 contracts. Reform 2.0 works with all remaining components. - Removed
Operation::contract_class
. Please useOperation::["contract.default.class"]
. - Removed
Operation::contract_class=
. Please useOperation::["contract.default.class"]=
. Doesn't inherit.
- Removed
Operation::Dispatch
, it's calledOperation::Callback
.
- Removed
Operation::Collection
. Please useOperation::present
.
- Removed
Controller
, this is now in trailblazer-rails.
- You can't call
Create.().contract
anymore. The contract instance(s) are available through theResult
object via["contract.default"]
. - Removed the deprecation for
validate
, signature is(params[, model, options, contract_class])
. - Removed the deprecation for
contract
, signature is([model, options, contract_class])
.
consider
got removed sincestep
now evaluates the step's result and deviates (or not).
- It's now Contract::Persist( name: "params" ) instead of ( name: "contract.params" ).
- New, very slick keyword arguments for steps.
- Removed
Operation::Controller
. - Renamed
Persist
toContract::Persist
. - Simplify inheritance by introducing
Operation::override
. Contract
paths are now consistent.
- Still undefined
self.~
.
- Stricter
uber
dependency.
- Rename
Operation::Representer::ClassMethods
toOperation::Representer::DSL
and allow to useDSL
andRendering
withoutDeserialization
so you can use two different representers. Policy::Guard::policy
now also accepts aCallable
object.- Add
Operation#model=
.
Representer#represented
defaults tomodel
now, not tocontract
anymore.- The only way to let Trailblazer pass a document to the operation is via
is_document: true
. There is no guessing anymore based on whether or notRepresenter
is mixed into the operation or not. - Add
Operation#params!
that works exactly like#model!
: return another params hash here if you want to change theparams
structure while avoiding modifying the original one. - Add
Controller#params!
that works exactly likeOperation#params!
and allows returning an arbitrary params object in the controller. Thanks to @davidpelaez for inspiration. - Deprecate
Dispatch
in favor ofCallback
. In operations, please includeOperation::Callback
. Also, introducedOperation#callback!
which aliases to#dispatch!
. Goal is having to think less, and now all naming is in line.
Representer#to_json
now allows passing options.- The
:params
key never got propagated toprepopulate!
when usingController#form
. This is now fixed.
- Fix
Controller#run
, which now returns the operation instance instead of theElse
object.
- Remove unprofessional
puts
, @smathy.
- Treat all requests as
params
requests unless the operation has a representer mixed in. If you don't want that, you can override usingis_document: false
. This appears to be the smoothest solution for all. - In
Controller#form
, the options argument is now passed intoform.prepopulate!(options)
. This allows to use arbitrary options and theoptions[:params]
for prepopulation.
- Treat
:js
requests as non-document, too. Controller#form
now returns the form object and not the operation.- In
Controller
,#form
,#present
,#run
and#respond
now all have the same API:run(constant, options)
. If you want to pass a custom params hash, userun Comment::Create, params: {..}
.
- All Rails-relevant files are now in the
trailblazer-rails
gem. You have to include it should you be in a Rails environment. Operation[{..}]
is deprecated in favor ofOperation.({..})
.Operation::CRUD
is nowOperation::Model
.Controller#form
now invokes#prepopulate!
before rendering the view.Controller#present
does not instantiate and assign@form
anymore.- The internal
Operation
API has changed from#initialize()
and#run(params)
to#initialize(params)
and#run
.
- Added
Operation::Policy
. - Added
Operation::Resolver
.
- Add
Operation::reject
which will run the block when invalid. - In the railtie, require
trailblazer/autoloading
as I am assuming Rails users want maximum comfort.
- Allow to use
#contract
before#validate
. The contract will be instantiated once per#run
using#contract
and then memoized. This allows to add/modify the contract before you validate it using#validate
. - New signature for
Operation#contract_for(model, contract_class)
. It used to be contract, then model.
- Autoload
Dispatch
.
- In Railtie, use
ActionDispatch::Reloader.to_prepare
for autoloading, nothing else. This should fix spring reloading. - Allow
Op#validate(params, model, Contract)
with CRUD. - Allows prefixed table names, e.g.
admin.users
inController
. The instance variables will be@user
. Thanks to @fernandes and especially @HuckyDucky. - Added
Operation::Collection
which will allow additional behavior like pagination and scoping. Thanks to @fernandes for his work on this. - Added
Operation::collection
to runsetup!
without instantiating a contract. This is called in the newController#collection
method. - Added
Operation#model
as this is a fundamental concept now. - Improved the undocumented
Representer
module which allows inferring representers from contract, using them to deserialize documents for the form, and rendering documents. - Changed
Operation::Dispatch
which now provides imperative callbacks.
-
The return value of #process is no longer returned from ::run and ::call. They always return the operation instance.
-
The return value of #validate is
true
orfalse
. This allows a more intuitive operation body.def process(params) if validate(params) .. do valid else .. handle invalid end end
Worker
only works with Reform >= 2.0.0.
- Added
Operation#setup_model!(params)
that can be overridden to add nested objects or process models right aftermodel!
. Don't add deserialization logic here, let Reform/Representable do that. - Added
Operation#setup_params!(params)
to normalize parameters before#process
. Thanks to @gogogarrett. - Added
Controller::ActiveRecord
that will setup a named controller instance variable for your operation model. Thanks @gogogarrett! - Added
CRUD::ActiveModel
that currently infers the contract's::model
from the operation's model.
Controller#present
no longer callsrespond_to
, but lets you do the rendering. This will soon be re-introduced usingrespond(present: true)
.Controller#form
did not respect builders, this is fixed now.- Use
request.body.read
in Unicorn/etc. environments inController#respond
.
- Autoloading changed, again. We now
require_dependency
in every request in dev.
crud_autoloading
now simplyrequire_dependency
s model files, then does the same for the CRUD operation file. This should fix random undefined constant problems in development.Controller#form
did not use builders. This is fixed now.
- Add
crud_autoloading
.
- Use reform-1.2.0.
- First stable release after almost 6 months of blood, sweat and tears. I know, this is a ridiculously brief codebase but it was a hell of a job to structure everything the way it is now. Enjoy!