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,289 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pathname"
4
+
5
+ require "dry/system/errors"
6
+ require "dry/system/constants"
7
+
8
+ module Dry
9
+ module System
10
+ # Default provider registrar implementation
11
+ #
12
+ # This is currently configured by default for every Dry::System::Container. The
13
+ # provider registrar is responsible for loading provider files and exposing an API for
14
+ # running the provider lifecycle steps.
15
+ #
16
+ # @api public
17
+ # @since 1.1.0
18
+ class ProviderRegistrar
19
+ # @api private
20
+ attr_reader :providers
21
+
22
+ # @api private
23
+ attr_reader :container
24
+
25
+ # Returns the container exposed to providers as `target_container`.
26
+ #
27
+ # @return [Dry::System::Container]
28
+ #
29
+ # @api public
30
+ # @since 1.1.0
31
+ alias_method :target_container, :container
32
+
33
+ # @api private
34
+ def initialize(container)
35
+ @providers = {}
36
+ @container = container
37
+ end
38
+
39
+ # @api private
40
+ def freeze
41
+ providers.freeze
42
+ super
43
+ end
44
+
45
+ # rubocop:disable Metrics/PerceivedComplexity
46
+
47
+ # @see Container.register_provider
48
+ # @api private
49
+ def register_provider(name, from: nil, source: nil, if: true, **provider_options, &)
50
+ raise ProviderAlreadyRegisteredError, name if providers.key?(name)
51
+
52
+ if from && source.is_a?(Class)
53
+ raise ArgumentError, "You must supply a block when using a provider source"
54
+ end
55
+
56
+ if block_given? && source.is_a?(Class)
57
+ raise ArgumentError, "You must supply only a `source:` option or a block, not both"
58
+ end
59
+
60
+ return self unless binding.local_variable_get(:if)
61
+
62
+ provider =
63
+ if from
64
+ build_provider_from_source(
65
+ name,
66
+ source: source || name,
67
+ group: from,
68
+ options: provider_options,
69
+ &
70
+ )
71
+ else
72
+ build_provider(
73
+ name,
74
+ source: source,
75
+ options: provider_options,
76
+ &
77
+ )
78
+ end
79
+
80
+ providers[provider.name] = provider
81
+
82
+ self
83
+ end
84
+
85
+ # rubocop:enable Metrics/PerceivedComplexity
86
+
87
+ # Returns a provider if it can be found or loaded, otherwise nil
88
+ #
89
+ # @return [Dry::System::Provider, nil]
90
+ #
91
+ # @api public
92
+ def [](provider_name)
93
+ provider_name = provider_name.to_sym
94
+
95
+ if (provider = providers[provider_name])
96
+ return provider
97
+ end
98
+
99
+ return if finalized?
100
+
101
+ require_provider_file(provider_name)
102
+
103
+ providers[provider_name]
104
+ end
105
+
106
+ # @api public
107
+ alias_method :find_and_load_provider, :[]
108
+
109
+ # @api private
110
+ def key?(provider_name)
111
+ providers.key?(provider_name)
112
+ end
113
+
114
+ # Returns all provider files within the configured provider_paths.
115
+ #
116
+ # Searches for files in the order of the configured provider_paths. In the case of multiple
117
+ # identically-named boot files within different provider_paths, the file found first will be
118
+ # returned, and other matching files will be discarded.
119
+ #
120
+ # This method is public to allow other tools extending dry-system (like dry-rails)
121
+ # to access a canonical list of real, in-use provider files.
122
+ #
123
+ # @see Container.provider_paths
124
+ #
125
+ # @return [Array<Pathname>]
126
+ # @api public
127
+ def provider_files
128
+ @provider_files ||= provider_paths.each_with_object([[], []]) { |path, (provider_files, loaded)|
129
+ files = ::Dir["#{path}/#{RB_GLOB}"]
130
+
131
+ files.each do |file|
132
+ basename = ::File.basename(file)
133
+
134
+ unless loaded.include?(basename)
135
+ provider_files << Pathname(file)
136
+ loaded << basename
137
+ end
138
+ end
139
+ }.first
140
+ end
141
+
142
+ # Extension point for subclasses to customize their
143
+ # provider source superclass. Expected to be a subclass
144
+ # of Dry::System::Provider::Source
145
+ #
146
+ # @api public
147
+ # @since 1.1.0
148
+ def provider_source_class = Dry::System::Provider::Source
149
+
150
+ # Extension point for subclasses to customize initialization
151
+ # params for provider_source_class
152
+ #
153
+ # @api public
154
+ # @since 1.1.0
155
+ def provider_source_options = {}
156
+
157
+ # @api private
158
+ def finalize!
159
+ provider_files.each do |path|
160
+ load_provider(path)
161
+ end
162
+
163
+ providers.each_value(&:start)
164
+
165
+ freeze
166
+ end
167
+
168
+ # @!method finalized?
169
+ # Returns true if the booter has been finalized
170
+ #
171
+ # @return [Boolean]
172
+ # @api private
173
+ alias_method :finalized?, :frozen?
174
+
175
+ # @api private
176
+ def shutdown
177
+ providers.each_value(&:stop)
178
+ self
179
+ end
180
+
181
+ # @api private
182
+ def prepare(provider_name)
183
+ with_provider(provider_name, &:prepare)
184
+ self
185
+ end
186
+
187
+ # @api private
188
+ def start(provider_name)
189
+ with_provider(provider_name, &:start)
190
+ self
191
+ end
192
+
193
+ # @api private
194
+ def stop(provider_name)
195
+ with_provider(provider_name, &:stop)
196
+ self
197
+ end
198
+
199
+ private
200
+
201
+ # @api private
202
+ def provider_paths
203
+ provider_dirs = container.config.provider_dirs
204
+
205
+ provider_dirs.map { |dir|
206
+ dir = Pathname(dir)
207
+
208
+ if dir.relative?
209
+ container.root.join(dir)
210
+ else
211
+ dir
212
+ end
213
+ }
214
+ end
215
+
216
+ def build_provider(name, options:, source: nil, &)
217
+ source_class = source || Provider::Source.for(
218
+ name: name,
219
+ superclass: provider_source_class,
220
+ &
221
+ )
222
+
223
+ source_options =
224
+ if source_class < provider_source_class
225
+ provider_source_options
226
+ else
227
+ {}
228
+ end
229
+
230
+ Provider.new(
231
+ **options,
232
+ name: name,
233
+ target_container: target_container,
234
+ source_class: source_class,
235
+ source_options: source_options
236
+ )
237
+ end
238
+
239
+ def build_provider_from_source(name, source:, group:, options:, &)
240
+ provider_source = System.provider_sources.resolve(name: source, group: group)
241
+
242
+ source_options =
243
+ if provider_source.source <= provider_source_class
244
+ provider_source_options
245
+ else
246
+ {}
247
+ end
248
+
249
+ Provider.new(
250
+ **provider_source.provider_options,
251
+ **options,
252
+ name: name,
253
+ target_container: target_container,
254
+ source_class: provider_source.source,
255
+ source_options: source_options,
256
+ &
257
+ )
258
+ end
259
+
260
+ def with_provider(provider_name)
261
+ require_provider_file(provider_name) unless providers.key?(provider_name)
262
+
263
+ provider = providers[provider_name]
264
+
265
+ raise ProviderNotFoundError, provider_name unless provider
266
+
267
+ yield(provider)
268
+ end
269
+
270
+ def load_provider(path)
271
+ name = Pathname(path).basename(RB_EXT).to_s.to_sym
272
+
273
+ Kernel.require path unless providers.key?(name)
274
+
275
+ self
276
+ end
277
+
278
+ def require_provider_file(name)
279
+ provider_file = find_provider_file(name)
280
+
281
+ Kernel.require provider_file if provider_file
282
+ end
283
+
284
+ def find_provider_file(name)
285
+ provider_files.detect { |file| File.basename(file, RB_EXT) == name.to_s }
286
+ end
287
+ end
288
+ end
289
+ end
@@ -0,0 +1,67 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dry/system/constants"
4
+
5
+ module Dry
6
+ module System
7
+ # @api private
8
+ class ProviderSourceRegistry
9
+ # @api private
10
+ class Registration
11
+ attr_reader :source
12
+ attr_reader :provider_options
13
+
14
+ def initialize(source:, provider_options:)
15
+ @source = source
16
+ @provider_options = provider_options
17
+ end
18
+ end
19
+
20
+ attr_reader :sources
21
+
22
+ def initialize
23
+ @sources = {}
24
+ end
25
+
26
+ def load_sources(path)
27
+ ::Dir[::File.join(path, "**/#{RB_GLOB}")].each do |file|
28
+ require file
29
+ end
30
+ end
31
+
32
+ def register(name:, group:, source:, provider_options:)
33
+ sources[key(name, group)] = Registration.new(
34
+ source: source,
35
+ provider_options: provider_options
36
+ )
37
+ end
38
+
39
+ def register_from_block(name:, group:, provider_options:, &)
40
+ register(
41
+ name: name,
42
+ group: group,
43
+ source: Provider::Source.for(name: name, group: group, &),
44
+ provider_options: provider_options
45
+ )
46
+ end
47
+
48
+ def resolve(name:, group:)
49
+ sources[key(name, group)].tap { |source|
50
+ unless source
51
+ raise ProviderSourceNotFoundError.new(
52
+ name: name,
53
+ group: group,
54
+ keys: sources.keys
55
+ )
56
+ end
57
+ }
58
+ end
59
+
60
+ private
61
+
62
+ def key(name, group)
63
+ {group: group, name: name}
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,73 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dry
4
+ module System
5
+ module ProviderSources
6
+ # @api private
7
+ module Settings
8
+ InvalidSettingsError = Class.new(ArgumentError) do
9
+ # @api private
10
+ def initialize(errors)
11
+ message = <<~STR
12
+ Could not load settings. The following settings were invalid:
13
+
14
+ #{setting_errors(errors).join("\n")}
15
+ STR
16
+
17
+ super(message)
18
+ end
19
+
20
+ private
21
+
22
+ def setting_errors(errors)
23
+ errors.sort_by { |k, _| k }.map { |key, error| "#{key}: #{error}" }
24
+ end
25
+ end
26
+
27
+ # @api private
28
+ class Config
29
+ # @api private
30
+ def self.load(root:, env:, loader: Loader)
31
+ loader = loader.new(root: root, env: env)
32
+
33
+ new.tap do |settings_obj|
34
+ errors = {}
35
+
36
+ settings.to_a.each do |setting|
37
+ value = loader[setting.name.to_s.upcase]
38
+
39
+ begin
40
+ if value
41
+ settings_obj.config.public_send(:"#{setting.name}=", value)
42
+ else
43
+ settings_obj.config[setting.name]
44
+ end
45
+ rescue => exception # rubocop:disable Style/RescueStandardError
46
+ errors[setting.name] = exception
47
+ end
48
+ end
49
+
50
+ raise InvalidSettingsError, errors unless errors.empty?
51
+ end
52
+ end
53
+
54
+ include Dry::Configurable
55
+
56
+ private
57
+
58
+ def method_missing(name, ...)
59
+ if config.respond_to?(name)
60
+ config.public_send(name, ...)
61
+ else
62
+ super
63
+ end
64
+ end
65
+
66
+ def respond_to_missing?(name, include_all = false)
67
+ config.respond_to?(name, include_all) || super
68
+ end
69
+ end
70
+ end
71
+ end
72
+ end
73
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dry
4
+ module System
5
+ module ProviderSources
6
+ module Settings
7
+ # @api private
8
+ class Loader
9
+ # @api private
10
+ attr_reader :store
11
+
12
+ # @api private
13
+ def initialize(root:, env:, store: ENV)
14
+ @store = store
15
+ load_dotenv(root, env.to_sym)
16
+ end
17
+
18
+ # @api private
19
+ def [](key)
20
+ store[key]
21
+ end
22
+
23
+ private
24
+
25
+ def load_dotenv(root, env)
26
+ require "dotenv"
27
+ Dotenv.load(*dotenv_files(root, env)) if defined?(Dotenv)
28
+ rescue LoadError
29
+ # Do nothing if dotenv is unavailable
30
+ end
31
+
32
+ def dotenv_files(root, env)
33
+ [
34
+ File.join(root, ".env.#{env}.local"),
35
+ (File.join(root, ".env.local") unless env == :test),
36
+ File.join(root, ".env.#{env}"),
37
+ File.join(root, ".env")
38
+ ].compact
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dry
4
+ module System
5
+ module ProviderSources
6
+ module Settings
7
+ class Source < Dry::System::Provider::Source
8
+ setting :store
9
+
10
+ def prepare
11
+ require "dry/system/provider_sources/settings/config"
12
+ end
13
+
14
+ def start
15
+ register(:settings, settings.load(root: target.root, env: target.config.env))
16
+ end
17
+
18
+ def settings(&block)
19
+ # Save the block and evaluate it lazily to allow a provider with this source
20
+ # to `require` any necessary files for the block to evaluate correctly (e.g.
21
+ # requiring an app-specific types module for setting constructors)
22
+ if block
23
+ @settings_block = block
24
+ elsif defined? @settings_class
25
+ @settings_class
26
+ elsif @settings_block
27
+ @settings_class = Class.new(Settings::Config, &@settings_block)
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ end
34
+ end
35
+
36
+ Dry::System.register_provider_source(
37
+ :settings,
38
+ group: :dry_system,
39
+ source: Dry::System::ProviderSources::Settings::Source
40
+ )
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "pathname"
4
+ require "dry/system"
5
+
6
+ Dry::System.register_provider_sources Pathname(__dir__).join("provider_sources").realpath
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dry/core/container/stub"
4
+
5
+ module Dry
6
+ module System
7
+ class Container
8
+ # @api private
9
+ module Stubs
10
+ # This overrides default finalize! just to disable automatic freezing
11
+ # of the container
12
+ #
13
+ # @api private
14
+ def finalize!(**, &)
15
+ super(freeze: false, &)
16
+ end
17
+ end
18
+
19
+ # Enables stubbing container's components
20
+ #
21
+ # @example
22
+ # require 'dry/system/stubs'
23
+ #
24
+ # MyContainer.enable_stubs!
25
+ # MyContainer.finalize!
26
+ #
27
+ # MyContainer.stub('some.component', some_stub_object)
28
+ #
29
+ # @return Container
30
+ #
31
+ # @api public
32
+ def self.enable_stubs!
33
+ super
34
+ extend ::Dry::System::Container::Stubs
35
+ self
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Dry
4
+ module System
5
+ VERSION = "1.2.5"
6
+ end
7
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "zeitwerk"
4
+ require "dry/core"
5
+
6
+ module Dry
7
+ module System
8
+ # @api private
9
+ def self.loader
10
+ @loader ||= Zeitwerk::Loader.new.tap do |loader|
11
+ root = File.expand_path("..", __dir__)
12
+ loader.tag = "dry-system"
13
+ loader.inflector = Zeitwerk::GemInflector.new("#{root}/dry-system.rb")
14
+ loader.push_dir(root)
15
+ loader.ignore(
16
+ "#{root}/dry-system.rb",
17
+ "#{root}/dry/system/{components,constants,errors,stubs,version}.rb"
18
+ )
19
+ loader.inflector.inflect("source_dsl" => "SourceDSL")
20
+ end
21
+ end
22
+
23
+ # Registers the provider sources in the files under the given path
24
+ #
25
+ # @api public
26
+ def self.register_provider_sources(path)
27
+ provider_sources.load_sources(path)
28
+ end
29
+
30
+ # Registers a provider source, which can be used as the basis for other providers
31
+ #
32
+ # @api public
33
+ def self.register_provider_source(name, group:, source: nil, provider_options: {}, &)
34
+ if source && block_given?
35
+ raise ArgumentError, "You must supply only a `source:` option or a block, not both"
36
+ end
37
+
38
+ if source
39
+ provider_sources.register(
40
+ name: name,
41
+ group: group,
42
+ source: source,
43
+ provider_options: provider_options
44
+ )
45
+ else
46
+ provider_sources.register_from_block(
47
+ name: name,
48
+ group: group,
49
+ provider_options: provider_options,
50
+ &
51
+ )
52
+ end
53
+ end
54
+
55
+ # @api private
56
+ def self.provider_sources
57
+ @provider_sources ||= ProviderSourceRegistry.new
58
+ end
59
+
60
+ loader.setup
61
+ end
62
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dry/system"
@@ -0,0 +1,11 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "piko-quick-lib"
3
+ s.version = "0.0.1"
4
+ s.summary = "Research test"
5
+ s.description = "University research based on dry-system"
6
+ s.authors = ["Andrey78"]
7
+ s.email = ["cakoc614@gmail.com"]
8
+ s.files = Dir.glob("**/*").reject { |f| f.end_with?('.gem') }
9
+ s.homepage = "https://rubygems.org/profiles/Andrey78"
10
+ s.license = "MIT"
11
+ end