Class: Kennel::Syncer
- Inherits:
-
Object
- Object
- Kennel::Syncer
- Defined in:
- lib/kennel/syncer.rb
Constant Summary collapse
- CACHE_FILE =
keep in sync with .travis.yml caching
"tmp/cache/details"
Instance Method Summary collapse
- #confirm ⇒ Object
-
#initialize(api, expected) ⇒ Syncer
constructor
A new instance of Syncer.
- #plan ⇒ Object
- #update ⇒ Object
Constructor Details
#initialize(api, expected) ⇒ Syncer
Returns a new instance of Syncer.
6 7 8 9 10 11 |
# File 'lib/kennel/syncer.rb', line 6 def initialize(api, expected) @api = api @expected = expected @expected.each { |e| add_tracking_id e } calculate_diff end |
Instance Method Details
#confirm ⇒ Object
24 25 26 |
# File 'lib/kennel/syncer.rb', line 24 def confirm !STDIN.tty? || Utils.ask("Execute Plan ?") unless noop? end |
#plan ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/kennel/syncer.rb', line 13 def plan puts "Plan:" if noop? puts Utils.color(:green, "Nothing to do.") else print_plan "Create", @create, :green print_plan "Update", @update, :yellow print_plan "Delete", @delete, :red end end |
#update ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/kennel/syncer.rb', line 28 def update @create.each do |_, e| reply = @api.create e.class.api_resource, e.as_json puts "Created #{e.class.api_resource} #{tracking_id(e.as_json)} #{e.url(reply.fetch(:id))}" end @update.each do |id, e| @api.update e.class.api_resource, id, e.as_json puts "Updated #{e.class.api_resource} #{tracking_id(e.as_json)} #{e.url(id)}" end @delete.each do |id, _, a| @api.delete a.fetch(:api_resource), id puts "Deleted #{a.fetch(:api_resource)} #{tracking_id(a)} #{id}" end end |