Class: TRMNLP::Commands::Pull
Defined Under Namespace
Classes: Options
Instance Method Summary collapse
Methods inherited from Base
#initialize, options_from, run
Constructor Details
This class inherits a constructor from TRMNLP::Commands::Base
Instance Method Details
#call ⇒ Object
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 41 42 43 44 45 46 47 48 |
# File 'lib/trmnlp/commands/pull.rb', line 13 def call context.validate! authenticate! plugin_settings_id = .id || config.plugin.id raise PluginIdRequired, 'plugin ID must be specified' if plugin_settings_id.nil? unless .force answer = prompt('Local plugin files will be overwritten. Are you sure? (y/n) ').downcase raise Aborted, 'aborting' unless %w[y yes].include?(answer) 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 # NOTE: delete-before-extract avoids EACCES on Linux when an # existing template-generated file is non-writable. # rubyzip's block-based overwrite confirmation does not chmod. dest_path.delete if dest_path.exist? zip_file.extract(entry, destination_directory: paths.src_dir) end end size = File.size(tempfile.path) ensure tempfile.close end reporter.info "Downloaded plugin (#{size} bytes)" end |