0.0
No release in over a year
This is an async implementation of Mediator pattern with pipline behaviors. It is a port of Mediatr from .Net C#
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 10.0
~> 3.4.0

Runtime

 Project Readme

Eztek MediatR

Buy Me A Coffee

Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file lib/eztek/mediat_r. To experiment with that code, run bin/console for an interactive prompt.

Installation

Add this line to your application's Gemfile:

gem 'eztek-mediat_r'

And then execute:

$ bundle install

Or install it yourself as:

$ gem install eztek-mediat_r

Usage

Initialize mediatR

Add new file config/initializers/mediat_r.rb to initializer mediatR

require 'ez/mediat_r'

Rails.configuration.to_prepare do
    Rails.configuration.mediator = EZ::MediatR.new
    Rails.configuration.mediator.tap do |mediator|
        # Register command - handler
        mediator.register(Auth::Commands::LoginCommand, Auth::Commands::Handlers::LoginCommandHandler.new)
    end
end

Register mediaR in container with dry-container, dry-auto_inject

Use file dependency.rb to register mediatR

require 'ez/mediat_r'

dependency_container = Dry::Container.new
dependency_container.register('mediator', -> { Rails.configuration.mediator })
AutoInject = Dry::AutoInject(dependency_container)

Define mediatR in controller

include AutoInject['mediator']

Run mediator

command = Auth::Commands::LoginCommand.new(username, password)
mediator.execute(command) 

Generator structure with rails

    $ rails generate command feature command_name

Example:

    $ rails generate command auth login

This will create: app/cqrs/auth/commands/login_command.rb app/cqrs/auth/commands/validators/login_command_validator.rb app/cqrs/auth/commands/handlers/login_command_handler.rb

Development

After checking out the repo, run bin/setup to install dependencies. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and the created tag, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/yeucon02vn/eztek-mediat_r.