ekylibre-plugin_system 0.5.0 → 0.5.1

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: e67301a6ea670850bd6794f51d287fabb277f209fbbf5983d3e29540de7fefb4
4
- data.tar.gz: 5fe4b34bdad1085b5484ba7ebf809466005ca01343634aa5942596e9bf7d0d18
3
+ metadata.gz: c18835a3f0df42efc51f7255499700f5daf5c58995acd0391d01bd4c5eb96b34
4
+ data.tar.gz: fd48bb8dd840471bd7e746be73f520e62cd7c690ff3aed0c725eb39dab7c15fb
5
5
  SHA512:
6
- metadata.gz: 81ff8b3f60e94fca1a5ecf30ad0ebdd39c946af640ec6ab15e578a72fc881d2096bdcc7f96d2dc531111e5f83e57a04abdd0c9cfef61753e9fd1a63b512631b9
7
- data.tar.gz: 38521c74d7ef72588fe61d8b0e7d27f04260c2d964e2b36c5715052e2c8ebf8f7d741608f44376ecfa2b0c5ea832391982b14f9197cd2791c7063319497901fc
6
+ metadata.gz: 06e0dc832b6d3d8d362752aa71c018e2880cfdec5981324e5502e6b1ca7e529e75b6ee9754b4e87e74a11a17b08cd094c09d9bbf6d99de1adc372dabafa26592
7
+ data.tar.gz: ca4a600d5192155300d387050c6e631bb2e0eb2b6198c675165121e21a3cb709d387a4fe7b587b14d1e09cc5432485e7ac265ce615f080839c7aa2a642bbff38
@@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
26
26
 
27
27
  spec.add_development_dependency 'bundler', '>= 1.17'
28
28
  spec.add_development_dependency 'minitest', '~> 5.14'
29
+ spec.add_development_dependency 'minitest-reporters', '~> 1.4'
29
30
  spec.add_development_dependency 'rake', '~> 13.0'
30
31
  spec.add_development_dependency 'rubocop', '~> 1.3.0'
31
32
  end
@@ -11,6 +11,7 @@ end
11
11
  loader = Zeitwerk::Loader.for_gem
12
12
  loader.ignore(__FILE__)
13
13
  loader.ignore("#{__dir__}/plugin_system/rails/**/*.rb")
14
+ loader.ignore("#{__dir__}/plugin_system/testing/**/*.rb")
14
15
  loader.setup
15
16
 
16
17
  require_relative 'ekylibre/plugin_system/rails/railtie' if defined?(::Rails)
@@ -4,14 +4,10 @@ module Ekylibre
4
4
  module PluginSystem
5
5
  # Helper methods to access the container from the Rails console
6
6
  module ConsoleHelper
7
- extend ActiveSupport::Concern
8
-
7
+ # Provides an easy access to the container from the console context.
9
8
  # @return [Corindon::DependencyInjection::Container]
10
9
  def container
11
- instance = ::Rails.application.system.container
12
- RequestStore['container'] = instance
13
-
14
- instance
10
+ GlobalContainer.get
15
11
  end
16
12
  end
17
13
  end
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Ekylibre
4
+ module PluginSystem
5
+ # This class is a wrapper around RequestStore that, in addition to provide a concise way to access the container globally,
6
+ # ensures that a container is present if the application ask for one (nil is not a valid value)
7
+ class GlobalContainer
8
+ class << self
9
+ private :new
10
+
11
+ # @param [Corindon::DependencyInjection::Container] container
12
+ def set(container)
13
+ RequestStore['container'] = container
14
+ end
15
+
16
+ def unset
17
+ RequestStore.delete('container')
18
+ end
19
+
20
+ # @param [Corindon::DependencyInjection::Container] container
21
+ def replace_with(container, &block)
22
+ prev = if has?
23
+ get
24
+ else
25
+ nil
26
+ end
27
+
28
+ set(container)
29
+
30
+ block.call
31
+ ensure
32
+ if prev.nil?
33
+ unset
34
+ else
35
+ set(prev)
36
+ end
37
+ end
38
+
39
+ def has?
40
+ RequestStore.exist?('container')
41
+ end
42
+
43
+ # @return [Corindon::DependencyInjection::Container]
44
+ def get
45
+ container = RequestStore['container']
46
+
47
+ if container.nil?
48
+ raise StandardError.new(
49
+ 'The application requires the container to be loaded to work. Please load it before calling GlobalContainer.get'
50
+ )
51
+ else
52
+ container
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -14,13 +14,14 @@ module Ekylibre
14
14
 
15
15
  def call(env)
16
16
  # request_container = enter_tenant(container, ::Ekylibre::Tenant.current)
17
- RequestStore['container'] = container
17
+ GlobalContainer.replace_with(container) do
18
18
 
19
- # We HAVE to mutate the environment because Devise (and maybe other) needs to pass information up the middleware stack
20
- # from the Rails application to the Auth middleware through the environment
21
- env['container'] = container
19
+ # We HAVE to mutate the environment because Devise (and maybe other) needs to pass information up the middleware stack
20
+ # from the Rails application to the Auth middleware through the environment
21
+ env['container'] = container
22
22
 
23
- @app.call(env)
23
+ @app.call(env)
24
+ end
24
25
  end
25
26
 
26
27
  private
@@ -12,10 +12,11 @@ module Ekylibre
12
12
  end
13
13
 
14
14
  def call(_worker_class, item, _queue)
15
- RequestStore['container'] = container
16
- item['container'] = container
15
+ GlobalContainer.replace_with(container) do
16
+ item['container'] = container
17
17
 
18
- yield
18
+ yield
19
+ end
19
20
  ensure
20
21
  # We want to have the same behavior as the request_store-sidekiq gem.
21
22
  # However, we want to insert our middleware BEFORE the Batch middleware.
@@ -22,7 +22,10 @@ module Ekylibre
22
22
  end
23
23
 
24
24
  # rubocop:disable Lint/Debugger
25
- console do
25
+ console do |app|
26
+ # Make the app container accessible in the RequestStore when in rails console
27
+ GlobalContainer.set(app.system.container)
28
+
26
29
  ::Rails::ConsoleMethods.send :include, ConsoleHelper
27
30
  end
28
31
  # rubocop:enable Lint/Debugger
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'io/console'
4
+ require 'minitest/reporters'
5
+
6
+ module Ekylibre
7
+ module PluginSystem
8
+ module Testing
9
+ class SpecReporter < Minitest::Reporters::SpecReporter
10
+ def record_print_status(test)
11
+ test_name = test.name.gsub(/^test_: /, 'test:')
12
+ print_colored_status(test)
13
+ print pad_test(test_name)
14
+ print(format(' (%.2fs)', test.time)) unless test.time.nil?
15
+ puts
16
+ end
17
+
18
+ private def pad_test(str)
19
+ if ENV.key?('CI')
20
+ super
21
+ else
22
+ pad(format("%-#{[TEST_SIZE, IO.console.winsize[1] - 15].max}s", str), TEST_PADDING)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Ekylibre
4
4
  module PluginSystem
5
- VERSION = '0.5.0'
5
+ VERSION = '0.5.1'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ekylibre-plugin_system
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ekylibre developers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-02-09 00:00:00.000000000 Z
11
+ date: 2021-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: corindon
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: '5.14'
97
+ - !ruby/object:Gem::Dependency
98
+ name: minitest-reporters
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '1.4'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '1.4'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: rake
99
113
  requirement: !ruby/object:Gem::Requirement
@@ -133,6 +147,7 @@ files:
133
147
  - lib/ekylibre-plugin_system.rb
134
148
  - lib/ekylibre/plugin_system/console_helper.rb
135
149
  - lib/ekylibre/plugin_system/controller_mixin.rb
150
+ - lib/ekylibre/plugin_system/global_container.rb
136
151
  - lib/ekylibre/plugin_system/middleware/rack_middleware.rb
137
152
  - lib/ekylibre/plugin_system/middleware/sidekiq_middleware.rb
138
153
  - lib/ekylibre/plugin_system/middleware/sidekiq_middleware/client_middleware.rb
@@ -146,6 +161,7 @@ files:
146
161
  - lib/ekylibre/plugin_system/sugar/scripts.rb
147
162
  - lib/ekylibre/plugin_system/sugar/themes.rb
148
163
  - lib/ekylibre/plugin_system/system.rb
164
+ - lib/ekylibre/plugin_system/testing/spec_reporter.rb
149
165
  - lib/ekylibre/plugin_system/version.rb
150
166
  homepage: https://www.ekylibre.com
151
167
  licenses: