eztek-mediat_r 1.0.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8c66221e78adb55cce7b38b481a32ae12a8f4f22e5c4b25b8d12a1435fa3b98d
4
- data.tar.gz: 381eb46fbd9daedee47f246368214b5805a9433c59b8b20c27de6010a2876bb4
3
+ metadata.gz: 81fe49ca3fee1be65127f9c763d31fd0da477737b0a2d016c5e8efb1a9712f7d
4
+ data.tar.gz: a71cb6498c253234c65e32f5a5df4eeadc313e89c5f81ee461369f7039783eeb
5
5
  SHA512:
6
- metadata.gz: 9475134a35c04b01e42b7ae2b47d031821c3e8bc51056f679abbaf7ed5fe09bf5650134fc3d3fce6f402f30f3742fd9d29bcf78ccfa0dcd036d8452cb111082f
7
- data.tar.gz: 3f8a32363b4df0da42eba84d7598dc0eda50aeb283fc5e7375da48886ea0997490edd75fe340135bae76bcbdbd782ed162b1839170c799c9c2e879ab23bdbf6d
6
+ metadata.gz: a9be31068ed497359eaf3278955420ed1231d35c5dde06fdb0dd7c325257dff1795a28912bf07b8b69e882d382584508909d4ab224961b446516be98de8f7cc9
7
+ data.tar.gz: e0b8646e6be3ea108701125521f1ed4c7f485211ce8d5c4e42bbb23961d727dddc7b0a04bffcb936b70463a74a3724235cbf1db6df6316d23f7b5accae914313
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
- # Eztek::MediatR
1
+ # Eztek MediatR
2
2
 
3
- 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.
3
+ <a href="https://www.buymeacoffee.com/phunguyen" target="_blank"><img src="https://www.buymeacoffee.com/assets/img/custom_images/orange_img.png" alt="Buy Me A Coffee" style="height: 41px !important;width: 174px !important;box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;-webkit-box-shadow: 0px 3px 2px 0px rgba(190, 190, 190, 0.5) !important;" ></a>
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ 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.
6
6
 
7
7
  ## Installation
8
8
 
@@ -21,8 +21,55 @@ Or install it yourself as:
21
21
  $ gem install eztek-mediat_r
22
22
 
23
23
  ## Usage
24
+ ### Initialize mediatR
25
+ Add new file config/initializers/mediat_r.rb to initializer mediatR
26
+ ```ruby
27
+ require 'ez/mediat_r'
28
+
29
+ mediator = EZ::MediatR.new
30
+ Rails.configuration.to_prepare do
31
+ Rails.configuration.bus = Bus.new
32
+ Rails.configuration.bus.tap do |bus|
33
+ # Register command - handler
34
+ bus.register(Auth::Commands::LoginCommand, Auth::Commands::Handlers::LoginCommandHandler.new)
35
+ end
36
+ end
37
+
38
+ ```
39
+
40
+ ### Declare mediatR in controller
41
+ ```ruby
42
+ def initialize
43
+ @mediator = Rails.configuration.bus
44
+ end
45
+
46
+ ```
47
+
48
+ or dependency with dry-container, dry-auto_inject:
49
+
50
+ ### Register mediaR in container
51
+ Use file dependency.rb to register mediatR
52
+ ```ruby
53
+ require 'ez/mediat_r'
54
+
55
+ dependency_container = Dry::Container.new
56
+ dependency_container.register('mediator', -> { EZ::MediatR.new })
57
+ AutoInject = Dry::AutoInject(dependency_container)
58
+
59
+ ```
60
+
61
+ ### Define mediatR in controller
62
+ ```ruby
63
+ include AutoInject['mediator']
24
64
 
25
- TODO: Write usage instructions here
65
+ ```
66
+
67
+ ### Run mediator
68
+ ```ruby
69
+ command = Auth::Commands::LoginCommand.new(username, password)
70
+ mediator.execute(command)
71
+
72
+ ```
26
73
 
27
74
  ## Development
28
75
 
@@ -32,4 +79,4 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
32
79
 
33
80
  ## Contributing
34
81
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/eztek-mediat_r.
82
+ Bug reports and pull requests are welcome on GitHub at https://github.com/yeucon02vn/eztek-mediat_r.
@@ -1,7 +1,7 @@
1
- # frozen_string_literal: true
2
-
3
- module EZ
4
- module MediatR
5
- VERSION = "1.0.1"
6
- end
7
- end
1
+ # frozen_string_literal: true
2
+
3
+ module EZ
4
+ module MediatR
5
+ VERSION = "1.1.0"
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ Description:
2
+ Creates the command model structure for you.
3
+
4
+ Example:
5
+ rails generate command user create_user
6
+
7
+ This will create:
8
+ app/cqrs/user/commands/create_user_command.rb
9
+ app/cqrs/user/commands/validators/create_user_command_validator.rb
10
+ app/cqrs/user/commands/handlers/create_user_command_handler.rb
@@ -0,0 +1,30 @@
1
+ class CommandGenerator < Rails::Generators::Base
2
+ source_root File.expand_path('../templates', __FILE__)
3
+ argument :model, type: :string
4
+ argument :name, type: :string
5
+ class_option :validator, type: :boolean, default: true, desc: "Generate validator."
6
+ class_option :doc, type: :boolean, default: true, desc: "Include documentation."
7
+
8
+ def generate_init
9
+ generate_command
10
+ generate_command_handler
11
+ end
12
+
13
+ def generate_validator
14
+ generate_command_validator if options.validator?
15
+ end
16
+
17
+ private
18
+
19
+ def generate_command
20
+ template 'command_template.template', "app/cqrs/#{model.underscore}/commands/#{name.underscore}_command.rb"
21
+ end
22
+
23
+ def generate_command_validator
24
+ template 'command_validator_template.template', "app/cqrs/#{model.underscore}/commands/validators/#{name.underscore}_command_validator.rb"
25
+ end
26
+
27
+ def generate_command_handler
28
+ template 'command_handler_template.template', "app/cqrs/#{model.underscore}/commands/handlers/#{name.underscore}_command_handler.rb"
29
+ end
30
+ end
@@ -1,7 +1,7 @@
1
1
  module <%= model.camelcase %>::Commands
2
2
  class <%= name.camelcase %>Command
3
3
  include ActiveModel::Validations
4
- <%- options.validator -%>
4
+ <%- if options.validator? -%>
5
5
  validates_with Validators::<%= name.camelcase %>CommandValidator
6
6
  <%- end -%>
7
7
 
@@ -0,0 +1,10 @@
1
+ Description:
2
+ Creates the query model structure for you.
3
+
4
+ Example:
5
+ rails generate query user get_all_user
6
+
7
+ This will create:
8
+ app/cqrs/user/queries/get_all_user_query.rb
9
+ app/cqrs/user/queries/validators/get_all_user_query_validator.rb
10
+ app/cqrs/user/queries/handlers/get_all_user_query_handler.rb
@@ -0,0 +1,30 @@
1
+ class QueryGenerator < Rails::Generators::Base
2
+ source_root File.expand_path('../templates', __FILE__)
3
+ argument :model, type: :string
4
+ argument :name, type: :string
5
+ class_option :validator, type: :boolean, default: true, desc: "Generate validator."
6
+ class_option :doc, type: :boolean, default: true, desc: "Include documentation."
7
+
8
+ def generate_init
9
+ generate_query
10
+ generate_query_handler
11
+ end
12
+
13
+ def generate_validator
14
+ generate_query_validator if options.validator?
15
+ end
16
+
17
+ private
18
+
19
+ def generate_query
20
+ template 'query_template.template', "app/cqrs/#{model.underscore}/queries/#{name.underscore}_query.rb"
21
+ end
22
+
23
+ def generate_query_validator
24
+ template 'query_validator_template.template', "app/cqrs/#{model.underscore}/queries/validators/#{name.underscore}_query_validator.rb"
25
+ end
26
+
27
+ def generate_query_handler
28
+ template 'query_handler_template.template', "app/cqrs/#{model.underscore}/queries/handlers/#{name.underscore}_query_handler.rb"
29
+ end
30
+ end
@@ -1,7 +1,7 @@
1
1
  module <%= model.camelcase %>::Queries
2
2
  class <%= name.camelcase %>Query
3
3
  include ActiveModel::Validations
4
- <%- options.validator -%>
4
+ <%- if options.validator? -%>
5
5
  validates_with Validators::<%= name.camelcase %>QueryValidator
6
6
  <%- end -%>
7
7
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eztek-mediat_r
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - yeucon02vn
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-09-08 00:00:00.000000000 Z
11
+ date: 2022-09-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: concurrent-ruby
@@ -79,16 +79,16 @@ files:
79
79
  - lib/ez/mediat_r.rb
80
80
  - lib/ez/mediat_r/alias.rb
81
81
  - lib/ez/mediat_r/version.rb
82
- - lib/generators/commands/USAGE
83
- - lib/generators/commands/commands_generator.rb
84
- - lib/generators/commands/templates/command_handler_template.template
85
- - lib/generators/commands/templates/command_template.template
86
- - lib/generators/commands/templates/command_validator_template.template
87
- - lib/generators/queries/USAGE
88
- - lib/generators/queries/queries_generator.rb
89
- - lib/generators/queries/templates/queries_handler_template.template
90
- - lib/generators/queries/templates/queries_template.template
91
- - lib/generators/queries/templates/queries_validator_template.template
82
+ - lib/generators/command/USAGE
83
+ - lib/generators/command/command_generator.rb
84
+ - lib/generators/command/templates/command_handler_template.template
85
+ - lib/generators/command/templates/command_template.template
86
+ - lib/generators/command/templates/command_validator_template.template
87
+ - lib/generators/query/USAGE
88
+ - lib/generators/query/query_generator.rb
89
+ - lib/generators/query/templates/query_handler_template.template
90
+ - lib/generators/query/templates/query_template.template
91
+ - lib/generators/query/templates/query_validator_template.template
92
92
  - sig/ez/mediat_r.rbs
93
93
  homepage: https://github.com/yeucon02vn/eztek-mediat_r
94
94
  licenses:
File without changes
@@ -1,33 +0,0 @@
1
- class CommandsGenerator < Rails::Generators::Base
2
- source_root File.expand_path('../templates', __FILE__)
3
- argument :model, type: :string
4
- argument :name, type: :string
5
- class_option :validator, type: :boolean, default: false, desc: "Generate validator."
6
- class_option :doc, type: :boolean, default: true, desc: "Include documentation."
7
-
8
- def generate_init
9
- generate_command
10
- end
11
-
12
- def generate_validator
13
- generate_validator if validator
14
- end
15
-
16
- def generate_handler
17
- generate_handler unless model == 'init'
18
- end
19
-
20
- private
21
-
22
- def generate_command
23
- template 'commands_template.template', "app/cqrs/#{model.underscore}/commands/#{{name.underscore}_command.rb}"
24
- end
25
-
26
- def generate_validator
27
- template 'commands_validator_template.template', "app/cqrs/#{model.underscore}/commands/validators/#{{name.underscore}_command_validator.rb}"
28
- end
29
-
30
- def generate_handler
31
- template 'commands_handler_template.template', "app/cqrs/#{model.underscore}/commands/handlers/#{{name.underscore}_command_handler.rb}"
32
- end
33
- end
File without changes
@@ -1,33 +0,0 @@
1
- class QueriesGenerator < Rails::Generators::Base
2
- source_root File.expand_path('../templates', __FILE__)
3
- argument :model, type: :string
4
- argument :name, type: :string
5
- class_option :validator, type: :boolean, default: false, desc: "Generate validator."
6
- class_option :doc, type: :boolean, default: true, desc: "Include documentation."
7
-
8
- def generate_init
9
- generate_query
10
- end
11
-
12
- def generate_validator
13
- generate_validator if validator
14
- end
15
-
16
- def generate_handler
17
- generate_handler unless model == 'init'
18
- end
19
-
20
- private
21
-
22
- def generate_query
23
- template 'queries_template.template', "app/cqrs/#{model.underscore}/queries/#{{name.underscore}_query.rb}"
24
- end
25
-
26
- def generate_validator
27
- template 'queries_validator_template.template', "app/cqrs/#{model.underscore}/queries/validators/#{{name.underscore}_query_validator.rb}"
28
- end
29
-
30
- def generate_handler
31
- template 'queries_handler_template.template', "app/cqrs/#{model.underscore}/queries/handlers/#{{name.underscore}_query_handler.rb}"
32
- end
33
- end