Class: Siba::InstalledPlugins

Inherits:
Object
  • Object
show all
Extended by:
FilePlug
Defined in:
lib/siba/plugins/installed_plugins.rb

Constant Summary collapse

GEM_PREFIX =
"siba-"

Class Method Summary collapse

Methods included from FilePlug

siba_file, siba_file, siba_file=

Class Method Details

.all_installedObject



16
17
18
# File 'lib/siba/plugins/installed_plugins.rb', line 16

def all_installed
  @installed ||= find_installed
end

.category_dir(category) ⇒ Object



37
38
39
# File 'lib/siba/plugins/installed_plugins.rb', line 37

def category_dir(category)
  File.expand_path "../#{category}/",  __FILE__
end

.gem_name(category, type) ⇒ Object



45
46
47
# File 'lib/siba/plugins/installed_plugins.rb', line 45

def gem_name(category, type)
  "#{GEM_PREFIX}#{category}-#{type}"
end

.install_gem_message(category, type) ⇒ Object



53
54
55
# File 'lib/siba/plugins/installed_plugins.rb', line 53

def install_gem_message(category, type)
  "'#{type}' plugin is not installed.\nRun 'gem install #{gem_name(category, type)}' to install it and try again."
end

.installed?(category, type) ⇒ Boolean

Returns:

  • (Boolean)


10
11
12
13
14
# File 'lib/siba/plugins/installed_plugins.rb', line 10

def installed?(category, type)
  types = all_installed[category]
  return false if types.nil?
  types.include? type
end

.plugin_category_and_type(category, type) ⇒ Object



49
50
51
# File 'lib/siba/plugins/installed_plugins.rb', line 49

def plugin_category_and_type(category, type)
  "#{category}#{type.nil? ? "" : '-' + type}"
end

.plugin_path(category, type) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/siba/plugins/installed_plugins.rb', line 20

def plugin_path(category, type)
  unless installed? category, type
    raise Siba::Error, "Plugin #{plugin_category_and_type(category, type)} is not installed"
  end
  siba_file.run_this do
    path = type_dir category, type
    unless siba_file.file_directory? path
      path = Siba::GemHelper.gem_path gem_name(category, type)
      path = File.join path, "lib", gem_name(category, type)
    end
    unless siba_file.file_directory? path
      raise Siba::Error, "Failed to get path to plugin #{plugin_category_and_type(category, type)}"
    end
    path
  end
end

.type_dir(category, type) ⇒ Object



41
42
43
# File 'lib/siba/plugins/installed_plugins.rb', line 41

def type_dir(category, type)
  File.join category_dir(category), type
end