Class: Doggy::CLI::Pull

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

Instance Method Summary collapse

Constructor Details

#initialize(options, ids) ⇒ Pull

Returns a new instance of Pull.



8
9
10
11
# File 'lib/doggy/cli/pull.rb', line 8

def initialize(options, ids)
  @options = options
  @ids = ids
end

Instance Method Details

#runObject



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/doggy/cli/pull.rb', line 13

def run
  @local_resources = Doggy::Model.all_local_resources
  if @ids.empty?
    Parallel.each(@local_resources) do |local_resource|
      if remote_resource = local_resource.class.find(local_resource.id)
        remote_resource.path = local_resource.path
        remote_resource.save_local
      else
        local_resource.destroy_local
      end
    end
  else
    @ids.each { |id| pull_by_id(id.to_i) }
  end
end