Class: Kennel::Syncer
- Inherits:
-
Object
- Object
- Kennel::Syncer
- Defined in:
- lib/kennel/syncer.rb
Defined Under Namespace
Constant Summary collapse
- DELETE_ORDER =
dashboards references monitors + slos, slos reference monitors
["dashboard", "slo", "monitor", "synthetics/tests"].freeze
- LINE_UP =
go up and clear
"\e[1A\033[K"
Instance Method Summary collapse
- #confirm ⇒ Object
-
#initialize(api, expected, actual, kennel:, project_filter: nil, tracking_id_filter: nil) ⇒ Syncer
constructor
A new instance of Syncer.
- #plan ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(api, expected, actual, kennel:, project_filter: nil, tracking_id_filter: nil) ⇒ Syncer
Returns a new instance of Syncer.
13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/kennel/syncer.rb', line 13 def initialize(api, expected, actual, kennel:, project_filter: nil, tracking_id_filter: nil) @api = api @kennel = kennel @project_filter = project_filter @tracking_id_filter = tracking_id_filter @expected = Set.new expected # need set to speed up deletion @actual = actual calculate_diff validate_plan prevent_irreversible_partial_updates end |
Instance Method Details
#confirm ⇒ Object
44 45 46 47 48 |
# File 'lib/kennel/syncer.rb', line 44 def confirm return false if noop? return true if ENV["CI"] || !STDIN.tty? || !Kennel.err.tty? Utils.ask("Execute Plan ?") end |
#plan ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/kennel/syncer.rb', line 25 def plan Kennel.out.puts "Plan:" if noop? Kennel.out.puts Utils.color(:green, "Nothing to do") else @warnings.each { || Kennel.out.puts Utils.color(:yellow, "Warning: #{message}") } print_plan "Create", @create, :green print_plan "Update", @update, :yellow print_plan "Delete", @delete, :red end Plan.new( changes: @create.map { |_id, e, _a| Change.new(:create, e.class.api_resource, e.tracking_id, nil) } + @update.map { |id, e, _a| Change.new(:update, e.class.api_resource, e.tracking_id, id) } + @delete.map { |id, _e, a| Change.new(:delete, a.fetch(:klass).api_resource, a.fetch(:tracking_id), id) } ) end |
#update ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/kennel/syncer.rb', line 50 def update changes = [] each_resolved @create do |_, e| = "#{e.class.api_resource} #{e.tracking_id}" Kennel.out.puts "Creating #{message}" reply = @api.create e.class.api_resource, e.as_json Utils. reply, e.class id = reply.fetch(:id) changes << Change.new(:create, e.class.api_resource, e.tracking_id, id) populate_id_map [], [reply] # allow resolving ids we could previously no resolve Kennel.out.puts "#{LINE_UP}Created #{message} #{e.class.url(id)}" end each_resolved @update do |id, e| = "#{e.class.api_resource} #{e.tracking_id} #{e.class.url(id)}" Kennel.out.puts "Updating #{message}" @api.update e.class.api_resource, id, e.as_json changes << Change.new(:update, e.class.api_resource, e.tracking_id, id) Kennel.out.puts "#{LINE_UP}Updated #{message}" end @delete.each do |id, _, a| klass = a.fetch(:klass) = "#{klass.api_resource} #{a.fetch(:tracking_id)} #{id}" Kennel.out.puts "Deleting #{message}" @api.delete klass.api_resource, id changes << Change.new(:delete, klass.api_resource, a.fetch(:tracking_id), id) Kennel.out.puts "#{LINE_UP}Deleted #{message}" end Plan.new(changes: changes) end |