rage_arch 0.1.0 → 0.1.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 +4 -4
- data/README.md +40 -28
- data/lib/generators/rage_arch/templates/ar_dep.rb.tt +1 -1
- data/lib/generators/rage_arch/templates/dep.rb.tt +1 -1
- data/lib/generators/rage_arch/templates/rage_arch.rb.tt +8 -4
- data/lib/rage_arch/railtie.rb +9 -1
- data/lib/rage_arch/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1efdb5d61edaeaed3b4f44b83933db1acda1a157730c0aace9084f62c7112cd4
|
|
4
|
+
data.tar.gz: 8fac4ebf0082380d5f24ae8db666de8247e317f9bb4835195c55a54c54fb58b1
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5f2b0e4d5f7dfe2f18b1497b967695d8a4a5d452fc7546b9661ee380955abb19b0f2cf6a59fecea1200e54eb3eaa84ec0d209f440d6145f766ee509413c84fc5
|
|
7
|
+
data.tar.gz: b1641934f744c9fc48f060105044b90b3a829b2ce27ad28d974d9343c4915f04a10df033dbf0351b0d5b059d6b542a57aa016ac7037ef91fd8272d7ed96b2552
|
data/README.md
CHANGED
|
@@ -12,33 +12,33 @@
|
|
|
12
12
|
|
|
13
13
|
```bash
|
|
14
14
|
bundle install
|
|
15
|
-
rails g
|
|
15
|
+
rails g rage_arch:install
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
-
Creates `config/initializers/
|
|
18
|
+
Creates `config/initializers/rage_arch.rb`, `app/use_cases/`, `app/deps/`, and injects `include RageArch::Controller` into `ApplicationController`.
|
|
19
19
|
|
|
20
20
|
---
|
|
21
21
|
|
|
22
22
|
## Components
|
|
23
23
|
|
|
24
|
-
### `
|
|
24
|
+
### `RageArch::Result` — typed result object
|
|
25
25
|
|
|
26
26
|
```ruby
|
|
27
|
-
result =
|
|
27
|
+
result = RageArch::Result.success(order)
|
|
28
28
|
result.success? # => true
|
|
29
29
|
result.value # => order
|
|
30
30
|
|
|
31
|
-
result =
|
|
31
|
+
result = RageArch::Result.failure(["Validation error"])
|
|
32
32
|
result.failure? # => true
|
|
33
33
|
result.errors # => ["Validation error"]
|
|
34
34
|
```
|
|
35
35
|
|
|
36
36
|
---
|
|
37
37
|
|
|
38
|
-
### `
|
|
38
|
+
### `RageArch::UseCase::Base` — use cases
|
|
39
39
|
|
|
40
40
|
```ruby
|
|
41
|
-
class CreateOrder <
|
|
41
|
+
class CreateOrder < RageArch::UseCase::Base
|
|
42
42
|
use_case_symbol :create_order
|
|
43
43
|
deps :order_store, :notifications # injected by symbol
|
|
44
44
|
|
|
@@ -54,23 +54,23 @@ end
|
|
|
54
54
|
Build and run manually:
|
|
55
55
|
|
|
56
56
|
```ruby
|
|
57
|
-
use_case =
|
|
57
|
+
use_case = RageArch::UseCase::Base.build(:create_order)
|
|
58
58
|
result = use_case.call(reference: "REF-1", total_cents: 1000)
|
|
59
59
|
```
|
|
60
60
|
|
|
61
61
|
---
|
|
62
62
|
|
|
63
|
-
### `
|
|
63
|
+
### `RageArch::Container` — dependency registration
|
|
64
64
|
|
|
65
65
|
```ruby
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
66
|
+
RageArch.register(:order_store, MyApp::Deps::OrderStore.new)
|
|
67
|
+
RageArch.register_ar(:user_store, User) # automatic ActiveRecord wrapper
|
|
68
|
+
RageArch.resolve(:order_store)
|
|
69
69
|
```
|
|
70
70
|
|
|
71
71
|
---
|
|
72
72
|
|
|
73
|
-
### `
|
|
73
|
+
### `RageArch::Controller` — thin controller mixin
|
|
74
74
|
|
|
75
75
|
```ruby
|
|
76
76
|
def create
|
|
@@ -86,12 +86,12 @@ end
|
|
|
86
86
|
|
|
87
87
|
---
|
|
88
88
|
|
|
89
|
-
### `
|
|
89
|
+
### `RageArch::EventPublisher` — domain events
|
|
90
90
|
|
|
91
91
|
Every use case automatically publishes an event when it finishes. Other use cases subscribe to react:
|
|
92
92
|
|
|
93
93
|
```ruby
|
|
94
|
-
class Notifications::SendPostCreatedEmail <
|
|
94
|
+
class Notifications::SendPostCreatedEmail < RageArch::UseCase::Base
|
|
95
95
|
use_case_symbol :send_post_created_email
|
|
96
96
|
deps :mailer
|
|
97
97
|
subscribe :posts_create # runs when :posts_create event is published
|
|
@@ -122,7 +122,7 @@ skip_auto_publish
|
|
|
122
122
|
### Orchestration — use cases calling use cases
|
|
123
123
|
|
|
124
124
|
```ruby
|
|
125
|
-
class CreateOrderWithNotification <
|
|
125
|
+
class CreateOrderWithNotification < RageArch::UseCase::Base
|
|
126
126
|
use_case_symbol :create_order_with_notification
|
|
127
127
|
deps :order_store
|
|
128
128
|
use_cases :orders_create, :notifications_send
|
|
@@ -142,13 +142,13 @@ end
|
|
|
142
142
|
|
|
143
143
|
| Command | What it does |
|
|
144
144
|
|---|---|
|
|
145
|
-
| `rails g
|
|
146
|
-
| `rails g
|
|
147
|
-
| `rails g
|
|
148
|
-
| `rails g
|
|
149
|
-
| `rails g
|
|
150
|
-
| `rails g
|
|
151
|
-
| `rails g
|
|
145
|
+
| `rails g rage_arch:install` | Initial setup (initializer, directories, controller mixin) |
|
|
146
|
+
| `rails g rage_arch:scaffold Post title:string` | Full CRUD: model, use cases, dep, controller, views, routes |
|
|
147
|
+
| `rails g rage_arch:scaffold Post title:string --api` | Same but API-only (JSON responses) |
|
|
148
|
+
| `rails g rage_arch:scaffold Post title:string --skip-model` | Skip model/migration if it already exists |
|
|
149
|
+
| `rails g rage_arch:use_case CreateOrder` | Generates a base use case file |
|
|
150
|
+
| `rails g rage_arch:dep post_store` | Generates a dep class by scanning method calls in use cases |
|
|
151
|
+
| `rails g rage_arch:ar_dep post_store Post` | Generates a dep that wraps an ActiveRecord model |
|
|
152
152
|
|
|
153
153
|
---
|
|
154
154
|
|
|
@@ -156,8 +156,8 @@ end
|
|
|
156
156
|
|
|
157
157
|
```ruby
|
|
158
158
|
# spec/rails_helper.rb
|
|
159
|
-
require "
|
|
160
|
-
require "
|
|
159
|
+
require "rage_arch/rspec_matchers"
|
|
160
|
+
require "rage_arch/fake_event_publisher"
|
|
161
161
|
```
|
|
162
162
|
|
|
163
163
|
**Result matchers:**
|
|
@@ -170,8 +170,8 @@ expect(result).to fail_with_errors(["Not found"])
|
|
|
170
170
|
**Fake event publisher:**
|
|
171
171
|
|
|
172
172
|
```ruby
|
|
173
|
-
publisher =
|
|
174
|
-
|
|
173
|
+
publisher = RageArch::FakeEventPublisher.new
|
|
174
|
+
RageArch.register(:event_publisher, publisher)
|
|
175
175
|
# ... run use case ...
|
|
176
176
|
expect(publisher.published).to include(hash_including(event: :post_created))
|
|
177
177
|
publisher.clear
|
|
@@ -179,11 +179,23 @@ publisher.clear
|
|
|
179
179
|
|
|
180
180
|
---
|
|
181
181
|
|
|
182
|
+
## Boot verification
|
|
183
|
+
|
|
184
|
+
At boot, `RageArch.verify_deps!` runs automatically and raises if any dep, method, or use case reference is unregistered. Disable with `config.rage.verify_deps = false`.
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
## Instrumentation
|
|
189
|
+
|
|
190
|
+
Every use case emits `"rage.use_case.run"` via `ActiveSupport::Notifications` with payload `symbol`, `params`, `success`, `errors`, `result`.
|
|
191
|
+
|
|
192
|
+
---
|
|
193
|
+
|
|
182
194
|
## Documentation
|
|
183
195
|
|
|
184
196
|
- [`doc/REFERENCE.md`](doc/REFERENCE.md) — Full API reference with all options and examples
|
|
185
197
|
- [`doc/DOCUMENTATION.md`](doc/DOCUMENTATION.md) — Detailed behaviour (use cases, deps, events, config)
|
|
186
|
-
- [`doc/
|
|
198
|
+
- [`doc/GETTING_STARTED.md`](doc/GETTING_STARTED.md) — Getting started guide with common tasks
|
|
187
199
|
|
|
188
200
|
## License
|
|
189
201
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
# Dep for :<%= symbol_name %>. Wraps the <%= model_name %> Active Record model.
|
|
4
|
-
# Register in config/initializers/rage_arch.rb:
|
|
4
|
+
# Register in config/initializers/rage_arch.rb: RageArch.register(:<%= symbol_name %>, <%= full_class_name %>.new)
|
|
5
5
|
module <%= module_name %>
|
|
6
6
|
class <%= class_name %>
|
|
7
7
|
def initialize
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
# Dep for :<%= symbol_name %>.
|
|
4
4
|
# Methods detected from use cases: <%= @methods.join(', ') %>.
|
|
5
|
-
# Register in config/initializers/rage_arch.rb:
|
|
5
|
+
# Register in config/initializers/rage_arch.rb: RageArch.register(:<%= symbol_name %>, <%= full_class_name %>.new)
|
|
6
6
|
module <%= module_name %>
|
|
7
7
|
class <%= class_name %>
|
|
8
8
|
<% @methods.each do |method_name| -%>
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
# Register your app's deps here. Deps are grouped by module (e.g. app/deps/posts/post_repo.rb → Posts::PostRepo).
|
|
4
|
-
# Use
|
|
4
|
+
# Use RageArch.register(:symbol, ClassName.new) or RageArch.register_ar(:symbol, Model) for AR-backed deps.
|
|
5
5
|
|
|
6
6
|
Rails.application.config.after_initialize do
|
|
7
7
|
# Deps
|
|
8
|
-
#
|
|
9
|
-
#
|
|
8
|
+
# RageArch.register(:post_repo, Posts::PostRepo.new)
|
|
9
|
+
# RageArch.register_ar(:user_repo, User)
|
|
10
10
|
|
|
11
11
|
# Event publisher: use cases that declare subscribe :event_name are wired here.
|
|
12
12
|
publisher = RageArch::EventPublisher.new
|
|
13
13
|
RageArch::UseCase::Base.wire_subscriptions_to(publisher)
|
|
14
|
-
|
|
14
|
+
RageArch.register(:event_publisher, publisher)
|
|
15
|
+
|
|
16
|
+
# Called here (after all deps are registered) instead of relying on the Railtie,
|
|
17
|
+
# which runs before this block. Skipped during asset precompilation.
|
|
18
|
+
RageArch.verify_deps! unless ENV["SECRET_KEY_BASE_DUMMY"].present?
|
|
15
19
|
end
|
data/lib/rage_arch/railtie.rb
CHANGED
|
@@ -12,12 +12,20 @@ module RageArch
|
|
|
12
12
|
# Load use case files so they register their symbols in the registry.
|
|
13
13
|
# Without this, build(:symbol) would fail until the use case constant was referenced.
|
|
14
14
|
config.after_initialize do |app|
|
|
15
|
+
# Skip everything during asset precompilation — no deps are registered then.
|
|
16
|
+
next if ENV["SECRET_KEY_BASE_DUMMY"].present?
|
|
17
|
+
|
|
15
18
|
use_cases_dir = app.root.join("app/use_cases")
|
|
16
19
|
if use_cases_dir.exist?
|
|
17
20
|
Dir[use_cases_dir.join("**/*.rb")].sort.each { |f| require f }
|
|
18
21
|
end
|
|
19
22
|
|
|
20
|
-
|
|
23
|
+
# NOTE: verify_deps! is intentionally NOT called here. This after_initialize
|
|
24
|
+
# runs before the app's own initializers' after_initialize blocks, so deps
|
|
25
|
+
# registered there would not be visible yet. Apps should call
|
|
26
|
+
# RageArch.verify_deps! manually at the end of their own after_initialize
|
|
27
|
+
# (config/initializers/rage_arch.rb), after all deps are registered.
|
|
28
|
+
# Set config.rage.verify_deps = false to opt out.
|
|
21
29
|
end
|
|
22
30
|
end
|
|
23
31
|
end
|
data/lib/rage_arch/version.rb
CHANGED