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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b6043ba9c36590180a011fbf26a25f7c84e20c6f9817bc580b7c0f50fd9b1e44
4
- data.tar.gz: 259f6da4d4546da83eb11a874e2ce08d5db951065e372b22270d0e3ae6923386
3
+ metadata.gz: 4791a22f8ccf6a76394e80553cc84d9c19e886ce9877c7727a0784d828b6f7a2
4
+ data.tar.gz: 7f1f19c2efc5e157008c92d94322f6551acddc69963e564698e9a1e9773f94e0
5
5
  SHA512:
6
- metadata.gz: 0e7e932f79f460e372e505f86e39446736536050d7dd9e637815e945147f42eab26866321c39701143b5ad8e0959421dac6b2ed32f340696eeef54652ebb517d
7
- data.tar.gz: f2568c2639857b90b49df2a52e3f1e557126de3ab256bc9e923b9c3867fba0b396966d603b2600791f1788e57f2ef277e149802ad220d10ea82d6e6773ae9b70
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
@@ -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
@@ -4,6 +4,7 @@ module Raes
4
4
  class SubscribeJob < ApplicationJob
5
5
  def perform(action)
6
6
  Reducer.call(action)
7
+ GC.start
7
8
  end
8
9
  end
9
10
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  Raes::Engine.routes.draw do
4
+ # engine routes
4
5
  end
@@ -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
@@ -23,10 +23,11 @@ module Raes
23
23
  end
24
24
 
25
25
  def create_state
26
- if @action.name.constantize.method(:call).arity.zero?
27
- @action.name.constantize.call
26
+ klass = @action.name.constantize
27
+ if klass.instance_method(:initialize).arity.zero?
28
+ klass.call
28
29
  else
29
- @action.name.constantize.call(JSON.parse(@action.payload).symbolize_keys)
30
+ klass.call(JSON.parse(@action.payload).symbolize_keys)
30
31
  end
31
32
  end
32
33
  end
@@ -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
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'raes/context_logger'
4
+
5
+ module Raes
6
+ module UseContextLogger
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ def logger
11
+ ContextLogger.new(self.class.name)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Raes
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.1'
5
5
  end
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.0
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-06-30 00:00:00.000000000 Z
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/async_event_store/application_helper.rb
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: '0'
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: []