senro_usecaser 0.3.0 → 0.4.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.
@@ -326,6 +326,91 @@ class DevelopmentProvider < SenroUsecaser::Provider
326
326
  end
327
327
  end
328
328
 
329
+ # =============================================================================
330
+ # パイプライン Input インターフェース
331
+ # =============================================================================
332
+ # パイプラインでは前のステップの Output が次のステップの Input になります。
333
+ # 各ステップが期待する属性をインターフェースとして定義し、
334
+ # `input InterfaceModule` で型チェックを行います。
335
+
336
+ # 最初のステップ用(user_id, product_ids)
337
+ module OrderRequestInput
338
+ #: () -> Integer
339
+ def user_id = raise NotImplementedError
340
+
341
+ #: () -> Array[Integer]
342
+ def product_ids = raise NotImplementedError
343
+ end
344
+
345
+ # ユーザー検証後(user, product_ids)
346
+ module ValidatedUserInput
347
+ #: () -> User
348
+ def user = raise NotImplementedError
349
+
350
+ #: () -> Array[Integer]
351
+ def product_ids = raise NotImplementedError
352
+ end
353
+
354
+ # 商品検証後(user, items, subtotal)
355
+ module ValidatedProductsInput
356
+ #: () -> User
357
+ def user = raise NotImplementedError
358
+
359
+ #: () -> Array[Product]
360
+ def items = raise NotImplementedError
361
+
362
+ #: () -> Integer
363
+ def subtotal = raise NotImplementedError
364
+ end
365
+
366
+ # 税計算後(user, items, subtotal, tax)
367
+ module TaxCalculatedInput
368
+ #: () -> User
369
+ def user = raise NotImplementedError
370
+
371
+ #: () -> Array[Product]
372
+ def items = raise NotImplementedError
373
+
374
+ #: () -> Integer
375
+ def subtotal = raise NotImplementedError
376
+
377
+ #: () -> Integer
378
+ def tax = raise NotImplementedError
379
+ end
380
+
381
+ # 割引適用後(user, items, subtotal, tax, discount)
382
+ # TaxCalculatedInput を継承
383
+ module DiscountAppliedInput
384
+ include TaxCalculatedInput
385
+
386
+ #: () -> Integer
387
+ def discount = raise NotImplementedError
388
+ end
389
+
390
+ # 合計計算後(user, items, subtotal, tax, discount, total)
391
+ # DiscountAppliedInput を継承(TaxCalculatedInput も含む)
392
+ module TotalCalculatedInput
393
+ include DiscountAppliedInput
394
+
395
+ #: () -> Integer
396
+ def total = raise NotImplementedError
397
+ end
398
+
399
+ # 注文作成後(user, order)
400
+ module OrderCreatedInput
401
+ #: () -> User
402
+ def user = raise NotImplementedError
403
+
404
+ #: () -> Order
405
+ def order = raise NotImplementedError
406
+ end
407
+
408
+ # 最終出力用(order)
409
+ module FinalOrderInput
410
+ #: () -> Order
411
+ def order = raise NotImplementedError
412
+ end
413
+
329
414
  # =============================================================================
330
415
  # 個別 UseCase(パイプラインステップ)
331
416
  # =============================================================================
@@ -333,6 +418,8 @@ end
333
418
  # ユーザー検証
334
419
  class ValidateUserUseCase < SenroUsecaser::Base
335
420
  class Input
421
+ include OrderRequestInput
422
+
336
423
  #: (user_id: Integer, product_ids: Array[Integer], **untyped) -> void
337
424
  def initialize(user_id:, product_ids:, **_rest)
338
425
  @user_id = user_id #: Integer
@@ -347,6 +434,8 @@ class ValidateUserUseCase < SenroUsecaser::Base
347
434
  end
348
435
 
349
436
  class Output
437
+ include ValidatedUserInput
438
+
350
439
  #: (user: User, product_ids: Array[Integer], **untyped) -> void
351
440
  def initialize(user:, product_ids:, **_rest)
352
441
  @user = user #: User
@@ -365,7 +454,7 @@ class ValidateUserUseCase < SenroUsecaser::Base
365
454
  # @rbs!
366
455
  # def user_repository: () -> UserRepository
367
456
 
368
- input Input
457
+ input OrderRequestInput
369
458
  output Output
370
459
 
371
460
  #: (Input) -> SenroUsecaser::Result[Output]
@@ -380,6 +469,8 @@ end
380
469
  # 商品検証と在庫チェック
381
470
  class ValidateProductsUseCase < SenroUsecaser::Base
382
471
  class Input
472
+ include ValidatedUserInput
473
+
383
474
  #: (user: User, product_ids: Array[Integer], **untyped) -> void
384
475
  def initialize(user:, product_ids:, **_rest)
385
476
  @user = user #: User
@@ -394,6 +485,8 @@ class ValidateProductsUseCase < SenroUsecaser::Base
394
485
  end
395
486
 
396
487
  class Output
488
+ include ValidatedProductsInput
489
+
397
490
  #: (user: User, items: Array[Product], subtotal: Integer, **untyped) -> void
398
491
  def initialize(user:, items:, subtotal:, **_rest)
399
492
  @user = user #: User
@@ -416,7 +509,7 @@ class ValidateProductsUseCase < SenroUsecaser::Base
416
509
  # @rbs!
417
510
  # def product_repository: () -> ProductRepository
418
511
 
419
- input Input
512
+ input ValidatedUserInput
420
513
  output Output
421
514
 
422
515
  #: (Input) -> SenroUsecaser::Result[Output]
@@ -443,6 +536,8 @@ end
443
536
  # 税金計算
444
537
  class CalculateTaxUseCase < SenroUsecaser::Base
445
538
  class Input
539
+ include ValidatedProductsInput
540
+
446
541
  #: (user: User, items: Array[Product], subtotal: Integer, **untyped) -> void
447
542
  def initialize(user:, items:, subtotal:, **_rest)
448
543
  @user = user #: User
@@ -461,6 +556,8 @@ class CalculateTaxUseCase < SenroUsecaser::Base
461
556
  end
462
557
 
463
558
  class Output
559
+ include TaxCalculatedInput
560
+
464
561
  #: (user: User, items: Array[Product], subtotal: Integer, tax: Integer, **untyped) -> void
465
562
  def initialize(user:, items:, subtotal:, tax:, **_rest)
466
563
  @user = user #: User
@@ -482,7 +579,7 @@ class CalculateTaxUseCase < SenroUsecaser::Base
482
579
  attr_reader :tax
483
580
  end
484
581
 
485
- input Input
582
+ input ValidatedProductsInput
486
583
  output Output
487
584
 
488
585
  #: (Input) -> SenroUsecaser::Result[Output]
@@ -495,6 +592,8 @@ end
495
592
  # プレミアム会員割引
496
593
  class ApplyPremiumDiscountUseCase < SenroUsecaser::Base
497
594
  class Input
595
+ include TaxCalculatedInput
596
+
498
597
  #: (user: User, items: Array[Product], subtotal: Integer, tax: Integer, **untyped) -> void
499
598
  def initialize(user:, items:, subtotal:, tax:, **_rest)
500
599
  @user = user #: User
@@ -517,6 +616,8 @@ class ApplyPremiumDiscountUseCase < SenroUsecaser::Base
517
616
  end
518
617
 
519
618
  class Output
619
+ include DiscountAppliedInput
620
+
520
621
  #: (user: User, items: Array[Product], subtotal: Integer, tax: Integer, discount: Integer, **untyped) -> void
521
622
  def initialize(user:, items:, subtotal:, tax:, discount:, **_rest)
522
623
  @user = user #: User
@@ -547,7 +648,7 @@ class ApplyPremiumDiscountUseCase < SenroUsecaser::Base
547
648
  # @rbs!
548
649
  # def discount_service: () -> DiscountService
549
650
 
550
- input Input
651
+ input TaxCalculatedInput
551
652
  output Output
552
653
 
553
654
  #: (Input) -> SenroUsecaser::Result[Output]
@@ -560,8 +661,12 @@ class ApplyPremiumDiscountUseCase < SenroUsecaser::Base
560
661
  end
561
662
 
562
663
  # 合計計算
664
+ # Note: TaxCalculatedInput または DiscountAppliedInput のどちらも受け入れる
665
+ # discount がない場合はデフォルト値 0 を使用
563
666
  class CalculateTotalUseCase < SenroUsecaser::Base
564
667
  class Input
668
+ include TaxCalculatedInput
669
+
565
670
  #: (user: User, items: Array[Product], subtotal: Integer, tax: Integer, ?discount: Integer, **untyped) -> void
566
671
  def initialize(user:, items:, subtotal:, tax:, discount: 0, **_rest)
567
672
  @user = user #: User
@@ -588,6 +693,8 @@ class CalculateTotalUseCase < SenroUsecaser::Base
588
693
  end
589
694
 
590
695
  class Output
696
+ include TotalCalculatedInput
697
+
591
698
  #: (user: User, items: Array[Product], subtotal: Integer, tax: Integer, discount: Integer, total: Integer, **untyped) -> void
592
699
  def initialize(user:, items:, subtotal:, tax:, discount:, total:, **_rest)
593
700
  @user = user #: User
@@ -617,15 +724,17 @@ class CalculateTotalUseCase < SenroUsecaser::Base
617
724
  attr_reader :total
618
725
  end
619
726
 
620
- input Input
727
+ input TaxCalculatedInput
621
728
  output Output
622
729
 
623
- #: (Input) -> SenroUsecaser::Result[Output]
730
+ #: (TaxCalculatedInput) -> SenroUsecaser::Result[Output]
624
731
  def call(input)
625
- total = input.subtotal + input.tax - input.discount
732
+ # ApplyPremiumDiscountUseCase がスキップされた場合は discount がない
733
+ discount = input.respond_to?(:discount) ? input.discount : 0 # steep:ignore NoMethod
734
+ total = input.subtotal + input.tax - discount
626
735
  success(Output.new(
627
736
  user: input.user, items: input.items, subtotal: input.subtotal,
628
- tax: input.tax, discount: input.discount, total: total
737
+ tax: input.tax, discount: discount, total: total
629
738
  ))
630
739
  end
631
740
  end
@@ -633,6 +742,8 @@ end
633
742
  # 決済処理
634
743
  class ProcessPaymentUseCase < SenroUsecaser::Base
635
744
  class Input
745
+ include TotalCalculatedInput
746
+
636
747
  #: (user: User, items: Array[Product], subtotal: Integer, tax: Integer, discount: Integer, total: Integer, **untyped) -> void
637
748
  def initialize(user:, items:, subtotal:, tax:, discount:, total:, **_rest)
638
749
  @user = user #: User
@@ -663,6 +774,8 @@ class ProcessPaymentUseCase < SenroUsecaser::Base
663
774
  end
664
775
 
665
776
  class Output
777
+ include TotalCalculatedInput
778
+
666
779
  #: (user: User, items: Array[Product], subtotal: Integer, tax: Integer, discount: Integer, total: Integer, payment: PaymentResult, **untyped) -> void
667
780
  def initialize(user:, items:, subtotal:, tax:, discount:, total:, payment:, **_rest)
668
781
  @user = user #: User
@@ -701,7 +814,7 @@ class ProcessPaymentUseCase < SenroUsecaser::Base
701
814
  # @rbs!
702
815
  # def payment_service: () -> PaymentService
703
816
 
704
- input Input
817
+ input TotalCalculatedInput
705
818
  output Output
706
819
 
707
820
  #: (Input) -> SenroUsecaser::Result[Output]
@@ -717,6 +830,8 @@ end
717
830
  # 注文作成
718
831
  class CreateOrderRecordUseCase < SenroUsecaser::Base
719
832
  class Input
833
+ include TotalCalculatedInput
834
+
720
835
  #: (user: User, items: Array[Product], subtotal: Integer, tax: Integer, discount: Integer, total: Integer, **untyped) -> void
721
836
  def initialize(user:, items:, subtotal:, tax:, discount:, total:, **_rest)
722
837
  @user = user #: User
@@ -747,6 +862,8 @@ class CreateOrderRecordUseCase < SenroUsecaser::Base
747
862
  end
748
863
 
749
864
  class Output
865
+ include OrderCreatedInput
866
+
750
867
  #: (user: User, order: Order, **untyped) -> void
751
868
  def initialize(user:, order:, **_rest)
752
869
  @user = user #: User
@@ -765,7 +882,7 @@ class CreateOrderRecordUseCase < SenroUsecaser::Base
765
882
  # @rbs!
766
883
  # def order_repository: () -> OrderRepository
767
884
 
768
- input Input
885
+ input TotalCalculatedInput
769
886
  output Output
770
887
 
771
888
  #: (Input) -> SenroUsecaser::Result[Output]
@@ -785,6 +902,8 @@ end
785
902
  # 通知送信
786
903
  class SendOrderNotificationUseCase < SenroUsecaser::Base
787
904
  class Input
905
+ include OrderCreatedInput
906
+
788
907
  #: (user: User, order: Order, **untyped) -> void
789
908
  def initialize(user:, order:, **_rest)
790
909
  @user = user #: User
@@ -799,6 +918,8 @@ class SendOrderNotificationUseCase < SenroUsecaser::Base
799
918
  end
800
919
 
801
920
  class Output
921
+ include FinalOrderInput
922
+
802
923
  #: (user: User, order: Order, notified: bool, **untyped) -> void
803
924
  def initialize(user:, order:, notified:, **_rest)
804
925
  @user = user #: User
@@ -821,10 +942,10 @@ class SendOrderNotificationUseCase < SenroUsecaser::Base
821
942
  # @rbs!
822
943
  # def notification_service: () -> NotificationService
823
944
 
824
- input Input
945
+ input OrderCreatedInput
825
946
  output Output
826
947
 
827
- #: (Input) -> SenroUsecaser::Result[Output]
948
+ #: (OrderCreatedInput) -> SenroUsecaser::Result[Output]
828
949
  def call(input)
829
950
  notification_service.send_email(
830
951
  to: input.user.email,
@@ -838,6 +959,8 @@ end
838
959
  # パイプライン最終出力をラップ
839
960
  class WrapOrderOutputUseCase < SenroUsecaser::Base
840
961
  class Input
962
+ include FinalOrderInput
963
+
841
964
  #: (order: Order, **untyped) -> void
842
965
  def initialize(order:, **_rest)
843
966
  @order = order #: Order
@@ -847,7 +970,7 @@ class WrapOrderOutputUseCase < SenroUsecaser::Base
847
970
  attr_reader :order
848
971
  end
849
972
 
850
- input Input
973
+ input FinalOrderInput
851
974
  output CreateOrderOutput
852
975
 
853
976
  #: (Input) -> SenroUsecaser::Result[CreateOrderOutput]
@@ -862,13 +985,13 @@ end
862
985
 
863
986
  # ログ記録用 Extension
864
987
  module LoggingExtension
865
- #: (Hash[Symbol, untyped]) -> void
866
- def self.before(context)
867
- puts " [Logging] UseCase 開始: #{context.keys.join(", ")}"
988
+ #: (untyped) -> void
989
+ def self.before(input)
990
+ puts " [Logging] UseCase 開始: #{input.class.name}"
868
991
  end
869
992
 
870
- #: (Hash[Symbol, untyped], SenroUsecaser::Result[untyped]) -> void
871
- def self.after(_context, result)
993
+ #: (untyped, SenroUsecaser::Result[untyped]) -> void
994
+ def self.after(_input, result)
872
995
  status = result.success? ? "成功" : "失敗"
873
996
  puts " [Logging] UseCase 終了: #{status}"
874
997
  end
@@ -877,6 +1000,8 @@ end
877
1000
  # 注文作成パイプライン
878
1001
  class CreateOrderUseCase < SenroUsecaser::Base
879
1002
  class Input
1003
+ include OrderRequestInput
1004
+
880
1005
  #: (user_id: Integer, product_ids: Array[Integer], **untyped) -> void
881
1006
  def initialize(user_id:, product_ids:, **_rest)
882
1007
  @user_id = user_id #: Integer
@@ -910,10 +1035,9 @@ class CreateOrderUseCase < SenroUsecaser::Base
910
1035
  step WrapOrderOutputUseCase
911
1036
  end
912
1037
 
913
- #: (Hash[Symbol, untyped]) -> bool
914
- def premium_user?(context)
915
- user = context[:user] #: User?
916
- user&.premium? || false
1038
+ #: (TaxCalculatedInput) -> bool
1039
+ def premium_user?(input)
1040
+ input.user.premium?
917
1041
  end
918
1042
  end
919
1043
 
@@ -1016,6 +1140,13 @@ puts "-" * 70
1016
1140
 
1017
1141
  # リクエストごとに current_user を注入するパターン
1018
1142
  class CurrentUserAwareUseCase < SenroUsecaser::Base
1143
+ # 空のInputクラス(入力不要なUseCase用)
1144
+ class Input
1145
+ #: (**untyped) -> void
1146
+ def initialize(**_rest)
1147
+ end
1148
+ end
1149
+
1019
1150
  depends_on :current_user, User
1020
1151
  depends_on :logger, Logger
1021
1152
 
@@ -1023,10 +1154,11 @@ class CurrentUserAwareUseCase < SenroUsecaser::Base
1023
1154
  # def current_user: () -> User
1024
1155
  # def logger: () -> Logger
1025
1156
 
1157
+ input Input
1026
1158
  output GreetingOutput
1027
1159
 
1028
- #: (?untyped, **untyped) -> SenroUsecaser::Result[GreetingOutput]
1029
- def call(_input = nil, **_args)
1160
+ #: (Input) -> SenroUsecaser::Result[GreetingOutput]
1161
+ def call(_input)
1030
1162
  logger.info("現在のユーザー: #{current_user.name}")
1031
1163
  success(GreetingOutput.new(greeted: "こんにちは、#{current_user.name}さん!"))
1032
1164
  end
@@ -1039,7 +1171,7 @@ scoped_container = SenroUsecaser.container.scope do
1039
1171
  register(:current_user, current_user)
1040
1172
  end
1041
1173
 
1042
- result = CurrentUserAwareUseCase.call(container: scoped_container)
1174
+ result = CurrentUserAwareUseCase.call(CurrentUserAwareUseCase::Input.new, container: scoped_container)
1043
1175
  if result.success?
1044
1176
  value = result.value!
1045
1177
  puts " #{value.greeted}"
@@ -1071,8 +1203,48 @@ puts
1071
1203
  puts "9. Accumulated Context の確認"
1072
1204
  puts "-" * 70
1073
1205
 
1206
+ # Accumulated Context 用インターフェース
1207
+ module InitialInput
1208
+ #: () -> String
1209
+ def initial = raise NotImplementedError
1210
+ end
1211
+
1212
+ module Step1Output
1213
+ #: () -> String
1214
+ def step1_data = raise NotImplementedError
1215
+
1216
+ #: () -> Integer
1217
+ def counter = raise NotImplementedError
1218
+ end
1219
+
1220
+ module Step2Output
1221
+ include Step1Output
1222
+
1223
+ #: () -> String
1224
+ def step2_data = raise NotImplementedError
1225
+ end
1226
+
1227
+ module FinalAccumulatedInput
1228
+ #: () -> Integer
1229
+ def counter = raise NotImplementedError
1230
+
1231
+ #: () -> bool
1232
+ def final = raise NotImplementedError
1233
+ end
1234
+
1235
+ module Step3Output
1236
+ include Step2Output
1237
+ include FinalAccumulatedInput
1238
+
1239
+ #: () -> String
1240
+ def step3_data = raise NotImplementedError
1241
+ end
1242
+
1243
+
1074
1244
  class Step1 < SenroUsecaser::Base
1075
1245
  class Input
1246
+ include InitialInput
1247
+
1076
1248
  #: (initial: String, **untyped) -> void
1077
1249
  def initialize(initial:, **_rest)
1078
1250
  @initial = initial #: String
@@ -1083,6 +1255,8 @@ class Step1 < SenroUsecaser::Base
1083
1255
  end
1084
1256
 
1085
1257
  class Output
1258
+ include Step1Output
1259
+
1086
1260
  #: (step1_data: String, counter: Integer, **untyped) -> void
1087
1261
  def initialize(step1_data:, counter:, **_rest)
1088
1262
  @step1_data = step1_data #: String
@@ -1096,10 +1270,10 @@ class Step1 < SenroUsecaser::Base
1096
1270
  attr_reader :counter
1097
1271
  end
1098
1272
 
1099
- input Input
1273
+ input InitialInput
1100
1274
  output Output
1101
1275
 
1102
- #: (Input) -> SenroUsecaser::Result[Output]
1276
+ #: (InitialInput) -> SenroUsecaser::Result[Output]
1103
1277
  def call(_input)
1104
1278
  success(Output.new(step1_data: "from step1", counter: 1))
1105
1279
  end
@@ -1107,6 +1281,8 @@ end
1107
1281
 
1108
1282
  class Step2 < SenroUsecaser::Base
1109
1283
  class Input
1284
+ include Step1Output
1285
+
1110
1286
  #: (step1_data: String, counter: Integer, **untyped) -> void
1111
1287
  def initialize(step1_data:, counter:, **_rest)
1112
1288
  @step1_data = step1_data #: String
@@ -1121,6 +1297,8 @@ class Step2 < SenroUsecaser::Base
1121
1297
  end
1122
1298
 
1123
1299
  class Output
1300
+ include Step2Output
1301
+
1124
1302
  #: (step1_data: String, step2_data: String, counter: Integer, **untyped) -> void
1125
1303
  def initialize(step1_data:, step2_data:, counter:, **_rest)
1126
1304
  @step1_data = step1_data #: String
@@ -1138,10 +1316,10 @@ class Step2 < SenroUsecaser::Base
1138
1316
  attr_reader :counter
1139
1317
  end
1140
1318
 
1141
- input Input
1319
+ input Step1Output
1142
1320
  output Output
1143
1321
 
1144
- #: (Input) -> SenroUsecaser::Result[Output]
1322
+ #: (Step1Output) -> SenroUsecaser::Result[Output]
1145
1323
  def call(input)
1146
1324
  success(Output.new(step1_data: input.step1_data, step2_data: "from step2", counter: input.counter + 1))
1147
1325
  end
@@ -1149,6 +1327,8 @@ end
1149
1327
 
1150
1328
  class Step3 < SenroUsecaser::Base
1151
1329
  class Input
1330
+ include Step2Output
1331
+
1152
1332
  #: (step1_data: String, step2_data: String, counter: Integer, **untyped) -> void
1153
1333
  def initialize(step1_data:, step2_data:, counter:, **_rest)
1154
1334
  @step1_data = step1_data #: String
@@ -1167,6 +1347,8 @@ class Step3 < SenroUsecaser::Base
1167
1347
  end
1168
1348
 
1169
1349
  class Output
1350
+ include Step3Output
1351
+
1170
1352
  #: (step1_data: String, step2_data: String, step3_data: String, counter: Integer, final: bool, **untyped) -> void
1171
1353
  def initialize(step1_data:, step2_data:, step3_data:, counter:, final:, **_rest)
1172
1354
  @step1_data = step1_data #: String
@@ -1192,13 +1374,15 @@ class Step3 < SenroUsecaser::Base
1192
1374
  attr_reader :final
1193
1375
  end
1194
1376
 
1195
- input Input
1377
+ # Step2がスキップされる場合を考慮してStep1Outputも受け付ける
1378
+ input Step1Output
1196
1379
  output Output
1197
1380
 
1198
- #: (Input) -> SenroUsecaser::Result[Output]
1381
+ #: (Step1Output) -> SenroUsecaser::Result[Output]
1199
1382
  def call(input)
1383
+ step2_data = input.respond_to?(:step2_data) ? input.step2_data : "skipped" # steep:ignore NoMethod
1200
1384
  success(Output.new(
1201
- step1_data: input.step1_data, step2_data: input.step2_data,
1385
+ step1_data: input.step1_data, step2_data: step2_data,
1202
1386
  step3_data: "from step3", counter: input.counter + 1, final: true
1203
1387
  ))
1204
1388
  end
@@ -1206,6 +1390,8 @@ end
1206
1390
 
1207
1391
  class WrapAccumulatedOutputUseCase < SenroUsecaser::Base
1208
1392
  class Input
1393
+ include FinalAccumulatedInput
1394
+
1209
1395
  #: (counter: Integer, final: bool, **untyped) -> void
1210
1396
  def initialize(counter:, final:, **_rest)
1211
1397
  @counter = counter #: Integer
@@ -1219,10 +1405,10 @@ class WrapAccumulatedOutputUseCase < SenroUsecaser::Base
1219
1405
  attr_reader :final
1220
1406
  end
1221
1407
 
1222
- input Input
1408
+ input FinalAccumulatedInput
1223
1409
  output AccumulatedOutput
1224
1410
 
1225
- #: (Input) -> SenroUsecaser::Result[AccumulatedOutput]
1411
+ #: (FinalAccumulatedInput) -> SenroUsecaser::Result[AccumulatedOutput]
1226
1412
  def call(input)
1227
1413
  success(AccumulatedOutput.new(counter: input.counter, final: input.final))
1228
1414
  end
@@ -1230,6 +1416,8 @@ end
1230
1416
 
1231
1417
  class AccumulatedContextDemo < SenroUsecaser::Base
1232
1418
  class Input
1419
+ include InitialInput
1420
+
1233
1421
  #: (initial: String, **untyped) -> void
1234
1422
  def initialize(initial:, **_rest)
1235
1423
  @initial = initial #: String
@@ -137,6 +137,11 @@ module NamespaceDemo
137
137
 
138
138
  # Public namespace の UseCase
139
139
  class ListPublicUsersUseCase < SenroUsecaser::Base
140
+ class Input
141
+ # : (**untyped) -> void
142
+ def initialize: (**untyped) -> void
143
+ end
144
+
140
145
  class Output
141
146
  # : (users: Array[User]) -> void
142
147
  def initialize: (users: Array[User]) -> void
@@ -149,12 +154,17 @@ module NamespaceDemo
149
154
 
150
155
  def logger: () -> Logger
151
156
 
152
- # : (?untyped, **untyped) -> SenroUsecaser::Result[Output]
153
- def call: (?untyped, **untyped) -> SenroUsecaser::Result[Output]
157
+ # : (Input) -> SenroUsecaser::Result[Output]
158
+ def call: (Input) -> SenroUsecaser::Result[Output]
154
159
  end
155
160
 
156
161
  # Admin namespace の UseCase
157
162
  class ListAdminUsersUseCase < SenroUsecaser::Base
163
+ class Input
164
+ # : (**untyped) -> void
165
+ def initialize: (**untyped) -> void
166
+ end
167
+
158
168
  class Output
159
169
  # : (users: Array[User]) -> void
160
170
  def initialize: (users: Array[User]) -> void
@@ -169,8 +179,8 @@ module NamespaceDemo
169
179
 
170
180
  def logger: () -> Logger
171
181
 
172
- # : (?untyped, **untyped) -> SenroUsecaser::Result[Output]
173
- def call: (?untyped, **untyped) -> SenroUsecaser::Result[Output]
182
+ # : (Input) -> SenroUsecaser::Result[Output]
183
+ def call: (Input) -> SenroUsecaser::Result[Output]
174
184
  end
175
185
 
176
186
  # Admin::Reports namespace の UseCase(ネストした namespace)
@@ -207,6 +217,11 @@ module NamespaceDemo
207
217
 
208
218
  # リクエストスコープで current_user を注入しつつ、namespace を活用
209
219
  class AdminActionUseCase < SenroUsecaser::Base
220
+ class Input
221
+ # : (**untyped) -> void
222
+ def initialize: (**untyped) -> void
223
+ end
224
+
210
225
  class Output
211
226
  # : (message: String) -> void
212
227
  def initialize: (message: String) -> void
@@ -221,14 +236,19 @@ module NamespaceDemo
221
236
 
222
237
  def notification_service: () -> Admin::NotificationService
223
238
 
224
- # : (?untyped, **untyped) -> SenroUsecaser::Result[Output]
225
- def call: (?untyped, **untyped) -> SenroUsecaser::Result[Output]
239
+ # : (Input) -> SenroUsecaser::Result[Output]
240
+ def call: (Input) -> SenroUsecaser::Result[Output]
226
241
  end
227
242
  end
228
243
 
229
244
  # Public::InferredUseCase → namespace "public" として推論
230
245
  module Public
231
246
  class InferredUseCase < SenroUsecaser::Base
247
+ class Input
248
+ # : (**untyped) -> void
249
+ def initialize: (**untyped) -> void
250
+ end
251
+
232
252
  class Output
233
253
  # : (message: String) -> void
234
254
  def initialize: (message: String) -> void
@@ -241,8 +261,8 @@ module Public
241
261
 
242
262
  def logger: () -> NamespaceDemo::Logger
243
263
 
244
- # : (?untyped, **untyped) -> SenroUsecaser::Result[Output]
245
- def call: (?untyped, **untyped) -> SenroUsecaser::Result[Output]
264
+ # : (Input) -> SenroUsecaser::Result[Output]
265
+ def call: (Input) -> SenroUsecaser::Result[Output]
246
266
  end
247
267
  end
248
268
 
@@ -250,6 +270,11 @@ end
250
270
  module Admin
251
271
  module Reports
252
272
  class InferredReportUseCase < SenroUsecaser::Base
273
+ class Input
274
+ # : (**untyped) -> void
275
+ def initialize: (**untyped) -> void
276
+ end
277
+
253
278
  class Output
254
279
  # : (message: String) -> void
255
280
  def initialize: (message: String) -> void
@@ -264,8 +289,8 @@ module Admin
264
289
 
265
290
  def logger: () -> NamespaceDemo::Logger
266
291
 
267
- # : (?untyped, **untyped) -> SenroUsecaser::Result[Output]
268
- def call: (?untyped, **untyped) -> SenroUsecaser::Result[Output]
292
+ # : (Input) -> SenroUsecaser::Result[Output]
293
+ def call: (Input) -> SenroUsecaser::Result[Output]
269
294
  end
270
295
  end
271
296
  end