k_config 0.0.2 → 0.0.6
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.
- checksums.yaml +4 -4
- data/docs/CHANGELOG.md +30 -0
- data/k_config.gemspec +2 -2
- data/lib/k_config/configuration.rb +65 -0
- data/lib/k_config/version.rb +1 -1
- data/lib/k_config.rb +36 -1
- data/package-lock.json +2 -2
- data/package.json +1 -1
- metadata +32 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: be6c1f47d8c6aaf2d67dbab345553d77b26d2bbc501dc12f8e756c7c833db264
|
4
|
+
data.tar.gz: 82dda6d6aa206e3d3e6a6c56481b3519a38069c27155c3a9decadaea2a2b79fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8ce80196bebde6e003279ee8b911b248da17842af31fc3848c7699888d908794a40b0de4cd4fd37f7116f276b7f18d3a45873edc3f66042d224cfd765ffbadb0
|
7
|
+
data.tar.gz: d79ec61cbf83797f0dbc60e13fc01c3a4ba3b415cd7a113575154453929d47e1ae2544d48d703ca5789f83240a3542a5d4fabb4e2220f0bd28ecf45b98c7d292
|
data/docs/CHANGELOG.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
## [0.0.5](https://github.com/klueless-io/k_config/compare/v0.0.4...v0.0.5) (2022-02-04)
|
2
|
+
|
3
|
+
|
4
|
+
### Bug Fixes
|
5
|
+
|
6
|
+
* add registered extensions and support for debug and initialize_copy inside of registered extensions ([da0d62d](https://github.com/klueless-io/k_config/commit/da0d62dcd6b4d1c4f556e2bccf6bde56a06baf8c))
|
7
|
+
* add registered extensions and support for debug and initialize_copy inside of registered extensions ([ce35adb](https://github.com/klueless-io/k_config/commit/ce35adb700c16e189da7a70d9aa206a91f629f99))
|
8
|
+
* flakey test ([ca87322](https://github.com/klueless-io/k_config/commit/ca873225580d406c0a2dc8709f04a9dd223b5c23))
|
9
|
+
|
10
|
+
## [0.0.4](https://github.com/klueless-io/k_config/compare/v0.0.3...v0.0.4) (2022-02-04)
|
11
|
+
|
12
|
+
|
13
|
+
### Bug Fixes
|
14
|
+
|
15
|
+
* add custom debug support ([5e1c344](https://github.com/klueless-io/k_config/commit/5e1c34444a23b7e3e9d50106524ed055e50d2d9b))
|
16
|
+
|
17
|
+
## [0.0.3](https://github.com/klueless-io/k_config/compare/v0.0.2...v0.0.3) (2022-02-04)
|
18
|
+
|
19
|
+
|
20
|
+
### Bug Fixes
|
21
|
+
|
22
|
+
* update gem dependancies ([6de42d0](https://github.com/klueless-io/k_config/commit/6de42d0d94b447a4a246a8889b4e5c88af3427f2))
|
23
|
+
|
24
|
+
## [0.0.2](https://github.com/klueless-io/k_config/compare/v0.0.1...v0.0.2) (2022-02-04)
|
25
|
+
|
26
|
+
|
27
|
+
### Bug Fixes
|
28
|
+
|
29
|
+
* github actions (ci/cd) ([ddde14c](https://github.com/klueless-io/k_config/commit/ddde14c614eaf904cc15dc4dc5e2131e1c6ce620))
|
30
|
+
* github actions (ci/cd) ([2cfd62d](https://github.com/klueless-io/k_config/commit/2cfd62d6c4031008107366efc1fd88c78136fbc4))
|
data/k_config.gemspec
CHANGED
@@ -42,6 +42,6 @@ Gem::Specification.new do |spec|
|
|
42
42
|
}
|
43
43
|
|
44
44
|
spec.add_dependency 'k_log', '~> 0.0.0'
|
45
|
-
|
46
|
-
|
45
|
+
spec.add_dependency 'k_type', '~> 0.0.0'
|
46
|
+
spec.add_dependency 'k_util', '~> 0.0.0'
|
47
47
|
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module KConfig
|
4
|
+
# Configuration object for all k_* GEMs.
|
5
|
+
#
|
6
|
+
# Hooks:
|
7
|
+
# You can use hooks to add your own customizations to configuration extensions.
|
8
|
+
class Configuration
|
9
|
+
include KUtil::Data::InstanceVariablesToH
|
10
|
+
include KLog::Logging
|
11
|
+
|
12
|
+
attr_accessor :config_name
|
13
|
+
|
14
|
+
# Initialize configuration.
|
15
|
+
#
|
16
|
+
# Will call #{configuration_key}_initialize method if it exists.
|
17
|
+
def initialize
|
18
|
+
self.class.registered_keys.each do |key|
|
19
|
+
method = "#{key}_initialize".to_sym
|
20
|
+
send(method) if respond_to?(method)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# Debug configuration is used for debugging.
|
25
|
+
#
|
26
|
+
# Will call #{configuration_key}_debug method if it exists.
|
27
|
+
def debug
|
28
|
+
log.section_heading(config_name) if config_name
|
29
|
+
|
30
|
+
self.class.registered_keys.each do |key|
|
31
|
+
method = "#{key}_debug".to_sym
|
32
|
+
send(method) if respond_to?(method)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Initialize_copy, used during clone.
|
37
|
+
#
|
38
|
+
# Will call #{configuration_key}_initialize_copy method if it exists.
|
39
|
+
def initialize_copy(orig)
|
40
|
+
self.class.registered_keys.each do |key|
|
41
|
+
method = "#{key}_initialize_copy".to_sym
|
42
|
+
send(method, orig) if respond_to?(method)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
class << self
|
47
|
+
def registered_keys
|
48
|
+
@registered_keys ||= []
|
49
|
+
end
|
50
|
+
|
51
|
+
# Register configuration extension key
|
52
|
+
#
|
53
|
+
# This key provides a unique method name prefix to common methods such as debug and initialize_copy
|
54
|
+
def register(key, extension)
|
55
|
+
if registered_keys.include?(key)
|
56
|
+
puts "Key #{key} already registered ... skipping"
|
57
|
+
return registered_keys
|
58
|
+
end
|
59
|
+
|
60
|
+
include(extension)
|
61
|
+
registered_keys << key
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/lib/k_config/version.rb
CHANGED
data/lib/k_config.rb
CHANGED
@@ -1,12 +1,47 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'k_log'
|
4
|
+
require 'k_type'
|
5
|
+
|
3
6
|
require_relative 'k_config/version'
|
7
|
+
require_relative 'k_config/configuration'
|
4
8
|
|
9
|
+
# KConfig is a configuration helper for k_* GEMs.
|
5
10
|
module KConfig
|
6
11
|
# raise KConfig::Error, 'Sample message'
|
7
12
|
Error = Class.new(StandardError)
|
8
13
|
|
9
|
-
#
|
14
|
+
# Configuration helpers
|
15
|
+
class << self
|
16
|
+
attr_writer :configuration
|
17
|
+
attr_writer :default_configuration_type
|
18
|
+
|
19
|
+
def default_configuration_type
|
20
|
+
@default_configuration_type ||= KConfig::Configuration
|
21
|
+
end
|
22
|
+
|
23
|
+
def configuration(config_name = :default)
|
24
|
+
@configuration ||= Hash.new do |h, key|
|
25
|
+
h[key] = default_configuration_type.new
|
26
|
+
end
|
27
|
+
config = @configuration[config_name]
|
28
|
+
config.config_name = config_name if config.respond_to?(:config_name) && config.config_name.nil?
|
29
|
+
config
|
30
|
+
end
|
31
|
+
|
32
|
+
def reset(config_name = :default)
|
33
|
+
@configuration ||= Hash.new do |h, key|
|
34
|
+
h[key] = default_configuration_type.new
|
35
|
+
end
|
36
|
+
config = default_configuration_type.new
|
37
|
+
config.config_name = config_name if config.respond_to?(:config_name) && config.config_name.nil?
|
38
|
+
@configuration[config_name] = config
|
39
|
+
end
|
40
|
+
|
41
|
+
def configure(config_name = :default)
|
42
|
+
yield(configuration(config_name))
|
43
|
+
end
|
44
|
+
end
|
10
45
|
end
|
11
46
|
|
12
47
|
if ENV['KLUE_DEBUG']&.to_s&.downcase == 'true'
|
data/package-lock.json
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
{
|
2
2
|
"name": "k_config",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.6",
|
4
4
|
"lockfileVersion": 2,
|
5
5
|
"requires": true,
|
6
6
|
"packages": {
|
7
7
|
"": {
|
8
8
|
"name": "k_config",
|
9
|
-
"version": "0.0.
|
9
|
+
"version": "0.0.6",
|
10
10
|
"devDependencies": {
|
11
11
|
"@klueless-js/semantic-release-rubygem": "github:klueless-js/semantic-release-rubygem",
|
12
12
|
"@semantic-release/changelog": "^6.0.1",
|
data/package.json
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: k_config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- David Cruwys
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-02-
|
11
|
+
date: 2022-02-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: k_log
|
@@ -24,6 +24,34 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.0.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: k_type
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.0.0
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.0.0
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: k_util
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 0.0.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 0.0.0
|
27
55
|
description: " KConfig provides configuration for multi-plugin architecture\n"
|
28
56
|
email:
|
29
57
|
- david@ideasmen.com.au
|
@@ -49,10 +77,12 @@ files:
|
|
49
77
|
- Rakefile
|
50
78
|
- bin/console
|
51
79
|
- bin/setup
|
80
|
+
- docs/CHANGELOG.md
|
52
81
|
- docs/CODE_OF_CONDUCT.md
|
53
82
|
- docs/LICENSE.txt
|
54
83
|
- k_config.gemspec
|
55
84
|
- lib/k_config.rb
|
85
|
+
- lib/k_config/configuration.rb
|
56
86
|
- lib/k_config/version.rb
|
57
87
|
- package-lock.json
|
58
88
|
- package.json
|