Sha256: a65c8f33f446ee6285a50b18901088576ea9ad61fd079ca3a8465a4624a2f8a1

Contents?: true

Size: 1.16 KB

Versions: 3

Compression:

Stored size: 1.16 KB

Contents

# encoding: utf-8

module Doggy
  class CLI::Pull
    def initialize(ids:, options:)
      @ids = ids
      @options = options
      @updated_by_last_action = false
    end

    def run
      pull_resources('dashboards', Models::Dashboard, @ids) if should_pull?('dashboards')
      pull_resources('monitors',   Models::Monitor, @ids)   if should_pull?('monitors')
      pull_resources('screens',    Models::Screen, @ids)    if should_pull?('screens')

      Doggy.ui.say "Nothing to pull: please specify object ID or use '-a' to pull everything" unless @updated_by_last_action
    end

  private

    def should_pull?(resource)
      !@options.empty? || @options[resource] || @ids.any?
    end

    def pull_resources(name, klass, ids)
      if ids.any?
        Doggy.ui.say "Pulling #{ name }: #{ids.join(', ')}"
        remote_resources = klass.all.find_all { |m| ids.include?(m.id.to_s) }
      else
        Doggy.ui.say "Pulling #{ name }"
        remote_resources = klass.all
      end
      local_resources  = klass.all_local
      klass.assign_paths(remote_resources, local_resources)
      @updated_by_last_action = true
      remote_resources.each(&:save_local)
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
doggy-2.0.15 lib/doggy/cli/pull.rb
doggy-2.0.14 lib/doggy/cli/pull.rb
doggy-2.0.12 lib/doggy/cli/pull.rb