senro_usecaser 0.3.0 → 0.4.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/.rubocop.yml +4 -0
- data/CHANGELOG.md +30 -0
- data/README.md +655 -0
- data/examples/namespace_demo.rb +50 -15
- data/examples/order_system.rb +222 -34
- data/examples/sig/namespace_demo.rbs +35 -10
- data/examples/sig/order_system.rbs +196 -20
- data/lib/senro_usecaser/base.rb +308 -76
- data/lib/senro_usecaser/depends_on.rb +257 -0
- data/lib/senro_usecaser/hook.rb +28 -82
- data/lib/senro_usecaser/retry_configuration.rb +131 -0
- data/lib/senro_usecaser/retry_context.rb +133 -0
- data/lib/senro_usecaser/version.rb +1 -1
- data/lib/senro_usecaser.rb +3 -0
- data/sig/generated/senro_usecaser/base.rbs +143 -30
- data/sig/generated/senro_usecaser/depends_on.rbs +197 -0
- data/sig/generated/senro_usecaser/hook.rbs +23 -35
- data/sig/generated/senro_usecaser/retry_configuration.rbs +90 -0
- data/sig/generated/senro_usecaser/retry_context.rbs +101 -0
- data/sig/overrides.rbs +0 -1
- metadata +7 -1
data/examples/namespace_demo.rb
CHANGED
|
@@ -292,6 +292,12 @@ module NamespaceDemo
|
|
|
292
292
|
class ListPublicUsersUseCase < SenroUsecaser::Base
|
|
293
293
|
namespace :public
|
|
294
294
|
|
|
295
|
+
class Input
|
|
296
|
+
#: (**untyped) -> void
|
|
297
|
+
def initialize(**_rest)
|
|
298
|
+
end
|
|
299
|
+
end
|
|
300
|
+
|
|
295
301
|
class Output
|
|
296
302
|
#: (users: Array[User]) -> void
|
|
297
303
|
def initialize(users:)
|
|
@@ -309,10 +315,11 @@ module NamespaceDemo
|
|
|
309
315
|
# def user_repository: () -> Public::UserRepository
|
|
310
316
|
# def logger: () -> Logger
|
|
311
317
|
|
|
318
|
+
input Input
|
|
312
319
|
output Output
|
|
313
320
|
|
|
314
|
-
#: (
|
|
315
|
-
def call(_input
|
|
321
|
+
#: (Input) -> SenroUsecaser::Result[Output]
|
|
322
|
+
def call(_input)
|
|
316
323
|
logger.info("Public ユーザー一覧を取得")
|
|
317
324
|
users = user_repository.all
|
|
318
325
|
success(Output.new(users: users))
|
|
@@ -323,6 +330,12 @@ module NamespaceDemo
|
|
|
323
330
|
class ListAdminUsersUseCase < SenroUsecaser::Base
|
|
324
331
|
namespace :admin
|
|
325
332
|
|
|
333
|
+
class Input
|
|
334
|
+
#: (**untyped) -> void
|
|
335
|
+
def initialize(**_rest)
|
|
336
|
+
end
|
|
337
|
+
end
|
|
338
|
+
|
|
326
339
|
class Output
|
|
327
340
|
#: (users: Array[User]) -> void
|
|
328
341
|
def initialize(users:)
|
|
@@ -342,10 +355,11 @@ module NamespaceDemo
|
|
|
342
355
|
# def audit_logger: () -> Admin::AuditLogger
|
|
343
356
|
# def logger: () -> Logger
|
|
344
357
|
|
|
358
|
+
input Input
|
|
345
359
|
output Output
|
|
346
360
|
|
|
347
|
-
#: (
|
|
348
|
-
def call(_input
|
|
361
|
+
#: (Input) -> SenroUsecaser::Result[Output]
|
|
362
|
+
def call(_input)
|
|
349
363
|
logger.info("Admin ユーザー一覧を取得")
|
|
350
364
|
|
|
351
365
|
# 管理者操作なので監査ログを記録
|
|
@@ -416,6 +430,12 @@ module NamespaceDemo
|
|
|
416
430
|
class AdminActionUseCase < SenroUsecaser::Base
|
|
417
431
|
namespace :admin
|
|
418
432
|
|
|
433
|
+
class Input
|
|
434
|
+
#: (**untyped) -> void
|
|
435
|
+
def initialize(**_rest)
|
|
436
|
+
end
|
|
437
|
+
end
|
|
438
|
+
|
|
419
439
|
class Output
|
|
420
440
|
#: (message: String) -> void
|
|
421
441
|
def initialize(message:)
|
|
@@ -435,10 +455,11 @@ module NamespaceDemo
|
|
|
435
455
|
# def audit_logger: () -> Admin::AuditLogger
|
|
436
456
|
# def notification_service: () -> Admin::NotificationService
|
|
437
457
|
|
|
458
|
+
input Input
|
|
438
459
|
output Output
|
|
439
460
|
|
|
440
|
-
#: (
|
|
441
|
-
def call(_input
|
|
461
|
+
#: (Input) -> SenroUsecaser::Result[Output]
|
|
462
|
+
def call(_input)
|
|
442
463
|
audit_logger.log(action: "admin_action", performed_by: current_user)
|
|
443
464
|
notification_service.notify(current_user, "アクションを実行しました")
|
|
444
465
|
success(Output.new(message: "#{current_user.name} がアクションを実行"))
|
|
@@ -459,6 +480,12 @@ module Public
|
|
|
459
480
|
# infer_namespace_from_module = true の場合、モジュール名 "Public" から
|
|
460
481
|
# namespace "public" が自動的に推論される
|
|
461
482
|
|
|
483
|
+
class Input
|
|
484
|
+
#: (**untyped) -> void
|
|
485
|
+
def initialize(**_rest)
|
|
486
|
+
end
|
|
487
|
+
end
|
|
488
|
+
|
|
462
489
|
class Output
|
|
463
490
|
#: (message: String) -> void
|
|
464
491
|
def initialize(message:)
|
|
@@ -476,10 +503,11 @@ module Public
|
|
|
476
503
|
# def user_repository: () -> NamespaceDemo::Public::UserRepository
|
|
477
504
|
# def logger: () -> NamespaceDemo::Logger
|
|
478
505
|
|
|
506
|
+
input Input
|
|
479
507
|
output Output
|
|
480
508
|
|
|
481
|
-
#: (
|
|
482
|
-
def call(_input
|
|
509
|
+
#: (Input) -> SenroUsecaser::Result[Output]
|
|
510
|
+
def call(_input)
|
|
483
511
|
logger.info("InferredUseCase: namespace を自動推論して実行")
|
|
484
512
|
users = user_repository.all
|
|
485
513
|
success(Output.new(message: "#{users.length} 人のユーザーを取得(namespace 自動推論)"))
|
|
@@ -495,6 +523,12 @@ module Admin
|
|
|
495
523
|
# infer_namespace_from_module = true の場合、モジュール名から
|
|
496
524
|
# namespace "admin::reports" が自動的に推論される
|
|
497
525
|
|
|
526
|
+
class Input
|
|
527
|
+
#: (**untyped) -> void
|
|
528
|
+
def initialize(**_rest)
|
|
529
|
+
end
|
|
530
|
+
end
|
|
531
|
+
|
|
498
532
|
class Output
|
|
499
533
|
#: (message: String) -> void
|
|
500
534
|
def initialize(message:)
|
|
@@ -514,10 +548,11 @@ module Admin
|
|
|
514
548
|
# def user_repository: () -> NamespaceDemo::Admin::UserRepository
|
|
515
549
|
# def logger: () -> NamespaceDemo::Logger
|
|
516
550
|
|
|
551
|
+
input Input
|
|
517
552
|
output Output
|
|
518
553
|
|
|
519
|
-
#: (
|
|
520
|
-
def call(_input
|
|
554
|
+
#: (Input) -> SenroUsecaser::Result[Output]
|
|
555
|
+
def call(_input)
|
|
521
556
|
logger.info("InferredReportUseCase: ネストした namespace を自動推論して実行")
|
|
522
557
|
users = user_repository.all
|
|
523
558
|
report = report_generator.generate("inferred_report", { count: users.length })
|
|
@@ -604,7 +639,7 @@ puts
|
|
|
604
639
|
puts "4. Public namespace UseCase 実行"
|
|
605
640
|
puts "-" * 70
|
|
606
641
|
|
|
607
|
-
result = NamespaceDemo::ListPublicUsersUseCase.call
|
|
642
|
+
result = NamespaceDemo::ListPublicUsersUseCase.call(NamespaceDemo::ListPublicUsersUseCase::Input.new)
|
|
608
643
|
if result.success?
|
|
609
644
|
output = result.value!
|
|
610
645
|
puts " 取得したユーザー数: #{output.users.length}"
|
|
@@ -618,7 +653,7 @@ puts
|
|
|
618
653
|
puts "5. Admin namespace UseCase 実行"
|
|
619
654
|
puts "-" * 70
|
|
620
655
|
|
|
621
|
-
result = NamespaceDemo::ListAdminUsersUseCase.call
|
|
656
|
+
result = NamespaceDemo::ListAdminUsersUseCase.call(NamespaceDemo::ListAdminUsersUseCase::Input.new)
|
|
622
657
|
if result.success?
|
|
623
658
|
output = result.value!
|
|
624
659
|
puts " 取得した管理者数: #{output.users.length}"
|
|
@@ -673,7 +708,7 @@ scoped_container = container.scope do
|
|
|
673
708
|
end
|
|
674
709
|
end
|
|
675
710
|
|
|
676
|
-
result = NamespaceDemo::AdminActionUseCase.call(container: scoped_container)
|
|
711
|
+
result = NamespaceDemo::AdminActionUseCase.call(NamespaceDemo::AdminActionUseCase::Input.new, container: scoped_container)
|
|
677
712
|
if result.success?
|
|
678
713
|
output = result.value!
|
|
679
714
|
puts " 結果: #{output.message}"
|
|
@@ -705,7 +740,7 @@ puts " infer_namespace_from_module = true に設定"
|
|
|
705
740
|
# Public::InferredUseCase は namespace を明示していないが、
|
|
706
741
|
# モジュール名から "public" namespace が推論される
|
|
707
742
|
puts " Public::InferredUseCase を実行(namespace 自動推論):"
|
|
708
|
-
result = Public::InferredUseCase.call
|
|
743
|
+
result = Public::InferredUseCase.call(Public::InferredUseCase::Input.new)
|
|
709
744
|
if result.success?
|
|
710
745
|
output = result.value!
|
|
711
746
|
puts " 結果: #{output.message}"
|
|
@@ -714,7 +749,7 @@ end
|
|
|
714
749
|
# Admin::Reports::InferredReportUseCase はネストしたモジュールから
|
|
715
750
|
# "admin::reports" namespace が推論される
|
|
716
751
|
puts " Admin::Reports::InferredReportUseCase を実行(ネストした namespace 自動推論):"
|
|
717
|
-
result = Admin::Reports::InferredReportUseCase.call
|
|
752
|
+
result = Admin::Reports::InferredReportUseCase.call(Admin::Reports::InferredReportUseCase::Input.new)
|
|
718
753
|
if result.success?
|
|
719
754
|
output = result.value!
|
|
720
755
|
puts " 結果: #{output.message}"
|