complex_config 0.22.3 → 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.3'
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
 
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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: complex_config
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.22.3
4
+ version: 0.23.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Frank
@@ -15,14 +15,14 @@ dependencies:
15
15
  requirements:
16
16
  - - "~>"
17
17
  - !ruby/object:Gem::Version
18
- version: '2.4'
18
+ version: '2.6'
19
19
  type: :development
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - "~>"
24
24
  - !ruby/object:Gem::Version
25
- version: '2.4'
25
+ version: '2.6'
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: rake
28
28
  requirement: !ruby/object:Gem::Requirement
@@ -107,6 +107,20 @@ dependencies:
107
107
  - - "~>"
108
108
  - !ruby/object:Gem::Version
109
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'
110
124
  - !ruby/object:Gem::Dependency
111
125
  name: json
112
126
  requirement: !ruby/object:Gem::Requirement