senro_usecaser 0.1.0

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.
@@ -0,0 +1,153 @@
1
+ # Generated from lib/senro_usecaser/provider.rb with RBS::Inline
2
+
3
+ module SenroUsecaser
4
+ # Base class for dependency providers
5
+ #
6
+ # Providers allow organizing dependency registrations across multiple files.
7
+ # Each provider is responsible for registering a group of related dependencies.
8
+ #
9
+ # @example Basic provider
10
+ # class UserProvider < SenroUsecaser::Provider
11
+ # def register(container)
12
+ # container.register(:user_repository, UserRepository.new)
13
+ # container.register_singleton(:user_service) do |c|
14
+ # UserService.new(repo: c.resolve(:user_repository))
15
+ # end
16
+ # end
17
+ # end
18
+ #
19
+ # @example Provider with namespace
20
+ # class AdminProvider < SenroUsecaser::Provider
21
+ # namespace :admin
22
+ #
23
+ # def register(container)
24
+ # container.register(:user_repository, AdminUserRepository.new)
25
+ # end
26
+ # end
27
+ #
28
+ # @example Provider with dependencies
29
+ # class PersistenceProvider < SenroUsecaser::Provider
30
+ # depends_on CoreProvider
31
+ #
32
+ # def register(container)
33
+ # container.register(:database, Database.connect)
34
+ # end
35
+ # end
36
+ #
37
+ # @example Conditional provider
38
+ # class DevelopmentProvider < SenroUsecaser::Provider
39
+ # enabled_if { SenroUsecaser.env.development? }
40
+ # end
41
+ class Provider
42
+ # Declares dependencies on other providers
43
+ #
44
+ # @example
45
+ # class PersistenceProvider < SenroUsecaser::Provider
46
+ # depends_on CoreProvider
47
+ # depends_on ConfigProvider
48
+ # end
49
+ #
50
+ # : (*singleton(Provider)) -> void
51
+ def self.depends_on: (*singleton(Provider)) -> void
52
+
53
+ # Returns the list of provider dependencies
54
+ #
55
+ # : () -> Array[singleton(Provider)]
56
+ def self.provider_dependencies: () -> Array[singleton(Provider)]
57
+
58
+ # Sets a condition for enabling this provider
59
+ #
60
+ # @example
61
+ # class DevelopmentProvider < SenroUsecaser::Provider
62
+ # enabled_if { Rails.env.development? }
63
+ # end
64
+ #
65
+ # : () { () -> bool } -> void
66
+ def self.enabled_if: () { () -> boolish } -> void
67
+
68
+ # Returns whether this provider is enabled
69
+ #
70
+ # : () -> bool
71
+ def self.enabled?: () -> bool
72
+
73
+ # Sets the namespace for this provider's registrations
74
+ #
75
+ # @example
76
+ # class AdminProvider < SenroUsecaser::Provider
77
+ # namespace :admin
78
+ # end
79
+ #
80
+ # : ((Symbol | String)) -> void
81
+ def self.namespace: (Symbol | String) -> void
82
+
83
+ # @rbs!
84
+ # def self.provider_namespace: () -> (Symbol | String)?
85
+ attr_reader provider_namespace: untyped
86
+
87
+ # Registers this provider's dependencies to the given container
88
+ #
89
+ # : (Container) -> void
90
+ def self.call: (Container) -> void
91
+
92
+ # Registers dependencies to the container, wrapped in namespace if declared
93
+ #
94
+ # : (Container) -> void
95
+ def register_to: (Container) -> void
96
+
97
+ # Returns the effective namespace for this provider
98
+ # Uses explicitly declared namespace, or infers from module structure if configured
99
+ #
100
+ # : () -> (Symbol | String)?
101
+ def effective_namespace: () -> (Symbol | String)?
102
+
103
+ # Infers namespace from the class's module structure
104
+ #
105
+ # @example
106
+ # Admin::UserProvider => "admin"
107
+ # Admin::Reports::ReportProvider => "admin::reports"
108
+ # CoreProvider => nil
109
+ #
110
+ # : () -> String?
111
+ def infer_namespace_from_class: () -> String?
112
+
113
+ # Called before register. Override in subclasses.
114
+ #
115
+ # @example
116
+ # def before_register(container)
117
+ # # Setup work
118
+ # end
119
+ #
120
+ # : (Container) -> void
121
+ def before_register: (Container) -> void
122
+
123
+ # Override this method to register dependencies
124
+ #
125
+ # @example
126
+ # def register(container)
127
+ # container.register(:logger, Logger.new)
128
+ # end
129
+ #
130
+ # : (Container) -> void
131
+ def register: (Container) -> void
132
+
133
+ # Called after all providers are registered. Override in subclasses.
134
+ #
135
+ # @example
136
+ # def after_boot(container)
137
+ # container.resolve(:database).verify_connection!
138
+ # end
139
+ #
140
+ # : (Container) -> void
141
+ def after_boot: (Container) -> void
142
+
143
+ # Called on application shutdown. Override in subclasses.
144
+ #
145
+ # @example
146
+ # def shutdown(container)
147
+ # container.resolve(:database).disconnect
148
+ # end
149
+ #
150
+ # : (Container) -> void
151
+ def shutdown: (Container) -> void
152
+ end
153
+ end
@@ -0,0 +1,109 @@
1
+ # Generated from lib/senro_usecaser/result.rb with RBS::Inline
2
+
3
+ module SenroUsecaser
4
+ # Represents the result of a UseCase execution
5
+ #
6
+ # Result is a generic type that holds either a success value or an array of errors.
7
+ # Use {.success} and {.failure} class methods to create instances.
8
+ #
9
+ # @example Success case
10
+ # result = SenroUsecaser::Result.success(user)
11
+ # result.success? # => true
12
+ # result.value # => user
13
+ #
14
+ # @example Failure case
15
+ # result = SenroUsecaser::Result.failure(
16
+ # SenroUsecaser::Error.new(code: :not_found, message: "User not found")
17
+ # )
18
+ # result.failure? # => true
19
+ # result.errors # => [#<SenroUsecaser::Error ...>]
20
+ #
21
+ # @rbs generic T
22
+ class Result[T]
23
+ attr_reader value: T?
24
+
25
+ attr_reader errors: Array[Error]
26
+
27
+ # Creates a success Result with the given value
28
+ #
29
+ # : [T] (T) -> Result[T]
30
+ def self.success: [T] (T) -> Result[T]
31
+
32
+ # Creates a failure Result with the given errors
33
+ #
34
+ # : (*Error) -> Result[untyped]
35
+ def self.failure: (*Error) -> Result[untyped]
36
+
37
+ # Creates a failure Result from an exception
38
+ #
39
+ # @example
40
+ # begin
41
+ # # some code that raises
42
+ # rescue => e
43
+ # Result.from_exception(e)
44
+ # end
45
+ #
46
+ # : (Exception, ?code: Symbol) -> Result[untyped]
47
+ def self.from_exception: (Exception, ?code: Symbol) -> Result[untyped]
48
+
49
+ # Executes a block and captures any exception as a failure Result
50
+ #
51
+ # @example
52
+ # result = Result.capture { User.find(id) }
53
+ # # If User.find raises, result is a failure with the exception
54
+ # # If User.find succeeds, result is a success with the return value
55
+ #
56
+ # @example With specific exception classes
57
+ # result = Result.capture(ActiveRecord::RecordNotFound, code: :not_found) do
58
+ # User.find(id)
59
+ # end
60
+ #
61
+ # : [T] (*Class, ?code: Symbol) { () -> T } -> Result[T]
62
+ def self.capture: [T] (*Class, ?code: Symbol) { () -> T } -> Result[T]
63
+
64
+ # : (?value: T?, ?errors: Array[Error]) -> void
65
+ def initialize: (?value: T?, ?errors: Array[Error]) -> void
66
+
67
+ # Returns true if the result is a success
68
+ #
69
+ # : () -> bool
70
+ def success?: () -> bool
71
+
72
+ # Returns true if the result is a failure
73
+ #
74
+ # : () -> bool
75
+ def failure?: () -> bool
76
+
77
+ # Returns the value if success, otherwise raises an error
78
+ #
79
+ # : () -> T
80
+ def value!: () -> T
81
+
82
+ # Returns the value if success, otherwise returns the given default
83
+ #
84
+ # : [U] (U) -> (T | U)
85
+ def value_or: [U] (U) -> (T | U)
86
+
87
+ # Applies a block to the value if success, returns failure with same errors if failure
88
+ #
89
+ # : [U] () { (T) -> U } -> Result[U]
90
+ def map: [U] () { (T) -> U } -> Result[U]
91
+
92
+ # Applies a block to the value if success, returns failure with same errors if failure
93
+ # The block should return a Result
94
+ #
95
+ # : [U] () { (T) -> Result[U] } -> Result[U]
96
+ def and_then: [U] () { (T) -> Result[U] } -> Result[U]
97
+
98
+ # Applies a block to the errors if failure, returns self if success
99
+ #
100
+ # : () { (Array[Error]) -> Result[T] } -> Result[T]
101
+ def or_else: () { (Array[Error]) -> Result[T] } -> Result[T]
102
+
103
+ # : (Result[untyped]) -> bool
104
+ def ==: (Result[untyped]) -> bool
105
+
106
+ # : () -> String
107
+ def inspect: () -> String
108
+ end
109
+ end
@@ -0,0 +1,6 @@
1
+ # Generated from lib/senro_usecaser/version.rb with RBS::Inline
2
+
3
+ module SenroUsecaser
4
+ # : String
5
+ VERSION: ::String
6
+ end
@@ -0,0 +1,113 @@
1
+ # Generated from lib/senro_usecaser.rb with RBS::Inline
2
+
3
+ # SenroUsecaser is a type-safe UseCase pattern implementation library for Ruby.
4
+ #
5
+ # It provides:
6
+ # - Type-safe input/output with RBS Inline
7
+ # - DI container with namespaces
8
+ # - Flexible composition with organize/include/extend patterns
9
+ #
10
+ # @example Basic UseCase
11
+ # class CreateUserUseCase < SenroUsecaser::Base
12
+ # def call(name:, email:)
13
+ # user = User.create(name: name, email: email)
14
+ # success(user)
15
+ # end
16
+ # end
17
+ #
18
+ # result = CreateUserUseCase.call(name: "Taro", email: "taro@example.com")
19
+ # if result.success?
20
+ # puts result.value.name
21
+ # end
22
+ module SenroUsecaser
23
+ # Returns the global container instance
24
+ #
25
+ # @example
26
+ # SenroUsecaser.container.register(:logger, Logger.new)
27
+ #
28
+ # : () -> Container
29
+ def self.container: () -> Container
30
+
31
+ # Sets the global container instance
32
+ #
33
+ # @example
34
+ # SenroUsecaser.container = MyCustomContainer.new
35
+ #
36
+ # : (Container) -> Container
37
+ attr_writer container: untyped
38
+
39
+ # Resets the global container (useful for testing)
40
+ #
41
+ # : () -> void
42
+ def self.reset_container!: () -> void
43
+
44
+ # Registers a provider to the global container
45
+ #
46
+ # @example
47
+ # SenroUsecaser.register_provider(UserProvider)
48
+ #
49
+ # : (singleton(Provider)) -> void
50
+ def self.register_provider: (singleton(Provider)) -> void
51
+
52
+ # Registers multiple providers to the global container
53
+ #
54
+ # @example
55
+ # SenroUsecaser.register_providers(UserProvider, OrderProvider, PaymentProvider)
56
+ #
57
+ # : (*singleton(Provider)) -> void
58
+ def self.register_providers: (*singleton(Provider)) -> void
59
+
60
+ # Returns the configuration instance
61
+ #
62
+ # : () -> Configuration
63
+ def self.configuration: () -> Configuration
64
+
65
+ # Configures SenroUsecaser
66
+ #
67
+ # @example
68
+ # SenroUsecaser.configure do |config|
69
+ # config.providers = [CoreProvider, UserProvider]
70
+ # config.infer_namespace_from_module = true
71
+ # end
72
+ #
73
+ # : () { (Configuration) -> void } -> void
74
+ def self.configure: () { (Configuration) -> void } -> void
75
+
76
+ # Boots all configured providers in dependency order
77
+ #
78
+ # @example
79
+ # SenroUsecaser.configure do |config|
80
+ # config.providers = [CoreProvider, UserProvider]
81
+ # end
82
+ # SenroUsecaser.boot!
83
+ #
84
+ # : () -> void
85
+ def self.boot!: () -> void
86
+
87
+ # Shuts down all booted providers
88
+ #
89
+ # : () -> void
90
+ def self.shutdown!: () -> void
91
+
92
+ # Returns the current environment
93
+ #
94
+ # @example
95
+ # SenroUsecaser.env.development?
96
+ # SenroUsecaser.env.production?
97
+ #
98
+ # : () -> Environment
99
+ def self.env: () -> Environment
100
+
101
+ # Sets the environment
102
+ #
103
+ # : (String) -> void
104
+ def self.env=: (String) -> void
105
+
106
+ # Resets all state (useful for testing)
107
+ #
108
+ # : () -> void
109
+ def self.reset!: () -> void
110
+
111
+ # : () -> String
112
+ private def self.detect_environment: () -> String
113
+ end
data/sig/overrides.rbs ADDED
@@ -0,0 +1,16 @@
1
+ # Supplementary type definitions for rbs-inline generated types
2
+ # Only add missing declarations that rbs-inline doesn't generate
3
+
4
+ module SenroUsecaser
5
+ class Provider
6
+ # Class method for provider_namespace (attr_reader in class << self)
7
+ def self.provider_namespace: () -> (Symbol | String)?
8
+ end
9
+
10
+ class Base
11
+ # Class methods that rbs-inline doesn't generate correctly
12
+ def self.organized_steps: () -> Array[Step]?
13
+ def self.use_case_namespace: () -> (Symbol | String)?
14
+ def self.input_class: () -> Class?
15
+ end
16
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: senro_usecaser
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Shogo Kawahara
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: |
13
+ SenroUsecaser is a UseCase pattern implementation library for Ruby.
14
+ It provides type-safe input/output, DI container with namespaces,
15
+ and flexible composition with organize/include/extend patterns.
16
+ Compatible with both Steep (RBS) and Sorbet.
17
+ email:
18
+ - kawahara@bucyou.net
19
+ executables: []
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - ".rspec"
24
+ - ".rubocop.yml"
25
+ - LICENSE
26
+ - README.md
27
+ - Rakefile
28
+ - Steepfile
29
+ - examples/RBS_GENERATION.md
30
+ - examples/namespace_demo.rb
31
+ - examples/order_system.rb
32
+ - examples/sig/namespace_demo.rbs
33
+ - examples/sig/order_system.rbs
34
+ - lefthook.yml
35
+ - lib/senro_usecaser.rb
36
+ - lib/senro_usecaser/base.rb
37
+ - lib/senro_usecaser/configuration.rb
38
+ - lib/senro_usecaser/container.rb
39
+ - lib/senro_usecaser/error.rb
40
+ - lib/senro_usecaser/provider.rb
41
+ - lib/senro_usecaser/result.rb
42
+ - lib/senro_usecaser/version.rb
43
+ - sig/generated/senro_usecaser.rbs
44
+ - sig/generated/senro_usecaser/base.rbs
45
+ - sig/generated/senro_usecaser/configuration.rbs
46
+ - sig/generated/senro_usecaser/container.rbs
47
+ - sig/generated/senro_usecaser/error.rbs
48
+ - sig/generated/senro_usecaser/provider.rbs
49
+ - sig/generated/senro_usecaser/result.rbs
50
+ - sig/generated/senro_usecaser/version.rbs
51
+ - sig/overrides.rbs
52
+ homepage: https://github.com/kawahara/senro_usecaser
53
+ licenses:
54
+ - MIT
55
+ metadata:
56
+ homepage_uri: https://github.com/kawahara/senro_usecaser
57
+ source_code_uri: https://github.com/kawahara/senro_usecaser
58
+ changelog_uri: https://github.com/kawahara/senro_usecaser/blob/main/CHANGELOG.md
59
+ rubygems_mfa_required: 'true'
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: 3.2.0
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubygems_version: 3.6.9
75
+ specification_version: 4
76
+ summary: A type-safe UseCase pattern implementation library for Ruby
77
+ test_files: []