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_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.
-
.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.
-
.rbs_overrides?(options) ⇒ Boolean
Whether any RBS-related CLI options were provided.
-
.sorbet_overrides?(options) ⇒ Boolean
Whether any Sorbet-related CLI options were provided.
Class Method Details
.apply_file_filters(raw, options) ⇒ void
module_function: when included, also defines #apply_file_filters (instance visibility: private)
This method returns an undefined value.
Merge CLI file include/exclude patterns into the raw config hash.
109 110 111 112 113 |
# File 'lib/docscribe/cli/config_builder.rb', line 109 def apply_file_filters(raw, ) files = raw['filter']['files'] ||= {} #: Hash[String, untyped] files['include'] = Array(files['include']) + [:include_file] files['exclude'] = Array(files['exclude']) + [:exclude_file] end |
.apply_filter_overrides(raw, options) ⇒ void
module_function: when included, also defines # (instance visibility: private)
This method returns an undefined value.
Apply method and file filter overrides to the raw config.
86 87 88 89 |
# File 'lib/docscribe/cli/config_builder.rb', line 86 def apply_filter_overrides(raw, ) apply_method_filters(raw, ) apply_file_filters(raw, ) end |
.apply_method_filters(raw, options) ⇒ void
module_function: when included, also defines #apply_method_filters (instance visibility: private)
This method returns an undefined value.
Merge CLI method include/exclude patterns into the raw config hash.
97 98 99 100 101 |
# File 'lib/docscribe/cli/config_builder.rb', line 97 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_rbs_collection(raw) ⇒ void
module_function: when included, also defines #apply_rbs_collection (instance visibility: private)
This method returns an undefined value.
Resolve and apply the RBS collection path into the raw config hash.
137 138 139 140 141 142 143 144 145 146 |
# File 'lib/docscribe/cli/config_builder.rb', line 137 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 or collection not installed. ' \ 'Run `bundle exec rbs collection install` first.' end end |
.apply_rbs_overrides(raw, options) ⇒ void
module_function: when included, also defines # (instance visibility: private)
This method returns an undefined value.
Apply RBS-related CLI overrides to the raw config.
122 123 124 125 126 127 128 129 130 |
# File 'lib/docscribe/cli/config_builder.rb', line 122 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: when included, also defines # (instance visibility: private)
This method returns an undefined value.
Apply Sorbet-related CLI overrides to the raw config.
155 156 157 158 159 160 161 |
# File 'lib/docscribe/cli/config_builder.rb', line 155 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 |
.build(base, options) ⇒ Docscribe::Config
module_function: when included, also defines #build (instance 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 |
# File 'lib/docscribe/cli/config_builder.rb', line 24 def build(base, ) return base unless needs_override?() raw = Marshal.load(Marshal.dump(base.raw)) apply_filter_overrides(raw, ) apply_rbs_overrides(raw, ) if [:rbs] || [:rbs_collection] || [:sig_dirs].any? apply_sorbet_overrides(raw, ) if [:sorbet] || [:rbi_dirs].any? Docscribe::Config.new(raw) end |
.filter_overrides?(options) ⇒ Boolean
module_function: when included, also defines #filter_overrides? (instance visibility: private)
Whether any method or file filter CLI options were provided.
51 52 53 54 55 56 |
# File 'lib/docscribe/cli/config_builder.rb', line 51 def filter_overrides?() [:include].any? || [:exclude].any? || [:include_file].any? || [:exclude_file].any? end |
.needs_override?(options) ⇒ Boolean
module_function: when included, also defines # (instance visibility: private)
Whether any CLI override is present.
40 41 42 43 44 |
# File 'lib/docscribe/cli/config_builder.rb', line 40 def needs_override?() filter_overrides?() || rbs_overrides?() || sorbet_overrides?() end |
.rbs_overrides?(options) ⇒ Boolean
module_function: when included, also defines #rbs_overrides? (instance visibility: private)
Whether any RBS-related CLI options were provided.
63 64 65 66 67 |
# File 'lib/docscribe/cli/config_builder.rb', line 63 def rbs_overrides?() [:rbs] || [:rbs_collection] || [:sig_dirs].any? end |
.sorbet_overrides?(options) ⇒ Boolean
module_function: when included, also defines #sorbet_overrides? (instance visibility: private)
Whether any Sorbet-related CLI options were provided.
74 75 76 77 |
# File 'lib/docscribe/cli/config_builder.rb', line 74 def sorbet_overrides?() [:sorbet] || [:rbi_dirs].any? end |