Class: Jax::PluginManager

Inherits:
Thor
  • Object
show all
Includes:
Generators::Actions, Generators::PluginBase, Util::Tar, Thor::Actions
Defined in:
lib/jax/commands/plugin_manager.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Generators::Actions

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

Methods included from Generators::PluginBase

#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

Methods included from Util::Tar

#gzip, #tar, #ungzip, #untar

Class Method Details

.basenameObject



235
236
237
# File 'lib/jax/commands/plugin_manager.rb', line 235

def basename
  "jax plugin"
end

.source_rootObject



134
135
136
# File 'lib/jax/commands/plugin_manager.rb', line 134

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

Instance Method Details

#install(name, *other_names) ⇒ Object



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
# File 'lib/jax/commands/plugin_manager.rb', line 19

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



111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
# File 'lib/jax/commands/plugin_manager.rb', line 111

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



80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/jax/commands/plugin_manager.rb', line 80

def push
  if destination_root =~ /^#{Regexp::escape ::Rails.application.root.join("vendor/plugins").to_s}\/?([^\/]+)(\/|$)/
    plugin_name = $1
    plugin_dir = ::Rails.application.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



47
48
49
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
# File 'lib/jax/commands/plugin_manager.rb', line 47

def uninstall(name)
  catch :complete do
    message = catch :aborted do
      plugin_path = ::Rails.application.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