Class: Zencoder::CLI::Plugin

Inherits:
Object
  • Object
show all
Extended by:
Helpers
Defined in:
lib/zencoder-cli/plugin.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Helpers

ask, confirm, display, error, format_date, home_directory, running_on_a_mac?, running_on_windows?, truncate

Constructor Details

#initialize(uri) ⇒ Plugin

Returns a new instance of Plugin.



35
36
37
38
# File 'lib/zencoder-cli/plugin.rb', line 35

def initialize(uri)
  @uri = uri
  guess_name(uri)
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/zencoder-cli/plugin.rb', line 7

def name
  @name
end

#uriObject (readonly)

Returns the value of attribute uri.



7
8
9
# File 'lib/zencoder-cli/plugin.rb', line 7

def uri
  @uri
end

Class Method Details

.directoryObject



9
10
11
# File 'lib/zencoder-cli/plugin.rb', line 9

def self.directory
  File.expand_path("#{home_directory}/.zencoder/plugins")
end

.listObject



13
14
15
16
17
# File 'lib/zencoder-cli/plugin.rb', line 13

def self.list
  Dir["#{directory}/*"].sort.map do |folder|
    File.basename(folder)
  end
end

.load!Object



19
20
21
22
23
24
25
26
27
# File 'lib/zencoder-cli/plugin.rb', line 19

def self.load!
  list.each do |plugin|
    begin
      load_plugin(plugin)
    rescue Exception => e
      display "Unable to load plugin: #{plugin}: #{e.message}"
    end
  end
end

.load_plugin(plugin) ⇒ Object



29
30
31
32
33
# File 'lib/zencoder-cli/plugin.rb', line 29

def self.load_plugin(plugin)
  folder = "#{self.directory}/#{plugin}"
  $: << "#{folder}/lib"    if File.directory? "#{folder}/lib"
  load "#{folder}/init.rb" if File.exists?  "#{folder}/init.rb"
end

Instance Method Details

#installObject



48
49
50
51
52
53
54
55
56
57
58
# File 'lib/zencoder-cli/plugin.rb', line 48

def install
  FileUtils.mkdir_p(path)
  Dir.chdir(path) do
    system("git init -q")
    if !system("git pull #{uri} -q")
      FileUtils.rm_rf path
      return false
    end
  end
  true
end

#pathObject



44
45
46
# File 'lib/zencoder-cli/plugin.rb', line 44

def path
  "#{self.class.directory}/#{name}"
end

#to_sObject



40
41
42
# File 'lib/zencoder-cli/plugin.rb', line 40

def to_s
  name
end

#uninstallObject



60
61
62
# File 'lib/zencoder-cli/plugin.rb', line 60

def uninstall
  FileUtils.rm_r path if File.directory?(path)
end