Sha256: f410e9c12611229e4da36e69bb18df67638c3d8439d87219b8e26a335c2e2cb7

Contents?: true

Size: 1.26 KB

Versions: 4

Compression:

Stored size: 1.26 KB

Contents

# encoding: utf-8

module Doggy
  class CLI::Push
    WARNING_MESSAGE = "You are about to force push all the objects. "\
      "This will override changes in Datadog if they have not been synced to the dog repository. "\
      "Do you want to proceed? (Y/N)"

    def sync_changes
      changed_resources = Doggy::Model.changed_resources
      Doggy.ui.say "Syncing #{changed_resources.size} objects to Datadog..."
      changed_resources.each do |resource|
        if resource.is_deleted
          Doggy.ui.say "Deleting #{resource.path}, with id = #{resource.id}"
          resp = resource.destroy
          Doggy.ui.say "Response: #{resp.inspect}"
        else
          Doggy.ui.say "Saving #{resource.path}, with id = #{resource.id}"
          resource.ensure_read_only!
          resource.save
        end
      end
      Doggy::Model.emit_shipit_deployment
    end

    def push_all(ids)
      if ids.empty? && !Doggy.ui.yes?(WARNING_MESSAGE)
        Doggy.ui.say('Operation cancelled')
        return
      end
      Doggy::Model.all_local_resources.each do |resource|
        next if ids.any? && !ids.include?(resource.id.to_s)
        Doggy.ui.say "Pushing #{resource.path}, with id #{resource.id}"
        resource.ensure_read_only!
        resource.save
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
doggy-2.0.42 lib/doggy/cli/push.rb
doggy-2.0.41 lib/doggy/cli/push.rb
doggy-2.0.40 lib/doggy/cli/push.rb
doggy-2.0.39 lib/doggy/cli/push.rb