smart_config 0.2.0 → 0.3.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.
- checksums.yaml +4 -4
- data/README.md +13 -10
- data/lib/smart_config/markdown.rb +6 -3
- data/lib/smart_config/values.rb +4 -0
- data/lib/smart_config/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 6c77b3cfa7c43568ea7791ab092681b4849013a52736c6a86b58520dfc65ebbd
|
|
4
|
+
data.tar.gz: 05fa38afe44718cf69416dbc3dc54d188c5089e82f9ebfa7bdfca38171dc14a6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 80126e552dd05d1837b65d5cedecef13dddb21239222e913a256719264fcf9495019d78b617d76ca994598af5ff94d14f8ed017ffa0cd60bbb34d40747cf46ab
|
|
7
|
+
data.tar.gz: 63d1884eac87f5f04f898fb0fc317fda3bd95423390a0604587c91ee63208de275b027061ececdad3be79994ede65456b7c87dba4206a671613e1cc6b4f9662e
|
data/README.md
CHANGED
|
@@ -85,19 +85,22 @@ All available options are:
|
|
|
85
85
|
| default | Sets a default value for the field, if no configuration could be found. If this option is not set, getting an unset field will raise an exception. |
|
|
86
86
|
| format | Sets the format of the field. If this option is not set, the field will be formatted as string. |
|
|
87
87
|
| description | A free-form text description of the field. Optional. Used for documentation generation. |
|
|
88
|
+
| example | A free-form example value for the field. Optional. Used for documentation generation. |
|
|
89
|
+
| no_docs | When set to `true`, excludes the field from documentation generation. |
|
|
88
90
|
|
|
89
|
-
The `description`
|
|
91
|
+
The `description`, `example`, and `no_docs` options are also accepted on `group`. When `no_docs: true` is set on a group, the entire group and all its nested values are excluded from documentation.
|
|
90
92
|
|
|
91
93
|
```ruby
|
|
92
94
|
group :smtp, description: 'SMTP server settings' do
|
|
93
|
-
value :hostname, description: 'The SMTP server hostname'
|
|
94
|
-
value :port, format: :integer, description: 'The SMTP server port'
|
|
95
|
+
value :hostname, description: 'The SMTP server hostname', example: 'smtp.example.com'
|
|
96
|
+
value :port, format: :integer, description: 'The SMTP server port', example: '587'
|
|
97
|
+
value :password, no_docs: true
|
|
95
98
|
end
|
|
96
99
|
```
|
|
97
100
|
|
|
98
101
|
#### Generating Documentation
|
|
99
102
|
|
|
100
|
-
`SmartConfig::Markdown` renders a Markdown table documenting all values in a config module, including their descriptions, defaults, and formats:
|
|
103
|
+
`SmartConfig::Markdown` renders a Markdown table documenting all values in a config module, including their descriptions, examples, defaults, and formats:
|
|
101
104
|
|
|
102
105
|
```ruby
|
|
103
106
|
puts SmartConfig::Markdown.new(Config).render
|
|
@@ -106,11 +109,11 @@ puts SmartConfig::Markdown.new(Config).render
|
|
|
106
109
|
Output:
|
|
107
110
|
|
|
108
111
|
```
|
|
109
|
-
| Key | Description | Default | Format |
|
|
110
|
-
|
|
111
|
-
| app_name | | My App | string |
|
|
112
|
-
| smtp.hostname | The SMTP server hostname | | string |
|
|
113
|
-
| smtp.port | The SMTP server port | | integer |
|
|
112
|
+
| Key | Description | Example | Default | Format |
|
|
113
|
+
|----------------|--------------------------|------------------|---------|---------|
|
|
114
|
+
| app_name | | | My App | string |
|
|
115
|
+
| smtp.hostname | The SMTP server hostname | smtp.example.com | | string |
|
|
116
|
+
| smtp.port | The SMTP server port | 587 | | integer |
|
|
114
117
|
```
|
|
115
118
|
|
|
116
|
-
Values from nested groups are listed with their full dotted key path. Groups themselves are not rendered as rows.
|
|
119
|
+
Values from nested groups are listed with their full dotted key path. Groups themselves are not rendered as rows. Values and groups with `no_docs: true` are omitted entirely.
|
|
@@ -14,10 +14,10 @@ module SmartConfig
|
|
|
14
14
|
return '' if rows.empty?
|
|
15
15
|
|
|
16
16
|
lines = []
|
|
17
|
-
lines << '| Key | Description | Default | Format |'
|
|
18
|
-
lines << '
|
|
17
|
+
lines << '| Key | Description | Example | Default | Format |'
|
|
18
|
+
lines << '|-----|-------------|---------|---------|--------|'
|
|
19
19
|
rows.each do |row|
|
|
20
|
-
cells = [row[:path], row[:description], row[:default], row[:format]]
|
|
20
|
+
cells = [row[:path], row[:description], row[:example], row[:default], row[:format]]
|
|
21
21
|
lines << "| #{cells.map { |c| escape(c) }.join(' | ')} |"
|
|
22
22
|
end
|
|
23
23
|
lines.join("\n")
|
|
@@ -32,6 +32,8 @@ module SmartConfig
|
|
|
32
32
|
def collect_entries(config, prefix)
|
|
33
33
|
raw = config.instance_variable_get(:@config) || {}
|
|
34
34
|
raw.flat_map do |key, entry|
|
|
35
|
+
next [] if entry[:no_docs]
|
|
36
|
+
|
|
35
37
|
next_prefix = prefix + [key.to_s]
|
|
36
38
|
if entry.key?(:group)
|
|
37
39
|
collect_entries(entry[:group], next_prefix)
|
|
@@ -45,6 +47,7 @@ module SmartConfig
|
|
|
45
47
|
{
|
|
46
48
|
path: prefix.join('.'),
|
|
47
49
|
description: entry.fetch(:description, ''),
|
|
50
|
+
example: entry.fetch(:example, ''),
|
|
48
51
|
default: entry.key?(:default) ? entry[:default].to_s : '',
|
|
49
52
|
format: entry[:format].to_s
|
|
50
53
|
}
|
data/lib/smart_config/values.rb
CHANGED
|
@@ -37,6 +37,10 @@ module SmartConfig
|
|
|
37
37
|
(@config || {})[name.to_sym]&.fetch(:description, '') || ''
|
|
38
38
|
end
|
|
39
39
|
|
|
40
|
+
def example_for(name)
|
|
41
|
+
(@config || {})[name.to_sym]&.fetch(:example, '') || ''
|
|
42
|
+
end
|
|
43
|
+
|
|
40
44
|
def get_value(name)
|
|
41
45
|
return @config[name][:group] if @config[name].key?(:group)
|
|
42
46
|
|
data/lib/smart_config/version.rb
CHANGED