Class: Textus::Maintenance::RuleLint
- Inherits:
-
Object
- Object
- Textus::Maintenance::RuleLint
- Defined in:
- lib/textus/maintenance/rule_lint.rb
Overview
Compare the live manifest’s ‘rules:` block against a candidate YAML string. Returns a Plan describing rule additions/removals/ changes. Does NOT write anything.
Instance Method Summary collapse
- #call(candidate_yaml:) ⇒ Object
-
#initialize(container:, call:) ⇒ RuleLint
constructor
A new instance of RuleLint.
Constructor Details
#initialize(container:, call:) ⇒ RuleLint
Returns a new instance of RuleLint.
9 10 11 12 13 |
# File 'lib/textus/maintenance/rule_lint.rb', line 9 def initialize(container:, call:) @container = container @call = call @root = container.root end |
Instance Method Details
#call(candidate_yaml:) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/textus/maintenance/rule_lint.rb', line 15 def call(candidate_yaml:) live_rules = current_rules candidate_rules = parse_candidate(candidate_yaml) live_by_match = live_rules.to_h { |r| [r["match"], r] } candidate_by_match = candidate_rules.to_h { |r| [r["match"], r] } steps = (candidate_by_match.keys - live_by_match.keys).map do |m| { "op" => "add_rule", "match" => m, "rule" => candidate_by_match[m] } end (live_by_match.keys - candidate_by_match.keys).each do |m| steps << { "op" => "remove_rule", "match" => m } end (live_by_match.keys & candidate_by_match.keys).each do |m| next if live_by_match[m] == candidate_by_match[m] steps << { "op" => "change_rule", "match" => m, "from" => live_by_match[m], "to" => candidate_by_match[m] } end Plan.new(steps: steps, warnings: []) end |