raes 0.1.0 → 0.2.1
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/helpers/{async_event_store → raes}/application_helper.rb +0 -0
- data/app/jobs/raes/stateless_job.rb +16 -0
- data/app/jobs/raes/subscribe_job.rb +1 -0
- data/config/routes.rb +1 -0
- data/lib/raes.rb +11 -0
- 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 +10 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4791a22f8ccf6a76394e80553cc84d9c19e886ce9877c7727a0784d828b6f7a2
|
4
|
+
data.tar.gz: 7f1f19c2efc5e157008c92d94322f6551acddc69963e564698e9a1e9773f94e0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 461b9e88954ab5056c80a8b051c74fcdd8c5b9bb6f3a1986ce959ac0d8b68a88dd261489119c4544147c18fdf1342b02aca6677d7b52ea3adab6e32162725084
|
7
|
+
data.tar.gz: ae00555bf5342322c17406aceddfb76de0de561f85f42e4841889e4972a411dd6947b13b5539ff1c6146924f11d1d4b310968856a67d2fba10db9d82e7e10bfd
|
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
|
File without changes
|
@@ -0,0 +1,16 @@
|
|
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
|
+
|
13
|
+
GC.start
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
data/config/routes.rb
CHANGED
data/lib/raes.rb
CHANGED
@@ -2,11 +2,18 @@
|
|
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
|
@@ -14,4 +21,8 @@ module Raes
|
|
14
21
|
def self.search(name)
|
15
22
|
Action.search(name)
|
16
23
|
end
|
24
|
+
|
25
|
+
def self.stateless(name, payload = {})
|
26
|
+
StatelessJob.perform_later(name.to_s, payload)
|
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.1
|
4
|
+
version: 0.2.1
|
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-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -85,8 +85,9 @@ files:
|
|
85
85
|
- app/assets/config/raes_manifest.js
|
86
86
|
- app/assets/stylesheets/raes/application.css
|
87
87
|
- app/controllers/raes/application_controller.rb
|
88
|
-
- app/helpers/
|
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: []
|