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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5baec6d3e93cb78128a09ddf0448b50b291c72d41002f161f0adbfcda8f0471d
4
- data.tar.gz: 98b529930e526149c73a85080acb0b2b008db88d02e8a75f9720db195721e835
3
+ metadata.gz: 6c77b3cfa7c43568ea7791ab092681b4849013a52736c6a86b58520dfc65ebbd
4
+ data.tar.gz: 05fa38afe44718cf69416dbc3dc54d188c5089e82f9ebfa7bdfca38171dc14a6
5
5
  SHA512:
6
- metadata.gz: 83b4657ecdfe488d740ab0494f391cbc8c9436339f0c794790da0e7f376c0a1383d80f9a20768977ca3a70eaa7edf2b3089a3605b148f2a28e5af0c6e14d7554
7
- data.tar.gz: 321702e528aa873f3bb7953c72b8b805b75b497dfac2b7aa7060fb914c48f35f528367e5b4b538946db91bd61dd8cda5d5dd467bab5f28e8fb2f5f28afdf6607
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` option is also accepted on `group`:
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
  }
@@ -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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SmartConfig
4
- VERSION = '0.2.0'
4
+ VERSION = '0.3.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_config
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Damien MATHIEU