Class: TRMNLP::Commands::Pull

Inherits:
Base
  • Object
show all
Defined in:
lib/trmnlp/commands/pull.rb

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from TRMNLP::Commands::Base

Instance Method Details

#callObject

Raises:



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/trmnlp/commands/pull.rb', line 9

def call
  context.validate!
  authenticate!

  plugin_settings_id = options.id || config.plugin.id
  raise Error, 'plugin ID must be specified' if plugin_settings_id.nil?

  unless options.force
    answer = prompt("Local plugin files will be overwritten. Are you sure? (y/n) ").downcase
    raise Error, 'aborting' unless answer == 'y' || answer == 'yes'
  end

  api = APIClient.new(config)
  tempfile = api.get_plugin_setting_archive(plugin_settings_id)
  size = 0

  begin
    Zip::File.open(tempfile.path) do |zip_file|
      zip_file.each do |entry|
        dest_path = paths.src_dir.join(entry.name)
        dest_path.dirname.mkpath
        zip_file.extract(entry, dest_path) { true } # overwrite existing
      end
    end

    size = File.size(tempfile.path)
  ensure
    tempfile.close
  end

  puts "Downloaded plugin (#{size} bytes)"
end