Class: Doggy::CLI::Push

Inherits:
Object
  • Object
show all
Defined in:
lib/doggy/cli/push.rb

Constant Summary collapse

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)"

Instance Method Summary collapse

Instance Method Details

#push_all(ids) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/doggy/cli/push.rb', line 26

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

#sync_changesObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/doggy/cli/push.rb', line 9

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