Class: Jax::Generators::Plugin::PluginManager

Inherits:
Thor
  • Object
show all
Includes:
Interactions, Jax::Generators::Plugin, Thor::Actions
Defined in:
lib/jax/generators/plugin/plugin_manager.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Interactions

#menu, #menu_choice, #overwrite, #prompt_yn, #say_option

Methods included from Jax::Generators::Plugin

#each_plugin, #extract_hash_from_response, #find_plugin_list, #get_remote_plugins_matching, #installed_plugin_manifests, #installed_plugins, #load_or_infer_manifest, #matching_plugins, #plugin_version, #rest_resource, #search, #search_query_rx

Class Method Details

.basenameObject



247
248
249
# File 'lib/jax/generators/plugin/plugin_manager.rb', line 247

def basename
  "jax plugin"
end

.source_rootObject



137
138
139
# File 'lib/jax/generators/plugin/plugin_manager.rb', line 137

def self.source_root
  File.expand_path("templates", File.dirname(__FILE__))
end

Instance Method Details

#install(name, *other_names) ⇒ Object



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
# File 'lib/jax/generators/plugin/plugin_manager.rb', line 22

def install(name, *other_names)
  catch(:complete) do
    message = catch(:aborted) do
      list = matching_plugins(name)
      if list.empty?
        raise "No plugin names match or begin with the text '#{name}'."
      elsif list.length == 1
        if list[0]['name'] != name
          prompt_yn "Plugin '#{name}' was not found, but '#{list[0]['name']}' was. Install it instead?"
        end
        install_plugin list[0]
      else
        say "No plugin was found with the name '#{name}', but the following candidates were found:"
        menu list.collect { |c| c['name'] } do |selected_name, selected_index|
          install_plugin list[selected_index]
        end
      end
      throw :complete
    end
    say_status :aborted, message, :yellow
    return # cancel any additional plugins if this one was aborted
  end
  
  install *other_names unless other_names.empty?
end

#list(name = nil) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/jax/generators/plugin/plugin_manager.rb', line 114

def list(name = nil)
  if options[:local] && matching_plugins(name).empty?
    say_status :missing, "There do not seem to be any plugins installed for this application."
    return
  else
    each_plugin(name) do |plugin|
      name, description = plugin['name'], plugin['description']

      if options[:detailed]
        say name
        say "  #{description}"
        say ""
      else
        if description.length > 60
          description = description[0...57] + "..."
        end
        say "#{name.ljust 19} #{description}"
      end
    end
  end
  say ""
end

#pushObject



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/jax/generators/plugin/plugin_manager.rb', line 83

def push
  if ENV['JAX_CWD'] && ENV['JAX_CWD'] =~ /^#{Regexp::escape Jax.root.join("vendor/plugins").to_s}\/?([^\/]+)(\/|$)/
    plugin_name = $1
    plugin_dir = Jax.root.join("vendor/plugins", plugin_name)
    manifest = plugin_dir.join("manifest.yml").to_s
    if File.exist? manifest
      manifest = Jax::Plugin::Manifest.find(plugin_name)
      if manifest.description.blank?
        say "Please enter a plugin description in the manifest.yml file"
      else
        publish_plugin manifest
      end
    else
      say "Plugin manifest is missing!"
      say "A default manifest file will be written. Please modify "
      say "this file before continuing."
      say ""
      Jax::Plugin::Manifest.new(plugin_name).save
      say_status :created, "manifest.yml", :green
    end
  else
    say_status :aborted, "Please run this script from within a plugin directory.", :red
  end
end

#uninstall(name) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/jax/generators/plugin/plugin_manager.rb', line 50

def uninstall(name)
  catch :complete do
    message = catch :aborted do
      plugin_path = Jax.root.join("vendor/plugins/#{name}")
      if File.exist?(plugin_path.to_s)
        uninstall_plugin name, plugin_path
      else
        # see if it's a partial name
        matches = search installed_plugins, name
        throw :aborted, "Plugin '#{name}' does not seem to be installed." if matches.empty?

        if matches.length == 1 && match = matches.shift
          prompt_yn "Plugin '#{name}' is not installed, but '#{match[0]}' was. Delete it instead?"
          uninstall_plugin *match
        else
          say "Plugin '#{name}' is not installed, but the following partial matches are:"
          menu matches.keys.sort, :allow_all => true do |name,index|
            uninstall_plugin name, matches[name]
          end
        end
      end

      throw :complete
    end
    
    say_status :aborted, message, :yellow
  end
end