Class: Kettle::Dev::ReleaseGraphContract
- Inherits:
-
Object
- Object
- Kettle::Dev::ReleaseGraphContract
- Defined in:
- lib/kettle/dev/release_graph_contract.rb
Overview
Parsed contract supplied by kettle-family for a single release target. Direct kettle-release calls receive the safe registry-only default.
Constant Summary collapse
- ENV_KEY =
"KETTLE_RELEASE_GRAPH_CONTRACT_JSON"- NAMES =
%w[registry_only wave_transition monorepo_ci_local branch_terminal].freeze
Instance Attribute Summary collapse
-
#ci_root ⇒ Object
readonly
Returns the value of attribute ci_root.
-
#local_path_roots ⇒ Object
readonly
Returns the value of attribute local_path_roots.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#selector_env ⇒ Object
readonly
Returns the value of attribute selector_env.
Class Method Summary collapse
Instance Method Summary collapse
- #allowed_path?(path) ⇒ Boolean
-
#initialize(name:, root:, ci_root:, local_path_roots: [], selector_env: {}) ⇒ ReleaseGraphContract
constructor
A new instance of ReleaseGraphContract.
- #local_paths? ⇒ Boolean
- #normalization_environment ⇒ Object
- #registry_only? ⇒ Boolean
Constructor Details
#initialize(name:, root:, ci_root:, local_path_roots: [], selector_env: {}) ⇒ ReleaseGraphContract
Returns a new instance of ReleaseGraphContract.
31 32 33 34 35 36 37 38 39 |
# File 'lib/kettle/dev/release_graph_contract.rb', line 31 def initialize(name:, root:, ci_root:, local_path_roots: [], selector_env: {}) @name = String(name) @root = File.realpath(root) @ci_root = canonical_path(ci_root) @local_path_roots = Array(local_path_roots).map { |path| canonical_path(path) }.uniq.freeze @selector_env = selector_env.to_h.map { |key, value| [String(key), String(value)] }.to_h.freeze validate! freeze end |
Instance Attribute Details
#ci_root ⇒ Object (readonly)
Returns the value of attribute ci_root.
13 14 15 |
# File 'lib/kettle/dev/release_graph_contract.rb', line 13 def ci_root @ci_root end |
#local_path_roots ⇒ Object (readonly)
Returns the value of attribute local_path_roots.
13 14 15 |
# File 'lib/kettle/dev/release_graph_contract.rb', line 13 def local_path_roots @local_path_roots end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
13 14 15 |
# File 'lib/kettle/dev/release_graph_contract.rb', line 13 def name @name end |
#selector_env ⇒ Object (readonly)
Returns the value of attribute selector_env.
13 14 15 |
# File 'lib/kettle/dev/release_graph_contract.rb', line 13 def selector_env @selector_env end |
Class Method Details
.from_environment(root:) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/kettle/dev/release_graph_contract.rb', line 15 def self.from_environment(root:) raw = (ENV[ENV_KEY] || "").strip return new(name: "registry_only", root: root, ci_root: root) if raw.empty? data = JSON.parse(raw) new( name: data["name"], ci_root: data["ci_root"] || root, local_path_roots: data["local_path_roots"] || [], selector_env: data["selector_env"] || {}, root: root ) rescue JSON::ParserError, KeyError, TypeError => error raise Error, "invalid #{ENV_KEY}: #{error.}" end |
Instance Method Details
#allowed_path?(path) ⇒ Boolean
49 50 51 52 |
# File 'lib/kettle/dev/release_graph_contract.rb', line 49 def allowed_path?(path) candidate = canonical_path(path) local_path_roots.any? { |root| path_within_root?(candidate, root) } end |
#local_paths? ⇒ Boolean
41 42 43 |
# File 'lib/kettle/dev/release_graph_contract.rb', line 41 def local_paths? !local_path_roots.empty? end |
#normalization_environment ⇒ Object
54 55 56 |
# File 'lib/kettle/dev/release_graph_contract.rb', line 54 def normalization_environment selector_env end |
#registry_only? ⇒ Boolean
45 46 47 |
# File 'lib/kettle/dev/release_graph_contract.rb', line 45 def registry_only? name == "registry_only" || name == "branch_terminal" end |