complex_config 0.22.2 → 0.23.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.
@@ -1,5 +1,29 @@
1
1
  module ComplexConfig
2
+ # A tree class that provides hierarchical representation of configuration
3
+ # data
4
+ #
5
+ # The Tree class is used to create visual tree structures from configuration
6
+ # data, allowing for easy display and understanding of nested configuration
7
+ # settings. It supports both UTF-8 and ASCII character sets for rendering
8
+ # tree connections and can handle various data types including Settings
9
+ # objects, hashes, arrays, and primitive values.
10
+ #
11
+ # @see ComplexConfig::Settings
12
+ # @see ComplexConfig::Tree#to_s
13
+ # @see ComplexConfig::Tree#to_a
2
14
  class Tree
15
+ # The convert method transforms configuration data into a tree structure
16
+ #
17
+ # This method recursively processes configuration values and converts them
18
+ # into a hierarchical tree representation. It handles different value types
19
+ # including ComplexConfig::Settings objects, Hashes, Arrays, and primitive
20
+ # values, creating appropriate tree nodes for each case.
21
+ #
22
+ # @param name [Object] The name or key to use for the tree node
23
+ # @param value [Object] The configuration value to convert, which can be a
24
+ # ComplexConfig::Settings object, Hash, Array, or primitive value
25
+ # @return [ComplexConfig::Tree] A tree object representing the hierarchical
26
+ # structure of the configuration data
3
27
  def self.convert(name, value)
4
28
  case value
5
29
  when ComplexConfig::Settings
@@ -25,18 +49,42 @@ module ComplexConfig
25
49
  end
26
50
  end
27
51
 
52
+ # The initialize method sets up a new tree node with the specified name and
53
+ # UTF-8 support configuration.
54
+ #
55
+ # @param name [Object] The name or key to use for the tree node
56
+ # @param utf8 [Boolean] Whether to use UTF-8 characters for tree rendering,
57
+ # defaults to the result of default_utf8
28
58
  def initialize(name, utf8: default_utf8)
29
59
  @name = name
30
60
  @utf8 = utf8
31
61
  @children = []
32
62
  end
33
63
 
64
+ # The default_utf8 method determines whether UTF-8 character support should
65
+ # be enabled
66
+ #
67
+ # This method checks the LANG environment variable to determine if UTF-8
68
+ # encoding should be used for tree rendering.
69
+ #
70
+ # @return [TrueClass, FalseClass] true if the LANG environment variable indicates
71
+ # UTF-8 encoding, false otherwise
34
72
  def default_utf8
35
73
  !!(ENV['LANG'] =~ /utf-8\z/i)
36
74
  end
37
75
 
38
76
  private
39
77
 
78
+ # The inner_child_prefix method determines the appropriate prefix string
79
+ # for tree child nodes
80
+ #
81
+ # This method returns a Unicode or ASCII character sequence used to
82
+ # visually represent the connection between parent and child nodes in a
83
+ # tree structure, depending on whether UTF-8 characters are enabled and
84
+ # whether the current node is the first child
85
+ #
86
+ # @param i [Integer] the index of the child node in relation to its siblings
87
+ # @return [String] the prefix string for the child node visualization
40
88
  def inner_child_prefix(i)
41
89
  if @utf8
42
90
  i.zero? ? "├─ " : "│ "
@@ -45,6 +93,11 @@ module ComplexConfig
45
93
  end
46
94
  end
47
95
 
96
+ # The last_child_prefix method determines the appropriate prefix string for
97
+ # tree child nodes
98
+ #
99
+ # @param i [Integer] the index of the child node in relation to its siblings
100
+ # @return [String] the prefix string for the last child node visualization
48
101
  def last_child_prefix(i)
49
102
  if @utf8
50
103
  i.zero? ? "└─ " : " "
@@ -55,6 +108,16 @@ module ComplexConfig
55
108
 
56
109
  public
57
110
 
111
+ # The to_enum method creates an enumerator for tree traversal
112
+ #
113
+ # This method generates an Enumerator that yields string representations of
114
+ # the tree structure, including node names and their hierarchical
115
+ # relationships. It processes children recursively and applies appropriate
116
+ # prefix characters based on UTF-8 support and child position to visually
117
+ # represent the tree structure.
118
+ #
119
+ # @return [Enumerator] An enumerator that yields formatted tree node strings
120
+ # in a hierarchical format with proper indentation and connection characters
58
121
  def to_enum
59
122
  Enumerator.new do |y|
60
123
  y.yield @name
@@ -74,20 +137,50 @@ module ComplexConfig
74
137
  end
75
138
  end
76
139
 
140
+ # The << method appends a child node to the tree structure
141
+ #
142
+ # @param child [ComplexConfig::Tree] the child tree node to add to this
143
+ # node's children
144
+ # @return [self] returns self to allow for method chaining after adding the
145
+ # child node
77
146
  def <<(child)
78
147
  @children << child
79
148
  end
80
149
 
150
+ # The to_ary method converts the tree structure to an array representation
151
+ #
152
+ # This method generates an array containing string representations of all
153
+ # nodes in the tree structure, including their hierarchical relationships
154
+ # and proper indentation with connection characters. It delegates to the
155
+ # to_enum method to produce the underlying enumeration before converting it
156
+ # to an array.
157
+ #
158
+ # @return [Array<String>] an array of formatted strings representing the tree
159
+ # structure with proper indentation and visual connections between parent
160
+ # and child nodes
81
161
  def to_ary
82
162
  to_enum.to_a
83
163
  end
84
164
 
165
+ # Alias for {to_ary}
166
+ #
167
+ # @see to_ary
85
168
  alias to_a to_ary
86
169
 
170
+ # The to_str method converts the tree structure to a string representation
171
+ #
172
+ # This method generates a string by joining all node representations in the
173
+ # tree with newline characters, providing a flat text representation of the
174
+ # hierarchical structure.
175
+ #
176
+ # @return [String] a newline-separated string containing all tree node representations
87
177
  def to_str
88
178
  to_ary * ?\n
89
179
  end
90
180
 
181
+ # Alias for {to_str}
182
+ #
183
+ # @see to_str
91
184
  alias to_s to_str
92
185
  end
93
186
  end
@@ -1,6 +1,6 @@
1
1
  module ComplexConfig
2
2
  # ComplexConfig version
3
- VERSION = '0.22.2'
3
+ VERSION = '0.23.0'
4
4
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc:
@@ -1,5 +1,18 @@
1
1
  require 'tins'
2
2
 
3
+ # Main namespace module for the ComplexConfig library
4
+ #
5
+ # This module serves as the root namespace for all components of the
6
+ # ComplexConfig system, providing configuration management, encryption
7
+ # capabilities, and structured access to YAML-based configuration data with
8
+ # support for environment-specific settings and plugin-based attribute
9
+ # resolution.
10
+ #
11
+ # @see ComplexConfig::Config
12
+ # @see ComplexConfig::Provider
13
+ # @see ComplexConfig::Settings
14
+ # @see ComplexConfig::Encryption
15
+ # @see ComplexConfig::KeySource
3
16
  module ComplexConfig
4
17
  end
5
18
 
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- RSpec.describe ComplexConfig::Config do
3
+ describe ComplexConfig::Config do
4
4
  let :plugin_code do
5
5
  -> id { skip }
6
6
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- RSpec.describe ComplexConfig::Encryption do
3
+ describe ComplexConfig::Encryption do
4
4
  let :secret do
5
5
  "\x1A8\x9E\xA8\xC2\x7F@@6\xB2W\a\x9A)\xCDw"
6
6
  end
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- RSpec.describe ComplexConfig::KeySource do
3
+ describe ComplexConfig::KeySource do
4
4
  it 'should provide key from pathname' do
5
5
  ks = described_class.new(pathname: asset('with-key-file.yml'))
6
6
  expect(ks.key).to eq '90ec1139596f9dfdb51e72277735ce9a'
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'complex_config/plugins/enable'
3
3
 
4
- RSpec.describe ComplexConfig::Plugins do
4
+ describe ComplexConfig::Plugins do
5
5
  let :provider do
6
6
  ComplexConfig::Provider
7
7
  end
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'fileutils'
3
3
 
4
- RSpec.describe ComplexConfig::Provider do
4
+ describe ComplexConfig::Provider do
5
5
  reset_new_config = -> * {
6
6
  described_class.config_dir = Pathname.new(__FILE__).dirname.dirname + 'config'
7
7
  described_class.key = nil
@@ -1,6 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
- RSpec.describe ComplexConfig::Settings do
3
+ describe ComplexConfig::Settings do
4
4
  before do
5
5
  # Disable all plugins for this spec b/c they interfere with how rspec works
6
6
  allow(ComplexConfig::Provider.instance).to receive(:plugins).and_return([])
@@ -1,7 +1,7 @@
1
1
  require 'spec_helper'
2
2
  require 'complex_config/shortcuts'
3
3
 
4
- RSpec.describe 'shortcuts' do
4
+ describe 'shortcuts' do
5
5
  let :provider do
6
6
  ComplexConfig::Provider
7
7
  end
data/spec/spec_helper.rb CHANGED
@@ -1,8 +1,7 @@
1
- if ENV['START_SIMPLECOV'].to_i == 1
2
- require 'simplecov'
3
- SimpleCov.start do
4
- add_filter "#{File.basename(File.dirname(__FILE__))}/"
5
- end
1
+ begin
2
+ require 'gem_hadar/simplecov'
3
+ GemHadar::SimpleCov.start
4
+ rescue LoadError
6
5
  end
7
6
  require 'rspec'
8
7
  begin
metadata CHANGED
@@ -1,14 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: complex_config
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.22.2
4
+ version: 0.23.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2024-10-21 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: gem_hadar
@@ -16,14 +15,14 @@ dependencies:
16
15
  requirements:
17
16
  - - "~>"
18
17
  - !ruby/object:Gem::Version
19
- version: '1.19'
18
+ version: '2.6'
20
19
  type: :development
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
23
  - - "~>"
25
24
  - !ruby/object:Gem::Version
26
- version: '1.19'
25
+ version: '2.6'
27
26
  - !ruby/object:Gem::Dependency
28
27
  name: rake
29
28
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +93,34 @@ dependencies:
94
93
  - - ">="
95
94
  - !ruby/object:Gem::Version
96
95
  version: '0'
96
+ - !ruby/object:Gem::Dependency
97
+ name: all_images
98
+ requirement: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '0.8'
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '0.8'
110
+ - !ruby/object:Gem::Dependency
111
+ name: context_spook
112
+ requirement: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '0.4'
117
+ type: :development
118
+ prerelease: false
119
+ version_requirements: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '0.4'
97
124
  - !ruby/object:Gem::Dependency
98
125
  name: json
99
126
  requirement: !ruby/object:Gem::Requirement
@@ -112,36 +139,30 @@ dependencies:
112
139
  name: tins
113
140
  requirement: !ruby/object:Gem::Requirement
114
141
  requirements:
115
- - - ">="
142
+ - - "~>"
116
143
  - !ruby/object:Gem::Version
117
- version: '0'
144
+ version: '1'
118
145
  type: :runtime
119
146
  prerelease: false
120
147
  version_requirements: !ruby/object:Gem::Requirement
121
148
  requirements:
122
- - - ">="
149
+ - - "~>"
123
150
  - !ruby/object:Gem::Version
124
- version: '0'
151
+ version: '1'
125
152
  - !ruby/object:Gem::Dependency
126
153
  name: mize
127
154
  requirement: !ruby/object:Gem::Requirement
128
155
  requirements:
129
156
  - - "~>"
130
157
  - !ruby/object:Gem::Version
131
- version: '0.3'
132
- - - ">="
133
- - !ruby/object:Gem::Version
134
- version: 0.3.4
158
+ version: '0.6'
135
159
  type: :runtime
136
160
  prerelease: false
137
161
  version_requirements: !ruby/object:Gem::Requirement
138
162
  requirements:
139
163
  - - "~>"
140
164
  - !ruby/object:Gem::Version
141
- version: '0.3'
142
- - - ">="
143
- - !ruby/object:Gem::Version
144
- version: 0.3.4
165
+ version: '0.6'
145
166
  - !ruby/object:Gem::Dependency
146
167
  name: base64
147
168
  requirement: !ruby/object:Gem::Requirement
@@ -182,7 +203,6 @@ extra_rdoc_files:
182
203
  - lib/complex_config/tree.rb
183
204
  - lib/complex_config/version.rb
184
205
  files:
185
- - ".all_images.yml"
186
206
  - CHANGES.md
187
207
  - Gemfile
188
208
  - LICENSE
@@ -231,7 +251,6 @@ homepage: https://github.com/flori/complex_config
231
251
  licenses:
232
252
  - Apache-2.0
233
253
  metadata: {}
234
- post_install_message:
235
254
  rdoc_options:
236
255
  - "--title"
237
256
  - ComplexConfig -- configuration library
@@ -250,8 +269,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
250
269
  - !ruby/object:Gem::Version
251
270
  version: '0'
252
271
  requirements: []
253
- rubygems_version: 3.5.18
254
- signing_key:
272
+ rubygems_version: 3.6.9
255
273
  specification_version: 4
256
274
  summary: configuration library
257
275
  test_files:
data/.all_images.yml DELETED
@@ -1,16 +0,0 @@
1
- dockerfile: |-
2
- RUN apk add --no-cache build-base git
3
- RUN gem update --system
4
- RUN gem install gem_hadar bundler
5
- script: &script |-
6
- echo -e "\e[1m"
7
- ruby -v
8
- echo -e "\e[0m"
9
- bundle install --full-index
10
- rake spec
11
-
12
- images:
13
- ruby:3.3-alpine: *script
14
- ruby:3.2-alpine: *script
15
- ruby:3.1-alpine: *script
16
- ruby:3.0-alpine: *script