rage_arch 0.2.1 → 0.2.2
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 +4 -4
- data/lib/rage_arch/auto_registry.rb +20 -9
- data/lib/rage_arch/patches/middleware_stack.rb +19 -0
- data/lib/rage_arch/railtie.rb +1 -0
- data/lib/rage_arch/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 827bf0c1b2891fa1d67035363a4b820a71038e7f9b56b4167a29aa7524fa56dc
|
|
4
|
+
data.tar.gz: 57e7d566e7b2cbf2ff23e0ee9b1958f7a3e96e9dd9bdf1a2bea22e69c32a5d1c
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 95f6572c4ce9124edd8570e31be5ef8a0aaebfd63a3e35ce0c72662910fdfe2daf7141f82d3a5c14f1a7df451340b7b3ac59df0a9805b65e957810359fbdb3a0
|
|
7
|
+
data.tar.gz: 137357b33fe38902cce2b6de71a3905d22b5b698422eabad04f852fc056ee6da763346dbac1cd842df21677df74677530ad759bd6bc47e9c8b00dbff484d8324
|
|
@@ -23,7 +23,7 @@ module RageArch
|
|
|
23
23
|
|
|
24
24
|
# Ensure all subclasses have their symbol inferred and registered
|
|
25
25
|
RageArch::UseCase::Base.descendants.each do |klass|
|
|
26
|
-
next if klass.
|
|
26
|
+
next if safe_class_name(klass).nil?
|
|
27
27
|
klass.use_case_symbol # triggers inference + registration if not already set
|
|
28
28
|
end
|
|
29
29
|
end
|
|
@@ -38,31 +38,42 @@ module RageArch
|
|
|
38
38
|
require file
|
|
39
39
|
end
|
|
40
40
|
|
|
41
|
-
# Register any class defined under app/deps/ that isn't already registered
|
|
41
|
+
# Register any class defined under app/deps/ that isn't already registered.
|
|
42
|
+
# Some gems (e.g. Faker) redefine .name with required keyword args,
|
|
43
|
+
# so we use safe_class_name to avoid ArgumentError on iteration.
|
|
42
44
|
ObjectSpace.each_object(Class).select do |klass|
|
|
43
|
-
|
|
44
|
-
next
|
|
45
|
+
klass_name = safe_class_name(klass)
|
|
46
|
+
next unless klass_name
|
|
47
|
+
next if klass_name.start_with?("RageArch::")
|
|
45
48
|
|
|
46
49
|
# Check if this class was loaded from app/deps/
|
|
47
50
|
source_file = begin
|
|
48
|
-
Object.const_source_location(
|
|
49
|
-
rescue
|
|
51
|
+
Object.const_source_location(klass_name)&.first
|
|
52
|
+
rescue StandardError
|
|
50
53
|
nil
|
|
51
54
|
end
|
|
52
55
|
next unless source_file && source_file.start_with?(deps_dir.to_s)
|
|
53
56
|
|
|
54
|
-
sym = ActiveSupport::Inflector.underscore(ActiveSupport::Inflector.demodulize(
|
|
57
|
+
sym = ActiveSupport::Inflector.underscore(ActiveSupport::Inflector.demodulize(klass_name)).to_sym
|
|
55
58
|
unless Container.registered?(sym)
|
|
56
59
|
begin
|
|
57
60
|
Container.register(sym, klass.new)
|
|
58
|
-
rescue LoadError, StandardError
|
|
61
|
+
rescue LoadError, StandardError
|
|
59
62
|
# Skip deps that fail to instantiate (e.g. missing gem dependencies).
|
|
60
|
-
# These are typically alternative implementations not currently active.
|
|
61
63
|
end
|
|
62
64
|
end
|
|
63
65
|
end
|
|
64
66
|
end
|
|
65
67
|
|
|
68
|
+
# Safely retrieve a class name. Some gems (e.g. Faker::Travel::Airport)
|
|
69
|
+
# redefine .name with required keyword arguments, which raises ArgumentError
|
|
70
|
+
# when called without them. Returns nil if the name cannot be retrieved.
|
|
71
|
+
def safe_class_name(klass)
|
|
72
|
+
klass.name
|
|
73
|
+
rescue ArgumentError, NoMethodError
|
|
74
|
+
nil
|
|
75
|
+
end
|
|
76
|
+
|
|
66
77
|
def resolve_store_deps
|
|
67
78
|
# For each use case, check declared deps ending in _store or _repo
|
|
68
79
|
RageArch::UseCase::Base.registry.each_value do |klass|
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Ruby 4.0+ freezes array literals by default. ActionPack's MiddlewareStack#build
|
|
4
|
+
# calls `middlewares.freeze` which permanently freezes the internal array,
|
|
5
|
+
# preventing later initializers (e.g. Propshaft) from inserting middleware.
|
|
6
|
+
#
|
|
7
|
+
# This patch makes `build` freeze a dup instead of the original array.
|
|
8
|
+
if RUBY_VERSION >= '4.0'
|
|
9
|
+
require 'action_dispatch/middleware/stack'
|
|
10
|
+
|
|
11
|
+
ActionDispatch::MiddlewareStack.prepend(Module.new do
|
|
12
|
+
def build(app = nil, &block)
|
|
13
|
+
duped = middlewares.dup
|
|
14
|
+
duped.freeze.reverse.inject(app || block) do |a, e|
|
|
15
|
+
e.build(a)
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end)
|
|
19
|
+
end
|
data/lib/rage_arch/railtie.rb
CHANGED
data/lib/rage_arch/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rage_arch
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Rage Corp
|
|
@@ -111,6 +111,7 @@ files:
|
|
|
111
111
|
- lib/rage_arch/deps/active_record.rb
|
|
112
112
|
- lib/rage_arch/event_publisher.rb
|
|
113
113
|
- lib/rage_arch/fake_event_publisher.rb
|
|
114
|
+
- lib/rage_arch/patches/middleware_stack.rb
|
|
114
115
|
- lib/rage_arch/railtie.rb
|
|
115
116
|
- lib/rage_arch/result.rb
|
|
116
117
|
- lib/rage_arch/rspec_helpers.rb
|