Class: Textus::Action::RuleLint
- Extended by:
- Contract::DSL
- Defined in:
- lib/textus/action/rule_lint.rb
Constant Summary collapse
- BURN =
:sync
Instance Method Summary collapse
- #call(container:) ⇒ Object
-
#initialize(candidate_yaml:) ⇒ RuleLint
constructor
A new instance of RuleLint.
Methods included from Contract::DSL
arg, around, cli, cli_stdin, contract, contract?, summary, surfaces, verb, view
Methods inherited from Base
Constructor Details
#initialize(candidate_yaml:) ⇒ RuleLint
Returns a new instance of RuleLint.
20 21 22 23 |
# File 'lib/textus/action/rule_lint.rb', line 20 def initialize(candidate_yaml:) super() @candidate_yaml = candidate_yaml end |
Instance Method Details
#call(container:) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/textus/action/rule_lint.rb', line 25 def call(container:, **) root = container.root live_rules = current_rules(root) candidate_rules = parse_candidate(@candidate_yaml) live_by_match = live_rules.to_h { |rule| [rule["match"], rule] } candidate_by_match = candidate_rules.to_h { |rule| [rule["match"], rule] } steps = (candidate_by_match.keys - live_by_match.keys).map do |match| { "op" => "add_rule", "match" => match, "rule" => candidate_by_match[match] } end (live_by_match.keys - candidate_by_match.keys).each do |match| steps << { "op" => "remove_rule", "match" => match } end (live_by_match.keys & candidate_by_match.keys).each do |match| next if live_by_match[match] == candidate_by_match[match] steps << { "op" => "change_rule", "match" => match, "from" => live_by_match[match], "to" => candidate_by_match[match], } end Textus::Background::Plan.new(steps: steps, warnings: []) end |