raes 0.1.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +19 -0
- data/app/jobs/raes/stateless_job.rb +14 -0
- data/config/routes.rb +1 -0
- data/lib/raes.rb +12 -1
- data/lib/raes/context_logger.rb +40 -0
- data/lib/raes/reducer.rb +4 -3
- data/lib/raes/use_caller.rb +0 -6
- data/lib/raes/use_context_logger.rb +15 -0
- data/lib/raes/version.rb +1 -1
- metadata +9 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d721d10ce56f1d6d3070a9b6d7c0de4837fb6264213071e352e4c943cad2e922
|
4
|
+
data.tar.gz: 6fb24ec1d713e01044b8fb3ae1b39f30b03e123439ec15e22ddd9dfb208ff70f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6119cb606129f09fa07731b4e3a3c497985e33a45b134bdef1839e50584e0323a7c2b242f31179c446f4dfdbb7dc531f2f42a9dd22e81bc9d33d3d25522d4fa
|
7
|
+
data.tar.gz: 9e5c47e1dab07a05a06e66881b39e8475210f0cc4ebd6bf5db878d7c43b9d36554eef794d7ddd82b5e8287639b76848da86472b1aa19abe4fc65a0bab0075ff0
|
data/README.md
CHANGED
@@ -86,6 +86,25 @@ If use storage, then execute:
|
|
86
86
|
$ rails active_storage:install
|
87
87
|
```
|
88
88
|
|
89
|
+
## Configuration
|
90
|
+
|
91
|
+
Add the following to your config/raes.yml:
|
92
|
+
|
93
|
+
```yaml
|
94
|
+
default: &default
|
95
|
+
concern:
|
96
|
+
context_logger: Rails
|
97
|
+
|
98
|
+
development:
|
99
|
+
<<: *default
|
100
|
+
|
101
|
+
test:
|
102
|
+
<<: *default
|
103
|
+
|
104
|
+
production:
|
105
|
+
<<: *default
|
106
|
+
```
|
107
|
+
|
89
108
|
## Test
|
90
109
|
|
91
110
|
```bash
|
@@ -0,0 +1,14 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Raes
|
4
|
+
class StatelessJob < ApplicationJob
|
5
|
+
def perform(name, payload)
|
6
|
+
klass = name.constantize
|
7
|
+
if klass.instance_method(:initialize).arity.zero?
|
8
|
+
klass.call
|
9
|
+
else
|
10
|
+
klass.call(payload.symbolize_keys)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
data/config/routes.rb
CHANGED
data/lib/raes.rb
CHANGED
@@ -2,16 +2,27 @@
|
|
2
2
|
|
3
3
|
require 'raes/engine'
|
4
4
|
require 'raes/use_caller'
|
5
|
+
require 'raes/use_context_logger'
|
5
6
|
require 'raes/use_storage'
|
6
7
|
require 'raes/dispatch'
|
7
8
|
require 'raes/reducer'
|
8
9
|
|
9
10
|
module Raes
|
11
|
+
def self.config
|
12
|
+
@config ||= Rails.application.config_for(:raes)
|
13
|
+
rescue StandardError
|
14
|
+
@config = {}
|
15
|
+
end
|
16
|
+
|
10
17
|
def self.dispatch(name, payload = {})
|
11
18
|
Dispatch.call(name, payload)
|
12
19
|
end
|
13
20
|
|
14
21
|
def self.search(name)
|
15
|
-
Action.search(name)
|
22
|
+
Action.search(name)
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.stateless(name, payload = {})
|
26
|
+
StatelessJob.perform_later(name.to_s, payload)
|
16
27
|
end
|
17
28
|
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Raes
|
4
|
+
class ContextLogger
|
5
|
+
def initialize(class_name)
|
6
|
+
@class_name = class_name
|
7
|
+
@logger_class = logger_class
|
8
|
+
end
|
9
|
+
|
10
|
+
def debug(message)
|
11
|
+
@logger_class.logger.debug context(message)
|
12
|
+
end
|
13
|
+
|
14
|
+
def info(message)
|
15
|
+
@logger_class.logger.info context(message)
|
16
|
+
end
|
17
|
+
|
18
|
+
def warn(message)
|
19
|
+
@logger_class.logger.warn context(message)
|
20
|
+
end
|
21
|
+
|
22
|
+
def error(message)
|
23
|
+
@logger_class.logger.error context(message)
|
24
|
+
end
|
25
|
+
|
26
|
+
def fatal(message)
|
27
|
+
@logger_class.logger.fatal context(message)
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def context(message)
|
33
|
+
{ class: @class_name, message: message }
|
34
|
+
end
|
35
|
+
|
36
|
+
def logger_class
|
37
|
+
(Raes.config.dig(:concern, :context_logger) || 'Rails').constantize
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
data/lib/raes/reducer.rb
CHANGED
@@ -23,10 +23,11 @@ module Raes
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def create_state
|
26
|
-
|
27
|
-
|
26
|
+
klass = @action.name.constantize
|
27
|
+
if klass.instance_method(:initialize).arity.zero?
|
28
|
+
klass.call
|
28
29
|
else
|
29
|
-
|
30
|
+
klass.call(JSON.parse(@action.payload).symbolize_keys)
|
30
31
|
end
|
31
32
|
end
|
32
33
|
end
|
data/lib/raes/use_caller.rb
CHANGED
@@ -16,12 +16,6 @@ module Raes
|
|
16
16
|
|
17
17
|
private
|
18
18
|
|
19
|
-
def initialize(*params)
|
20
|
-
return if params.empty?
|
21
|
-
|
22
|
-
raise NotImplementedError, "You must implement #{self.class}##{__method__}"
|
23
|
-
end
|
24
|
-
|
25
19
|
def call
|
26
20
|
raise NotImplementedError, "You must implement #{self.class}##{__method__}"
|
27
21
|
end
|
data/lib/raes/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: raes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ogom
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-12-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -87,6 +87,7 @@ files:
|
|
87
87
|
- app/controllers/raes/application_controller.rb
|
88
88
|
- app/helpers/raes/application_helper.rb
|
89
89
|
- app/jobs/raes/application_job.rb
|
90
|
+
- app/jobs/raes/stateless_job.rb
|
90
91
|
- app/jobs/raes/subscribe_job.rb
|
91
92
|
- app/mailers/raes/application_mailer.rb
|
92
93
|
- app/models/raes/action.rb
|
@@ -97,10 +98,12 @@ files:
|
|
97
98
|
- db/migrate/20200628202001_create_raes_actions.rb
|
98
99
|
- db/migrate/20200628202002_create_raes_storages.rb
|
99
100
|
- lib/raes.rb
|
101
|
+
- lib/raes/context_logger.rb
|
100
102
|
- lib/raes/dispatch.rb
|
101
103
|
- lib/raes/engine.rb
|
102
104
|
- lib/raes/reducer.rb
|
103
105
|
- lib/raes/use_caller.rb
|
106
|
+
- lib/raes/use_context_logger.rb
|
104
107
|
- lib/raes/use_storage.rb
|
105
108
|
- lib/raes/version.rb
|
106
109
|
- lib/tasks/raes_tasks.rake
|
@@ -109,7 +112,7 @@ licenses:
|
|
109
112
|
- MIT
|
110
113
|
metadata:
|
111
114
|
allowed_push_host: https://rubygems.org/
|
112
|
-
post_install_message:
|
115
|
+
post_install_message:
|
113
116
|
rdoc_options: []
|
114
117
|
require_paths:
|
115
118
|
- lib
|
@@ -117,7 +120,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
117
120
|
requirements:
|
118
121
|
- - ">="
|
119
122
|
- !ruby/object:Gem::Version
|
120
|
-
version: '
|
123
|
+
version: '2.6'
|
121
124
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
125
|
requirements:
|
123
126
|
- - ">="
|
@@ -125,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
128
|
version: '0'
|
126
129
|
requirements: []
|
127
130
|
rubygems_version: 3.0.3
|
128
|
-
signing_key:
|
131
|
+
signing_key:
|
129
132
|
specification_version: 4
|
130
133
|
summary: Summary of Rails Async Event Store.
|
131
134
|
test_files: []
|