Module: Kettle::Dev::OpenCollectiveConfig
- Defined in:
- lib/kettle/dev/open_collective_config.rb
Overview
Shared utility for resolving Open Collective configuration for this repository.
Centralizes the logic for locating and reading .opencollective.yml and
for deriving the handle from environment or the YAML file.
Class Method Summary collapse
-
.handle(required: false, root: nil, strict: false) ⇒ String?
Determine the Open Collective handle.
-
.yaml_path(root = nil) ⇒ String
Absolute path to a .opencollective.yml.
Class Method Details
.handle(required: false, root: nil, strict: false) ⇒ String?
Determine the Open Collective handle.
Precedence:
1) ENV[“OPENCOLLECTIVE_HANDLE”] when set and non-empty
2) .opencollective.yml key “collective” (or :collective)
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/kettle/dev/open_collective_config.rb', line 29 def handle(required: false, root: nil, strict: false) env = ENV["OPENCOLLECTIVE_HANDLE"] return env unless env.nil? || env.to_s.strip.empty? ypath = yaml_path(root) if strict yml = YAML.safe_load(File.read(ypath)) if yml.is_a?(Hash) handle = yml["collective"] || yml[:collective] || yml["org"] || yml[:org] return handle.to_s unless handle.nil? || handle.to_s.strip.empty? end elsif File.file?(ypath) begin yml = YAML.safe_load(File.read(ypath)) if yml.is_a?(Hash) handle = yml["collective"] || yml[:collective] || yml["org"] || yml[:org] return handle.to_s unless handle.nil? || handle.to_s.strip.empty? end rescue StandardError => e Kettle::Dev.debug_error(e, __method__) if Kettle::Dev.respond_to?(:debug_error) # fall through to required check end end if required Kettle::Dev::ExitAdapter.abort("ERROR: Open Collective handle not provided. Set OPENCOLLECTIVE_HANDLE or add 'collective: <handle>' to .opencollective.yml.") end nil end |