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,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015-2025 Hanakai team
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
@@ -0,0 +1,17 @@
1
+ <!--- This file is synced from hanakai-rb/repo-sync -->
2
+
3
+ [rubygem]: https://rubygems.org/gems/dry-system
4
+ [actions]: https://github.com/dry-rb/dry-system/actions
5
+
6
+ # dry-system [![Gem Version](https://badge.fury.io/rb/dry-system.svg)][rubygem] [![CI Status](https://github.com/dry-rb/dry-system/workflows/CI/badge.svg)][actions]
7
+
8
+ ## Links
9
+
10
+ - [User documentation](https://dry-rb.org/gems/dry-system)
11
+ - [API documentation](http://rubydoc.info/gems/dry-system)
12
+ - [Forum](https://discourse.dry-rb.org)
13
+
14
+ ## License
15
+
16
+ See `LICENSE` file.
17
+
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This file is synced from hanakai-rb/repo-sync. To update it, edit repo-sync.yml.
4
+
5
+ lib = File.expand_path("lib", __dir__)
6
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
7
+ require "dry/system/version"
8
+
9
+ Gem::Specification.new do |spec|
10
+ spec.name = "dry-system"
11
+ spec.authors = ["Hanakai team"]
12
+ spec.email = ["info@hanakai.org"]
13
+ spec.license = "MIT"
14
+ spec.version = Dry::System::VERSION.dup
15
+
16
+ spec.summary = "Organize your code into reusable components"
17
+ spec.description = spec.summary
18
+ spec.homepage = "https://dry-rb.org/gems/dry-system"
19
+ spec.files = Dir["CHANGELOG.md", "LICENSE", "README.md", "dry-system.gemspec", "lib/**/*"]
20
+ spec.bindir = "bin"
21
+ spec.executables = []
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.extra_rdoc_files = ["README.md", "CHANGELOG.md", "LICENSE"]
25
+
26
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
27
+ spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-system/blob/main/CHANGELOG.md"
28
+ spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-system"
29
+ spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-system/issues"
30
+ spec.metadata["funding_uri"] = "https://github.com/sponsors/hanami"
31
+
32
+ spec.required_ruby_version = ">= 3.1.0"
33
+
34
+ spec.add_runtime_dependency "dry-auto_inject", "~> 1.1"
35
+ spec.add_runtime_dependency "dry-configurable", "~> 1.3"
36
+ spec.add_runtime_dependency "dry-core", "~> 1.1"
37
+ spec.add_runtime_dependency "dry-inflector", "~> 1.1"
38
+ spec.add_development_dependency "bundler"
39
+ spec.add_development_dependency "rake"
40
+ spec.add_development_dependency "rspec"
41
+ end
42
+
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dry/system/constants"
4
+
5
+ module Dry
6
+ module System
7
+ # Default auto-registration implementation
8
+ #
9
+ # This is currently configured by default for every System::Container.
10
+ # Auto-registrar objects are responsible for loading files from configured
11
+ # auto-register paths and registering components automatically within the
12
+ # container.
13
+ #
14
+ # @api private
15
+ class AutoRegistrar
16
+ attr_reader :container
17
+
18
+ def initialize(container)
19
+ @container = container
20
+ end
21
+
22
+ # @api private
23
+ def finalize!
24
+ container.component_dirs.each do |component_dir|
25
+ call(component_dir) if component_dir.auto_register?
26
+ end
27
+ end
28
+
29
+ # @api private
30
+ def call(component_dir)
31
+ component_dir.each_component do |component|
32
+ next unless register_component?(component)
33
+
34
+ container.register(component.key, memoize: component.memoize?) { component.instance }
35
+ end
36
+ end
37
+
38
+ private
39
+
40
+ def register_component?(component)
41
+ !container.registered?(component.key) && component.auto_register?
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,190 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pathname"
4
+ require "dry/inflector"
5
+ require "dry/system/errors"
6
+ require "dry/system/constants"
7
+
8
+ module Dry
9
+ module System
10
+ # Components are objects providing information about auto-registered files.
11
+ # They expose an API to query this information and use a configurable
12
+ # loader object to initialize class instances.
13
+ #
14
+ # @api public
15
+ class Component
16
+ include Dry::Equalizer(:identifier, :file_path, :namespace, :options)
17
+
18
+ DEFAULT_OPTIONS = {
19
+ inflector: Dry::Inflector.new,
20
+ loader: Loader
21
+ }.freeze
22
+
23
+ # @!attribute [r] identifier
24
+ # @return [String] the component's unique identifier
25
+ attr_reader :identifier
26
+
27
+ # @!attribute [r] file_path
28
+ # @return [Pathname] the component's source file path
29
+ attr_reader :file_path
30
+
31
+ # @!attribute [r] namespace
32
+ # @return [Dry::System::Config::Namespace] the component's namespace
33
+ attr_reader :namespace
34
+
35
+ # @!attribute [r] options
36
+ # @return [Hash] the component's options
37
+ attr_reader :options
38
+
39
+ # @api private
40
+ def initialize(identifier, file_path:, namespace:, **options)
41
+ @identifier = identifier
42
+ @file_path = Pathname(file_path)
43
+ @namespace = namespace
44
+ @options = DEFAULT_OPTIONS.merge(options)
45
+ end
46
+
47
+ # Returns true, indicating that the component is directly loadable from the files
48
+ # managed by the container
49
+ #
50
+ # This is the inverse of {IndirectComponent#loadable?}
51
+ #
52
+ # @return [TrueClass]
53
+ #
54
+ # @api private
55
+ def loadable?
56
+ true
57
+ end
58
+
59
+ # Returns the component's instance
60
+ #
61
+ # @return [Object] component's class instance
62
+ # @api public
63
+ def instance(*args, **kwargs)
64
+ options[:instance]&.call(self, *args, **kwargs) || loader.call(self, *args, **kwargs)
65
+ end
66
+
67
+ # Returns the component's unique key
68
+ #
69
+ # @return [String] the key
70
+ #
71
+ # @see Identifier#key
72
+ #
73
+ # @api public
74
+ def key
75
+ identifier.key
76
+ end
77
+
78
+ # Returns the root namespace segment of the component's key, as a symbol
79
+ #
80
+ # @see Identifier#root_key
81
+ #
82
+ # @return [Symbol] the root key
83
+ #
84
+ # @api public
85
+ def root_key
86
+ identifier.root_key
87
+ end
88
+
89
+ # Returns a path-delimited representation of the compnent, appropriate for passing
90
+ # to `Kernel#require` to require its source file
91
+ #
92
+ # The path takes into account the rules of the namespace used to load the component.
93
+ #
94
+ # @example Component from a root namespace
95
+ # component.key # => "articles.create"
96
+ # component.require_path # => "articles/create"
97
+ #
98
+ # @example Component from an "admin/" path namespace (with `key: nil`)
99
+ # component.key # => "articles.create"
100
+ # component.require_path # => "admin/articles/create"
101
+ #
102
+ # @see Config::Namespaces#add
103
+ # @see Config::Namespace
104
+ #
105
+ # @return [String] the require path
106
+ #
107
+ # @api public
108
+ def require_path
109
+ if namespace.path
110
+ "#{namespace.path}#{PATH_SEPARATOR}#{path_in_namespace}"
111
+ else
112
+ path_in_namespace
113
+ end
114
+ end
115
+
116
+ # Returns an "underscored", path-delimited representation of the component,
117
+ # appropriate for passing to the inflector for constantizing
118
+ #
119
+ # The const path takes into account the rules of the namespace used to load the
120
+ # component.
121
+ #
122
+ # @example Component from a namespace with `const: nil`
123
+ # component.key # => "articles.create_article"
124
+ # component.const_path # => "articles/create_article"
125
+ # component.inflector.constantize(component.const_path) # => Articles::CreateArticle
126
+ #
127
+ # @example Component from a namespace with `const: "admin"`
128
+ # component.key # => "articles.create_article"
129
+ # component.const_path # => "admin/articles/create_article"
130
+ # component.inflector.constantize(component.const_path) # => Admin::Articles::CreateArticle
131
+ #
132
+ # @see Config::Namespaces#add
133
+ # @see Config::Namespace
134
+ #
135
+ # @return [String] the const path
136
+ #
137
+ # @api public
138
+ def const_path
139
+ namespace_const_path = namespace.const&.gsub(KEY_SEPARATOR, PATH_SEPARATOR)
140
+
141
+ if namespace_const_path
142
+ "#{namespace_const_path}#{PATH_SEPARATOR}#{path_in_namespace}"
143
+ else
144
+ path_in_namespace
145
+ end
146
+ end
147
+
148
+ # @api private
149
+ def loader
150
+ options.fetch(:loader)
151
+ end
152
+
153
+ # @api private
154
+ def inflector
155
+ options.fetch(:inflector)
156
+ end
157
+
158
+ # @api private
159
+ def auto_register?
160
+ callable_option?(options[:auto_register])
161
+ end
162
+
163
+ # @api private
164
+ def memoize?
165
+ callable_option?(options[:memoize])
166
+ end
167
+
168
+ private
169
+
170
+ def path_in_namespace
171
+ identifier_in_namespace =
172
+ if namespace.key
173
+ identifier.namespaced(from: namespace.key, to: nil)
174
+ else
175
+ identifier
176
+ end
177
+
178
+ identifier_in_namespace.key_with_separator(PATH_SEPARATOR)
179
+ end
180
+
181
+ def callable_option?(value)
182
+ if value.respond_to?(:call)
183
+ !!value.call(self)
184
+ else
185
+ !!value
186
+ end
187
+ end
188
+ end
189
+ end
190
+ end
@@ -0,0 +1,171 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pathname"
4
+ require "dry/system/constants"
5
+
6
+ module Dry
7
+ module System
8
+ # A configured component directory within the container's root. Provides access to the
9
+ # component directory's configuration, as well as methods for locating component files
10
+ # within the directory
11
+ #
12
+ # @see Dry::System::Config::ComponentDir
13
+ # @api private
14
+ class ComponentDir
15
+ # @!attribute [r] config
16
+ # @return [Dry::System::Config::ComponentDir] the component directory configuration
17
+ # @api private
18
+ attr_reader :config
19
+
20
+ # @!attribute [r] container
21
+ # @return [Dry::System::Container] the container managing the component directory
22
+ # @api private
23
+ attr_reader :container
24
+
25
+ # @api private
26
+ def initialize(config:, container:)
27
+ @config = config
28
+ @container = container
29
+ end
30
+
31
+ # Returns a component for the given key if a matching source file is found within
32
+ # the component dir
33
+ #
34
+ # This searches according to the component dir's configured namespaces, in order of
35
+ # definition, with the first match returned as the component.
36
+ #
37
+ # @param key [String] the component's key
38
+ # @return [Dry::System::Component, nil] the component, if found
39
+ #
40
+ # @api private
41
+ def component_for_key(key)
42
+ config.namespaces.each do |namespace|
43
+ identifier = Identifier.new(key)
44
+
45
+ next unless identifier.start_with?(namespace.key)
46
+
47
+ if (file_path = find_component_file(identifier, namespace))
48
+ return build_component(identifier, namespace, file_path)
49
+ end
50
+ end
51
+
52
+ nil
53
+ end
54
+
55
+ def each_component
56
+ return enum_for(:each_component) unless block_given?
57
+
58
+ each_file do |file_path, namespace|
59
+ yield component_for_path(file_path, namespace)
60
+ end
61
+ end
62
+
63
+ private
64
+
65
+ def each_file
66
+ return enum_for(:each_file) unless block_given?
67
+
68
+ raise ComponentDirNotFoundError, full_path unless Dir.exist?(full_path)
69
+
70
+ config.namespaces.each do |namespace|
71
+ files(namespace).each do |file|
72
+ yield file, namespace
73
+ end
74
+ end
75
+ end
76
+
77
+ def files(namespace)
78
+ if namespace.path?
79
+ ::Dir[::File.join(full_path, namespace.path, "**", RB_GLOB)]
80
+ else
81
+ non_root_paths = config.namespaces.to_a.reject(&:root?).map(&:path)
82
+
83
+ ::Dir[::File.join(full_path, "**", RB_GLOB)].reject { |file_path|
84
+ Pathname(file_path).relative_path_from(full_path).to_s.start_with?(*non_root_paths)
85
+ }
86
+ end
87
+ end
88
+
89
+ # Returns the full path of the component directory
90
+ #
91
+ # @return [Pathname]
92
+ def full_path
93
+ container.root.join(path)
94
+ end
95
+
96
+ # Returns a component for a full path to a Ruby source file within the component dir
97
+ #
98
+ # @param path [String] the full path to the file
99
+ # @return [Dry::System::Component] the component
100
+ def component_for_path(path, namespace)
101
+ key = Pathname(path).relative_path_from(full_path).to_s
102
+ .sub(RB_EXT, EMPTY_STRING)
103
+ .scan(WORD_REGEX)
104
+ .join(KEY_SEPARATOR)
105
+
106
+ identifier = Identifier.new(key)
107
+ .namespaced(
108
+ from: namespace.path&.gsub(PATH_SEPARATOR, KEY_SEPARATOR),
109
+ to: namespace.key
110
+ )
111
+
112
+ build_component(identifier, namespace, path)
113
+ end
114
+
115
+ def find_component_file(identifier, namespace)
116
+ # To properly find the file within a namespace with a key, we should strip the key
117
+ # from beginning of our given identifier
118
+ if namespace.key
119
+ identifier = identifier.namespaced(from: namespace.key, to: nil)
120
+ end
121
+
122
+ file_name = "#{identifier.key_with_separator(PATH_SEPARATOR)}#{RB_EXT}"
123
+
124
+ component_file =
125
+ if namespace.path?
126
+ full_path.join(namespace.path, file_name)
127
+ else
128
+ full_path.join(file_name)
129
+ end
130
+
131
+ component_file if component_file.exist?
132
+ end
133
+
134
+ def build_component(identifier, namespace, file_path)
135
+ options = {
136
+ inflector: container.config.inflector,
137
+ **component_options,
138
+ **MagicCommentsParser.(file_path)
139
+ }
140
+
141
+ Component.new(
142
+ identifier,
143
+ namespace: namespace,
144
+ file_path: file_path,
145
+ **options
146
+ )
147
+ end
148
+
149
+ def component_options
150
+ {
151
+ auto_register: auto_register,
152
+ loader: loader,
153
+ instance: instance,
154
+ memoize: memoize
155
+ }
156
+ end
157
+
158
+ def method_missing(name, ...)
159
+ if config.respond_to?(name)
160
+ config.public_send(name, ...)
161
+ else
162
+ super
163
+ end
164
+ end
165
+
166
+ def respond_to_missing?(name, include_all = false)
167
+ config.respond_to?(name) || super
168
+ end
169
+ end
170
+ end
171
+ end