Sha256: 63977491d88d4e21c111d906fed6cbdfd1a9807b68adb76f326f8d083ba377bc

Contents?: true

Size: 975 Bytes

Versions: 1

Compression:

Stored size: 975 Bytes

Contents

# encoding: utf-8

module Doggy
  class CLI::Pull
    def initialize(ids:, options:)
      @ids = ids
      @options = options
    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')
    end

  private

    def should_pull?(resource)
      @options.empty? || @options[resource]
    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)
      remote_resources.each(&:save_local)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
doggy-2.0.11 lib/doggy/cli/pull.rb