Module: Docscribe::CLI::ConfigBuilder
- Defined in:
- lib/docscribe/cli/config_builder.rb
Overview
Build and override effective config from CLI flags.
Class Method Summary collapse
-
.apply_file_filters(raw, options) ⇒ void
Merge CLI file include/exclude patterns into the raw config hash.
-
.apply_filter_overrides(raw, options) ⇒ void
Apply method and file filter overrides to the raw config.
-
.apply_method_filters(raw, options) ⇒ void
Merge CLI method include/exclude patterns into the raw config hash.
-
.apply_output_overrides(raw, options) ⇒ void
Apply output-related CLI overrides to the raw config.
-
.apply_rbs_collection(raw) ⇒ void
Resolve and apply the RBS collection path into the raw config hash.
-
.apply_rbs_overrides(raw, options) ⇒ void
Apply RBS-related CLI overrides to the raw config.
-
.apply_sorbet_overrides(raw, options) ⇒ void
Apply Sorbet-related CLI overrides to the raw config.
-
.apply_validation_overrides(raw, options) ⇒ void
Apply validation-related CLI overrides to the raw config.
-
.build(base, options) ⇒ Docscribe::Config
Build an effective config by applying CLI overrides on top of a base config.
-
.filter_overrides?(options) ⇒ Boolean
Whether any method or file filter CLI options were provided.
-
.needs_override?(options) ⇒ Boolean
Whether any CLI override is present.
-
.output_overrides?(options) ⇒ Boolean
Whether any output-related CLI options were provided.
-
.rbs_overrides?(options) ⇒ Boolean
Whether any RBS-related CLI options were provided.
-
.sorbet_overrides?(options) ⇒ Boolean
Whether any Sorbet-related CLI options were provided.
-
.validation_overrides?(options) ⇒ Boolean
Whether any validation-related CLI options were provided.
-
.warn_and_return_base(base, options) ⇒ Docscribe::Config
Warn about a missing collection opt-in and return the base config unchanged.
-
.warn_missing_rbs_collection(conf, options) ⇒ void
Warn when rbs_collection.lock.yaml exists but --rbs-collection was not passed.
Class Method Details
.apply_file_filters(raw, options) ⇒ void
module_function: defines #apply_file_filters (visibility: private)
This method returns an undefined value.
Merge CLI file include/exclude patterns into the raw config hash.
116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/docscribe/cli/config_builder.rb', line 116 def apply_file_filters(raw, ) files = raw['filter']['files'] if files.nil? files = {} #: Hash[String, untyped] raw['filter']['files'] = files end files['include'] = Array(files['include']) + [:include_file] files['exclude'] = Array(files['exclude']) + [:exclude_file] files end |
.apply_filter_overrides(raw, options) ⇒ void
module_function: defines #apply_filter_overrides (visibility: private)
This method returns an undefined value.
Apply method and file filter overrides to the raw config.
82 83 84 85 |
# File 'lib/docscribe/cli/config_builder.rb', line 82 def apply_filter_overrides(raw, ) apply_method_filters(raw, ) apply_file_filters(raw, ) end |
.apply_method_filters(raw, options) ⇒ void
module_function: defines #apply_method_filters (visibility: private)
This method returns an undefined value.
Merge CLI method include/exclude patterns into the raw config hash.
104 105 106 107 108 |
# File 'lib/docscribe/cli/config_builder.rb', line 104 def apply_method_filters(raw, ) raw['filter'] ||= {} raw['filter']['include'] = Array(raw['filter']['include']) + [:include] raw['filter']['exclude'] = Array(raw['filter']['exclude']) + [:exclude] end |
.apply_output_overrides(raw, options) ⇒ void
module_function: defines #apply_output_overrides (visibility: private)
This method returns an undefined value.
Apply output-related CLI overrides to the raw config.
Currently handles:
204 205 206 207 208 209 210 211 |
# File 'lib/docscribe/cli/config_builder.rb', line 204 def apply_output_overrides(raw, ) return unless [:keep_descriptions] || [:no_boilerplate] raw['keep_descriptions'] = true if [:keep_descriptions] raw['emit'] ||= {} raw['emit']['include_default_message'] = false if [:no_boilerplate] raw['emit']['include_param_documentation'] = false if [:no_boilerplate] end |
.apply_rbs_collection(raw) ⇒ void
module_function: defines #apply_rbs_collection (visibility: private)
This method returns an undefined value.
Resolve and apply the RBS collection path into the raw config hash.
159 160 161 162 163 164 165 166 167 168 |
# File 'lib/docscribe/cli/config_builder.rb', line 159 def apply_rbs_collection(raw) require 'docscribe/types/rbs/collection_loader' collection_path = Docscribe::Types::RBS::CollectionLoader.resolve if collection_path raw['rbs']['collection_dirs'] = Array(raw['rbs']['collection_dirs']) + [collection_path] else warn 'Docscribe: rbs_collection.lock.yaml not found. ' \ 'Run `bundle exec rbs collection install` first.' end end |
.apply_rbs_overrides(raw, options) ⇒ void
module_function: defines #apply_rbs_overrides (visibility: private)
This method returns an undefined value.
Apply RBS-related CLI overrides to the raw config.
134 135 136 137 138 139 140 141 142 |
# File 'lib/docscribe/cli/config_builder.rb', line 134 def apply_rbs_overrides(raw, ) raw['rbs'] ||= {} raw['rbs']['enabled'] = true raw['rbs']['sig_dirs'] = Array(raw['rbs']['sig_dirs']) + [:sig_dirs] if [:sig_dirs].any? return unless [:rbs_collection] apply_rbs_collection(raw) end |
.apply_sorbet_overrides(raw, options) ⇒ void
module_function: defines #apply_sorbet_overrides (visibility: private)
This method returns an undefined value.
Apply Sorbet-related CLI overrides to the raw config.
176 177 178 179 180 181 182 |
# File 'lib/docscribe/cli/config_builder.rb', line 176 def apply_sorbet_overrides(raw, ) raw['sorbet'] ||= {} raw['sorbet']['enabled'] = true return unless [:rbi_dirs].any? raw['sorbet']['rbi_dirs'] = Array(raw['sorbet']['rbi_dirs']) + [:rbi_dirs] end |
.apply_validation_overrides(raw, options) ⇒ void
module_function: defines #apply_validation_overrides (visibility: private)
This method returns an undefined value.
Apply validation-related CLI overrides to the raw config.
228 229 230 |
# File 'lib/docscribe/cli/config_builder.rb', line 228 def apply_validation_overrides(raw, ) raw['validate_types'] = [:validate_types] end |
.build(base, options) ⇒ Docscribe::Config
module_function: defines #build (visibility: private)
Build an effective config by applying CLI overrides on top of a base config.
CLI overrides currently affect:
- method/file include and exclude filters
- RBS enablement and additional signature directories
- Sorbet enablement and RBI directories
If no relevant CLI override is present, the original config is returned unchanged.
24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/docscribe/cli/config_builder.rb', line 24 def build(base, ) return warn_and_return_base(base, ) unless needs_override?() raw = Marshal.load(Marshal.dump(base.raw)) apply_filter_overrides(raw, ) apply_rbs_overrides(raw, ) if rbs_overrides?() apply_sorbet_overrides(raw, ) if sorbet_overrides?() apply_output_overrides(raw, ) apply_validation_overrides(raw, ) if validation_overrides?() conf = Docscribe::Config.new(config_path: base.config_path, **raw) warn_missing_rbs_collection(conf, ) conf end |
.filter_overrides?(options) ⇒ Boolean
module_function: defines #filter_overrides? (visibility: private)
Whether any method or file filter CLI options were provided.
69 70 71 72 73 74 |
# File 'lib/docscribe/cli/config_builder.rb', line 69 def filter_overrides?() [:include].any? || [:exclude].any? || [:include_file].any? || [:exclude_file].any? end |
.needs_override?(options) ⇒ Boolean
module_function: defines #needs_override? (visibility: private)
Whether any CLI override is present.
43 44 45 46 47 48 49 |
# File 'lib/docscribe/cli/config_builder.rb', line 43 def needs_override?() filter_overrides?() || rbs_overrides?() || sorbet_overrides?() || output_overrides?() || validation_overrides?() end |
.output_overrides?(options) ⇒ Boolean
module_function: defines #output_overrides? (visibility: private)
Whether any output-related CLI options were provided.
189 190 191 |
# File 'lib/docscribe/cli/config_builder.rb', line 189 def output_overrides?() !![:keep_descriptions] || !![:no_boilerplate] end |
.rbs_overrides?(options) ⇒ Boolean
module_function: defines #rbs_overrides? (visibility: private)
Whether any RBS-related CLI options were provided.
92 93 94 95 96 |
# File 'lib/docscribe/cli/config_builder.rb', line 92 def rbs_overrides?() [:rbs] || [:rbs_collection] || [:sig_dirs].any? end |
.sorbet_overrides?(options) ⇒ Boolean
module_function: defines #sorbet_overrides? (visibility: private)
Whether any Sorbet-related CLI options were provided.
149 150 151 152 |
# File 'lib/docscribe/cli/config_builder.rb', line 149 def sorbet_overrides?() [:sorbet] || [:rbi_dirs].any? end |
.validation_overrides?(options) ⇒ Boolean
module_function: defines #validation_overrides? (visibility: private)
Whether any validation-related CLI options were provided.
218 219 220 |
# File 'lib/docscribe/cli/config_builder.rb', line 218 def validation_overrides?() ![:validate_types].nil? end |
.warn_and_return_base(base, options) ⇒ Docscribe::Config
module_function: defines #warn_and_return_base (visibility: private)
Warn about a missing collection opt-in and return the base config unchanged.
Used when no CLI override is present so the nudge still fires on plain runs.
59 60 61 62 |
# File 'lib/docscribe/cli/config_builder.rb', line 59 def warn_and_return_base(base, ) warn_missing_rbs_collection(base, ) base end |
.warn_missing_rbs_collection(conf, options) ⇒ void
module_function: defines #warn_missing_rbs_collection (visibility: private)
This method returns an undefined value.
Warn when rbs_collection.lock.yaml exists but --rbs-collection was not passed.
The warning can be suppressed by setting rbs.warn_missing_collection: false
in the project's docscribe.yml.
241 242 243 244 245 246 247 248 249 250 |
# File 'lib/docscribe/cli/config_builder.rb', line 241 def warn_missing_rbs_collection(conf, ) return if [:rbs_collection] return if conf.raw.dig('rbs', 'collection') return unless conf.rbs_warn_missing_collection? return unless File.exist?('rbs_collection.lock.yaml') warn 'Docscribe: rbs_collection.lock.yaml found but --rbs-collection not set. ' \ 'Pass --rbs-collection or set `rbs.collection: true` in docscribe.yml to enable RBS collection. ' \ 'Set `rbs.warn_missing_collection: false` to suppress this warning.' end |