README.md in fluxo-0.2.0 vs README.md in fluxo-0.2.1

- old
+ new

@@ -238,9 +238,60 @@ Success(user) end end ``` +### Operation Validation + +If you have the `ActiveModel` gem installed, you can use the `validations` method to define validations on the operation. + +```ruby +class SubscribeOperation < Fluxo::Operation(:name, :email) + validations do + validates :name, presence: true + validates :email, presence: true, format: { with: /\A[^@]+@[^@]+\z/ } + end + + def call!(name:, email:) + # ... + end +end +``` + +### Operations Composition + +To promote single responsibility principle, Fluxo allows compose a complex operation flow by combining other operations. + +```ruby +class DoubleOperation < Fluxo::Operation(:num) + def call!(num:) + Success(num: num * 2) + end +end + +class SquareOperation < Fluxo::Operation(:num) + def call!(num:) + Success(num: num * 2) + end +end + +class ArithmeticOperation < Fluxo::Operation(:num) + flow :normalize, :double, :square + + def normalize(num:) + Success(num: num.to_i) + end + + def double(num:) + DoubleOperation.call(num: num) + end + + def square(num:) + SquareOperation.call(num: num) + end +end +``` + ### Configuration ```ruby Fluxo.config do |config| config.wrap_falsey_result = false