[feature] define after_initialize callback in sequent command
Define callback after_initialize in Sequent::Command. We can use this callback to do more things, such as set default value for command attributes.
class AfterInitCommand < Sequent::Command
attrs flag: Boolean
after_initialize do
@flag = true if @flag.nil?
end
end
I'm not sure if this is the way to go for 'default' values.
We could also introduce the following:
MyCommand < Sequent::Command
attr flag: Boolean, default: true
end
If you want this with attrs as well, we could try this:
MyCommand < Sequent::Command
attrs flag: opts(type: Boolean, default: true), other_flag: Boolean
end
I'm not sure if this is the way to go for 'default' values.
We could also introduce the following:
MyCommand < Sequent::Command attr flag: Boolean, default: true end
I think after_initialize is just another active model callback we can support (like we already do with validations). Using after_initialize also has access to other attributes in the object.
But we could also implement the default suggestion, that is probably more elegant to set default values.