lib/doggy/cli/pull.rb in doggy-0.2.2 vs lib/doggy/cli/pull.rb in doggy-2.0.0
- old
+ new
@@ -1,21 +1,29 @@
module Doggy
class CLI::Pull
- attr_reader :options, :ids
-
- def initialize(options, ids)
+ def initialize(options)
@options = options
- @ids = ids
end
def run
- begin
- Doggy::Dash.download(ids)
- Doggy::Monitor.download(ids)
- Doggy::Screen.download(ids)
- rescue DoggyError
- puts "Pull failed."
- exit 1
- end
+ pull_resources('dashboards', Models::Dashboard) if should_pull?('dashboards')
+ pull_resources('monitors', Models::Monitor) if should_pull?('monitors')
+ pull_resources('screens', Models::Screen) if should_pull?('screens')
end
+
+ private
+
+ def should_pull?(resource)
+ @options.empty? || @options[resource]
+ end
+
+ def pull_resources(name, klass)
+ Doggy.ui.say "Pulling #{ name }"
+ local_resources = klass.all_local
+ remote_resources = klass.all
+
+ klass.assign_paths(remote_resources, local_resources)
+ remote_resources.each(&:save_local)
+ end
end
end
+