Module: Spigoter::CLI::Update

Defined in:
lib/spigoter/cli/cli_update.rb

Overview

Module for updating plugins

Author:

Class Method Summary collapse

Class Method Details

.dependenciesObject



30
31
32
33
34
35
36
37
38
39
40
# File 'lib/spigoter/cli/cli_update.rb', line 30

def self.dependencies
  unless File.exist?('plugins.yml')
    Log.error "plugins.yml doesn't exists, please, create one (you can use spigoter init)"
    exit(1)
  end

  unless Dir.exist?('plugins')
    Log.error "plugins directory doesn't exists, please, create it"
    exit(1)
  end
end

.get_plugin(name, data) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/spigoter/cli/cli_update.rb', line 42

def self.get_plugin(name, data)
  Log.info "Updating plugin: #{name}"
  plugin_type = data[:type]

  if Spigoter::Plugin.list[plugin_type].nil?
    Log.error "Plugin type #{plugin_type} doesn't exists!"
    exit(1)
  end

  Spigoter::Plugin.list[plugin_type].new(data[:url])
rescue => e
  Log.error e.message
end

.main(opts = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/spigoter/cli/cli_update.rb', line 15

def self.main(opts = {})
  Log.info 'Updating!'
  dependencies
  plugins_data = Spigoter::Utils.get_plugins(opts)

  plugins_data.each do |name, data|
    objeto = get_plugin(name, data)
    next unless !objeto.nil? && (objeto.class < Spigoter::Plugin)

    File.open("plugins/#{name}.jar", 'w+b') do |f|
      f.write(objeto.file)
    end
  end
end

.updateObject



11
12
13
# File 'lib/spigoter/cli/cli_update.rb', line 11

def self.update
  ->(opts = {}) { main(opts) }
end