piko-quick-lib 0.0.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.
Files changed (49) hide show
  1. checksums.yaml +7 -0
  2. data/dry-system-1.2.5/CHANGELOG.md +1311 -0
  3. data/dry-system-1.2.5/LICENSE +21 -0
  4. data/dry-system-1.2.5/README.md +17 -0
  5. data/dry-system-1.2.5/dry-system.gemspec +42 -0
  6. data/dry-system-1.2.5/lib/dry/system/auto_registrar.rb +45 -0
  7. data/dry-system-1.2.5/lib/dry/system/component.rb +190 -0
  8. data/dry-system-1.2.5/lib/dry/system/component_dir.rb +171 -0
  9. data/dry-system-1.2.5/lib/dry/system/config/component_dir.rb +228 -0
  10. data/dry-system-1.2.5/lib/dry/system/config/component_dirs.rb +285 -0
  11. data/dry-system-1.2.5/lib/dry/system/config/namespace.rb +75 -0
  12. data/dry-system-1.2.5/lib/dry/system/config/namespaces.rb +192 -0
  13. data/dry-system-1.2.5/lib/dry/system/constants.rb +13 -0
  14. data/dry-system-1.2.5/lib/dry/system/container.rb +685 -0
  15. data/dry-system-1.2.5/lib/dry/system/errors.rb +132 -0
  16. data/dry-system-1.2.5/lib/dry/system/identifier.rb +176 -0
  17. data/dry-system-1.2.5/lib/dry/system/importer.rb +144 -0
  18. data/dry-system-1.2.5/lib/dry/system/indirect_component.rb +63 -0
  19. data/dry-system-1.2.5/lib/dry/system/loader/autoloading.rb +24 -0
  20. data/dry-system-1.2.5/lib/dry/system/loader.rb +84 -0
  21. data/dry-system-1.2.5/lib/dry/system/magic_comments_parser.rb +31 -0
  22. data/dry-system-1.2.5/lib/dry/system/manifest_registrar.rb +57 -0
  23. data/dry-system-1.2.5/lib/dry/system/plugins/bootsnap.rb +47 -0
  24. data/dry-system-1.2.5/lib/dry/system/plugins/dependency_graph/strategies.rb +66 -0
  25. data/dry-system-1.2.5/lib/dry/system/plugins/dependency_graph.rb +53 -0
  26. data/dry-system-1.2.5/lib/dry/system/plugins/env.rb +30 -0
  27. data/dry-system-1.2.5/lib/dry/system/plugins/logging.rb +73 -0
  28. data/dry-system-1.2.5/lib/dry/system/plugins/monitoring/proxy.rb +51 -0
  29. data/dry-system-1.2.5/lib/dry/system/plugins/monitoring.rb +45 -0
  30. data/dry-system-1.2.5/lib/dry/system/plugins/notifications.rb +27 -0
  31. data/dry-system-1.2.5/lib/dry/system/plugins/plugin.rb +61 -0
  32. data/dry-system-1.2.5/lib/dry/system/plugins/zeitwerk/compat_inflector.rb +22 -0
  33. data/dry-system-1.2.5/lib/dry/system/plugins/zeitwerk.rb +109 -0
  34. data/dry-system-1.2.5/lib/dry/system/plugins.rb +70 -0
  35. data/dry-system-1.2.5/lib/dry/system/provider/source.rb +281 -0
  36. data/dry-system-1.2.5/lib/dry/system/provider/source_dsl.rb +55 -0
  37. data/dry-system-1.2.5/lib/dry/system/provider.rb +291 -0
  38. data/dry-system-1.2.5/lib/dry/system/provider_registrar.rb +289 -0
  39. data/dry-system-1.2.5/lib/dry/system/provider_source_registry.rb +67 -0
  40. data/dry-system-1.2.5/lib/dry/system/provider_sources/settings/config.rb +73 -0
  41. data/dry-system-1.2.5/lib/dry/system/provider_sources/settings/loader.rb +44 -0
  42. data/dry-system-1.2.5/lib/dry/system/provider_sources/settings.rb +40 -0
  43. data/dry-system-1.2.5/lib/dry/system/provider_sources.rb +6 -0
  44. data/dry-system-1.2.5/lib/dry/system/stubs.rb +39 -0
  45. data/dry-system-1.2.5/lib/dry/system/version.rb +7 -0
  46. data/dry-system-1.2.5/lib/dry/system.rb +62 -0
  47. data/dry-system-1.2.5/lib/dry-system.rb +3 -0
  48. data/piko-quick-lib.gemspec +11 -0
  49. metadata +87 -0
@@ -0,0 +1,228 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dry/system/constants"
4
+
5
+ module Dry
6
+ module System
7
+ module Config
8
+ # @api public
9
+ class ComponentDir
10
+ include ::Dry::Configurable
11
+
12
+ # @!group Settings
13
+
14
+ # @!method auto_register=(policy)
15
+ #
16
+ # Sets the auto-registration policy for the component dir.
17
+ #
18
+ # This may be a simple boolean to enable or disable auto-registration for all
19
+ # components, or a proc accepting a {Dry::System::Component} and returning a
20
+ # boolean to configure auto-registration on a per-component basis
21
+ #
22
+ # Defaults to `true`.
23
+ #
24
+ # @param policy [Boolean, Proc]
25
+ # @return [Boolean, Proc]
26
+ #
27
+ # @example
28
+ # dir.auto_register = false
29
+ #
30
+ # @example
31
+ # dir.auto_register = proc do |component|
32
+ # !component.identifier.start_with?("entities")
33
+ # end
34
+ #
35
+ # @see auto_register
36
+ # @see Component
37
+ # @api public
38
+ #
39
+ # @!method auto_register
40
+ #
41
+ # Returns the configured auto-registration policy.
42
+ #
43
+ # @return [Boolean, Proc] the configured policy
44
+ #
45
+ # @see auto_register=
46
+ # @api public
47
+ setting :auto_register, default: true
48
+
49
+ # @!method instance=(instance_proc)
50
+ #
51
+ # Sets a proc used to return the instance of any component within the component
52
+ # dir.
53
+ #
54
+ # This proc should accept a {Dry::System::Component} and return the object to
55
+ # serve as the component's instance.
56
+ #
57
+ # When you provide an instance proc, it will be used in preference to the
58
+ # {loader} (either the default loader or an explicitly configured one). Provide
59
+ # an instance proc when you want a simple way to customize the instance for
60
+ # certain components. For complete control, provide a replacement loader via
61
+ # {loader=}.
62
+ #
63
+ # Defaults to `nil`.
64
+ #
65
+ # @param instance_proc [Proc, nil]
66
+ # @return [Proc]
67
+ #
68
+ # @example
69
+ # dir.instance = proc do |component|
70
+ # if component.key.match?(/workers\./)
71
+ # # Register classes for jobs
72
+ # component.loader.constant(component)
73
+ # else
74
+ # # Otherwise register regular instances per default loader
75
+ # component.loader.call(component)
76
+ # end
77
+ # end
78
+ #
79
+ # @see Component, Loader
80
+ # @api public
81
+ #
82
+ # @!method instance
83
+ #
84
+ # Returns the configured instance proc.
85
+ #
86
+ # @return [Proc, nil]
87
+ #
88
+ # @see instance=
89
+ # @api public
90
+ setting :instance
91
+
92
+ # @!method loader=(loader)
93
+ #
94
+ # Sets the loader to use when registering components from the dir in the
95
+ # container.
96
+ #
97
+ # Defaults to `Dry::System::Loader`.
98
+ #
99
+ # When using an autoloader like Zeitwerk, consider using
100
+ # `Dry::System::Loader::Autoloading`
101
+ #
102
+ # @param loader [#call] the loader
103
+ # @return [#call] the configured loader
104
+ #
105
+ # @see loader
106
+ # @see Loader
107
+ # @see Loader::Autoloading
108
+ # @api public
109
+ #
110
+ # @!method loader
111
+ #
112
+ # Returns the configured loader.
113
+ #
114
+ # @return [#call]
115
+ #
116
+ # @see loader=
117
+ # @api public
118
+ setting :loader, default: Dry::System::Loader
119
+
120
+ # @!method memoize=(policy)
121
+ #
122
+ # Sets whether to memoize components from the dir when registered in the
123
+ # container.
124
+ #
125
+ # This may be a simple boolean to enable or disable memoization for all
126
+ # components, or a proc accepting a `Dry::Sytem::Component` and returning a
127
+ # boolean to configure memoization on a per-component basis
128
+ #
129
+ # Defaults to `false`.
130
+ #
131
+ # @param policy [Boolean, Proc]
132
+ # @return [Boolean, Proc] the configured memoization policy
133
+ #
134
+ # @example
135
+ # dir.memoize = true
136
+ #
137
+ # @example
138
+ # dir.memoize = proc do |component|
139
+ # !component.identifier.start_with?("providers")
140
+ # end
141
+ #
142
+ # @see memoize
143
+ # @see Component
144
+ # @api public
145
+ #
146
+ # @!method memoize
147
+ #
148
+ # Returns the configured memoization policy.
149
+ #
150
+ # @return [Boolean, Proc] the configured memoization policy
151
+ #
152
+ # @see memoize=
153
+ # @api public
154
+ setting :memoize, default: false
155
+
156
+ # @!method namespaces
157
+ #
158
+ # Returns the configured namespaces for the component dir.
159
+ #
160
+ # Allows namespaces to added on the returned object via {Namespaces#add}.
161
+ #
162
+ # @return [Namespaces] the namespaces
163
+ #
164
+ # @see Namespaces#add
165
+ # @api public
166
+ setting :namespaces, default: Namespaces.new, cloneable: true
167
+
168
+ # @!method add_to_load_path=(policy)
169
+ #
170
+ # Sets whether the dir should be added to the `$LOAD_PATH` after the container
171
+ # is configured.
172
+ #
173
+ # Defaults to `true`. This may need to be set to `false` when using a class
174
+ # autoloading system.
175
+ #
176
+ # @param policy [Boolean]
177
+ # @return [Boolean]
178
+ #
179
+ # @see add_to_load_path
180
+ # @see Container.configure
181
+ # @api public
182
+ #
183
+ # @!method add_to_load_path
184
+ #
185
+ # Returns the configured value.
186
+ #
187
+ # @return [Boolean]
188
+ #
189
+ # @see add_to_load_path=
190
+ # @api public
191
+ setting :add_to_load_path, default: true
192
+
193
+ # @!endgroup
194
+
195
+ # Returns the component dir path, relative to the configured container root
196
+ #
197
+ # @return [String] the path
198
+ attr_reader :path
199
+
200
+ # @api public
201
+ def initialize(path)
202
+ super()
203
+ @path = path
204
+ yield self if block_given?
205
+ end
206
+
207
+ # @api private
208
+ def auto_register?
209
+ !!config.auto_register
210
+ end
211
+
212
+ private
213
+
214
+ def method_missing(name, ...)
215
+ if config.respond_to?(name)
216
+ config.public_send(name, ...)
217
+ else
218
+ super
219
+ end
220
+ end
221
+
222
+ def respond_to_missing?(name, include_all = false)
223
+ config.respond_to?(name) || super
224
+ end
225
+ end
226
+ end
227
+ end
228
+ end
@@ -0,0 +1,285 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dry/system/constants"
4
+ require "dry/system/errors"
5
+
6
+ module Dry
7
+ module System
8
+ module Config
9
+ # The configured component dirs for a container
10
+ #
11
+ # @api public
12
+ class ComponentDirs
13
+ # @!group Settings
14
+
15
+ # @!method auto_register=(value)
16
+ #
17
+ # Sets a default `auto_register` for all added component dirs
18
+ #
19
+ # @see ComponentDir.auto_register=
20
+ # @see auto_register
21
+ #
22
+ # @!method auto_register
23
+ #
24
+ # Returns the configured default `auto_register`
25
+ #
26
+ # @see auto_register=
27
+
28
+ # @!method instance=(value)
29
+ #
30
+ # Sets a default `instance` for all added component dirs
31
+ #
32
+ # @see ComponentDir.instance=
33
+ # @see auto_register
34
+ #
35
+ # @!method auto_register
36
+ #
37
+ # Returns the configured default `instance`
38
+ #
39
+ # @see instance=
40
+
41
+ # @!method loader=(value)
42
+ #
43
+ # Sets a default `loader` value for all added component dirs
44
+ #
45
+ # @see ComponentDir.loader=
46
+ # @see loader
47
+ #
48
+ # @!method loader
49
+ #
50
+ # Returns the configured default `loader`
51
+ #
52
+ # @see loader=
53
+
54
+ # @!method memoize=(value)
55
+ #
56
+ # Sets a default `memoize` value for all added component dirs
57
+ #
58
+ # @see ComponentDir.memoize=
59
+ # @see memoize
60
+ #
61
+ # @!method memoize
62
+ #
63
+ # Returns the configured default `memoize`
64
+ #
65
+ # @see memoize=
66
+
67
+ # @!method namespaces
68
+ #
69
+ # Returns the default configured namespaces for all added component dirs
70
+ #
71
+ # Allows namespaces to added on the returned object via {Dry::System::Config::Namespaces#add}.
72
+ #
73
+ # @see Dry::System::Config::Namespaces#add
74
+ #
75
+ # @return [Namespaces] the namespaces
76
+
77
+ # @!method add_to_load_path=(value)
78
+ #
79
+ # Sets a default `add_to_load_path` value for all added component dirs
80
+ #
81
+ # @see ComponentDir.add_to_load_path=
82
+ # @see add_to_load_path
83
+ #
84
+ # @!method add_to_load_path
85
+ #
86
+ # Returns the configured default `add_to_load_path`
87
+ #
88
+ # @see add_to_load_path=
89
+
90
+ # @!endgroup
91
+
92
+ # A ComponentDir for configuring the default values to apply to all added
93
+ # component dirs
94
+ #
95
+ # @see #method_missing
96
+ # @api private
97
+ attr_reader :defaults
98
+
99
+ # Creates a new component dirs
100
+ #
101
+ # @api private
102
+ def initialize
103
+ @dirs = {}
104
+ @defaults = ComponentDir.new(nil)
105
+ end
106
+
107
+ # @api private
108
+ def initialize_copy(source)
109
+ @dirs = source.dirs.transform_values(&:dup)
110
+ @defaults = source.defaults.dup
111
+ end
112
+
113
+ # Returns and optionally yields a previously added component dir
114
+ #
115
+ # @param path [String] the path for the component dir
116
+ # @yieldparam dir [ComponentDir] the component dir
117
+ #
118
+ # @return [ComponentDir] the component dir
119
+ #
120
+ # @api public
121
+ def dir(path)
122
+ dirs[path].tap do |dir|
123
+ # Defaults can be (re-)applied first, since the dir has already been added
124
+ apply_defaults_to_dir(dir) if dir
125
+ yield dir if block_given?
126
+ end
127
+ end
128
+ alias_method :[], :dir
129
+
130
+ # @overload add(path)
131
+ # Adds and configures a component dir for the given path
132
+ #
133
+ # @param path [String] the path for the component dir, relative to the configured
134
+ # container root
135
+ # @yieldparam dir [ComponentDir] the component dir to configure
136
+ #
137
+ # @return [ComponentDir] the added component dir
138
+ #
139
+ # @example
140
+ # component_dirs.add "lib" do |dir|
141
+ # dir.default_namespace = "my_app"
142
+ # end
143
+ #
144
+ # @see ComponentDir
145
+ # @api public
146
+ #
147
+ # @overload add(dir)
148
+ # Adds a configured component dir
149
+ #
150
+ # @param dir [ComponentDir] the configured component dir
151
+ #
152
+ # @return [ComponentDir] the added component dir
153
+ #
154
+ # @example
155
+ # dir = Dry::System::ComponentDir.new("lib")
156
+ # component_dirs.add dir
157
+ #
158
+ # @see ComponentDir
159
+ # @api public
160
+ def add(path_or_dir)
161
+ path, dir_to_add = path_and_dir(path_or_dir)
162
+
163
+ raise ComponentDirAlreadyAddedError, path if dirs.key?(path)
164
+
165
+ dirs[path] = dir_to_add.tap do |dir|
166
+ # Defaults must be applied after yielding, since the dir is being newly added,
167
+ # and must have its configuration fully in place before we can know which
168
+ # defaults to apply
169
+ yield dir if path_or_dir == path && block_given?
170
+ apply_defaults_to_dir(dir)
171
+ end
172
+ end
173
+
174
+ # Deletes and returns a previously added component dir
175
+ #
176
+ # @param path [String] the path for the component dir
177
+ #
178
+ # @return [ComponentDir] the removed component dir
179
+ #
180
+ # @api public
181
+ def delete(path)
182
+ dirs.delete(path)
183
+ end
184
+
185
+ # Returns the paths of the component dirs
186
+ #
187
+ # @return [Array<String>] the component dir paths
188
+ #
189
+ # @api public
190
+ def paths
191
+ dirs.keys
192
+ end
193
+
194
+ # Returns the count of component dirs
195
+ #
196
+ # @return [Integer]
197
+ #
198
+ # @api public
199
+ def length
200
+ dirs.length
201
+ end
202
+ alias_method :size, :length
203
+
204
+ # Returns the added component dirs, with default settings applied
205
+ #
206
+ # @return [Array<ComponentDir>]
207
+ #
208
+ # @api public
209
+ def to_a
210
+ dirs.each { |_, dir| apply_defaults_to_dir(dir) }
211
+ dirs.values
212
+ end
213
+
214
+ # Calls the given block once for each added component dir, passing the dir as an
215
+ # argument.
216
+ #
217
+ # @yieldparam dir [ComponentDir] the yielded component dir
218
+ #
219
+ # @api public
220
+ def each(&)
221
+ to_a.each(&)
222
+ end
223
+
224
+ protected
225
+
226
+ # Returns the hash of component dirs, keyed by their paths
227
+ #
228
+ # Recently changed default configuration may not be applied to these dirs. Use
229
+ # #to_a or #each to access dirs with default configuration fully applied.
230
+ #
231
+ # This method exists to encapsulate the instance variable and to serve the needs
232
+ # of #initialize_copy
233
+ #
234
+ # @return [Hash{String => ComponentDir}]
235
+ #
236
+ # @api private
237
+ attr_reader :dirs
238
+
239
+ private
240
+
241
+ # Converts a path string or pre-built component dir into a path and dir tuple
242
+ #
243
+ # @param path_or_dir [String,ComponentDir]
244
+ #
245
+ # @return [Array<(String, ComponentDir)>]
246
+ #
247
+ # @see #add
248
+ def path_and_dir(path_or_dir)
249
+ if path_or_dir.is_a?(ComponentDir)
250
+ dir = path_or_dir
251
+ [dir.path, dir]
252
+ else
253
+ path = path_or_dir
254
+ [path, ComponentDir.new(path)]
255
+ end
256
+ end
257
+
258
+ # Applies default settings to a component dir. This is run every time the dirs are
259
+ # accessed to ensure defaults are applied regardless of when new component dirs
260
+ # are added. This method must be idempotent.
261
+ #
262
+ # @return [void]
263
+ def apply_defaults_to_dir(dir)
264
+ defaults.config.values.each do |key, _|
265
+ if defaults.configured?(key) && !dir.configured?(key)
266
+ dir.public_send(:"#{key}=", defaults.public_send(key).dup)
267
+ end
268
+ end
269
+ end
270
+
271
+ def method_missing(name, ...)
272
+ if defaults.respond_to?(name)
273
+ defaults.public_send(name, ...)
274
+ else
275
+ super
276
+ end
277
+ end
278
+
279
+ def respond_to_missing?(name, include_all = false)
280
+ defaults.respond_to?(name) || super
281
+ end
282
+ end
283
+ end
284
+ end
285
+ end
@@ -0,0 +1,75 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dry/system/constants"
4
+
5
+ module Dry
6
+ module System
7
+ module Config
8
+ # A configured namespace for a component dir
9
+ #
10
+ # Namespaces consist of three elements:
11
+ #
12
+ # - The `path` within the component dir to which its namespace rules should apply.
13
+ # - A `key`, which determines the leading part of the key used to register
14
+ # each component in the container.
15
+ # - A `const`, which is the Ruby namespace expected to contain the class constants
16
+ # defined within each component's source file. This value is expected to be an
17
+ # "underscored" string, intended to be run through the configured inflector to be
18
+ # converted into a real constant (e.g. `"foo_bar/baz"` will become `FooBar::Baz`)
19
+ #
20
+ # Namespaces are added and configured for a component dir via {Namespaces#add}.
21
+ #
22
+ # @see Namespaces#add
23
+ #
24
+ # @api public
25
+ class Namespace
26
+ ROOT_PATH = nil
27
+
28
+ include Dry::Equalizer(:path, :key, :const)
29
+
30
+ # @api public
31
+ attr_reader :path
32
+
33
+ # @api public
34
+ attr_reader :key
35
+
36
+ # @api public
37
+ attr_reader :const
38
+
39
+ # Returns a namespace configured to serve as the default root namespace for a
40
+ # component dir, ensuring that all code within the dir can be loaded, regardless
41
+ # of any other explictly configured namespaces
42
+ #
43
+ # @return [Namespace] the root namespace
44
+ #
45
+ # @api private
46
+ def self.default_root
47
+ new(
48
+ path: ROOT_PATH,
49
+ key: nil,
50
+ const: nil
51
+ )
52
+ end
53
+
54
+ # @api private
55
+ def initialize(path:, key:, const:)
56
+ @path = path
57
+ # Default keys (i.e. when the user does not explicitly provide one) for non-root
58
+ # paths will include path separators, which we must convert into key separators
59
+ @key = key && key == path ? key.gsub(PATH_SEPARATOR, KEY_SEPARATOR) : key
60
+ @const = const
61
+ end
62
+
63
+ # @api public
64
+ def root?
65
+ path == ROOT_PATH
66
+ end
67
+
68
+ # @api public
69
+ def path?
70
+ !root?
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end