Class: Plugin
- Inherits:
-
Object
- Object
- Plugin
- Defined in:
- lib/commands/plugin/plugin.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
-
#versions ⇒ Object
readonly
Returns the value of attribute versions.
Class Method Summary collapse
Instance Method Summary collapse
-
#about(force_refresh = false) ⇒ Object
Returns a hash representing this plugin’s metadata.
-
#initialize(uri, name = nil) ⇒ Plugin
constructor
A new instance of Plugin.
- #install(method = nil, options = {}) ⇒ Object
- #installed? ⇒ Boolean
- #svn_url? ⇒ Boolean
- #to_s ⇒ Object
- #uninstall ⇒ Object
Constructor Details
#initialize(uri, name = nil) ⇒ Plugin
Returns a new instance of Plugin.
6 7 8 9 10 |
# File 'lib/commands/plugin/plugin.rb', line 6 def initialize(uri, name=nil) @uri = normalise_uri(uri) name.nil? ? guess_name(uri) : @name = name check_for_versions end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/commands/plugin/plugin.rb', line 4 def name @name end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
4 5 6 |
# File 'lib/commands/plugin/plugin.rb', line 4 def uri @uri end |
#versions ⇒ Object (readonly)
Returns the value of attribute versions.
4 5 6 |
# File 'lib/commands/plugin/plugin.rb', line 4 def versions @versions end |
Class Method Details
.find(name) ⇒ Object
12 13 14 |
# File 'lib/commands/plugin/plugin.rb', line 12 def self.find(name) name =~ /\// ? new(name) : Repositories.instance.find_plugin(name) end |
Instance Method Details
#about(force_refresh = false) ⇒ Object
Returns a hash representing this plugin’s metadata
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/commands/plugin/plugin.rb', line 61 def about(force_refresh=false) # Look in cache first unless force_refresh if Repositories.instance.source_cache['plugins'].has_key?(name) return Repositories.instance.source_cache['plugins'][name] end end # Get from original source tmp = "#{rails_env.root}/_tmp_about.yml" if svn_url? cmd = %(svn export #{@uri}/about.yml "#{tmp}") puts cmd if $verbose system(cmd) end about_uri = svn_url? ? tmp : File.join(@uri, 'about.yml') open(about_uri) do |stream| about_hash = YAML.load(stream.read) unless about_hash.is_a?(Hash) && !about_hash['plugin'].nil? raise("#{name}'s about.yml wasn't valid YAML") end return about_hash end rescue # Make yaml on the fly for this plugin. # The 'plugin' field (uri to the resource) is the only required field. { 'plugin' => uri } ensure FileUtils.rm_rf tmp if svn_url? end |
#install(method = nil, options = {}) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/commands/plugin/plugin.rb', line 29 def install(method=nil, = {}) = {:version => "bleeding_edge"}.merge() method ||= rails_env.best_install_method? method = :export if method == :http and svn_url? uninstall if installed? and [:force] unless installed? send("install_using_#{method}", ) run_install_hook else puts "already installed: #{name} (#{uri}). pass --force to reinstall" end end |
#installed? ⇒ Boolean
24 25 26 27 |
# File 'lib/commands/plugin/plugin.rb', line 24 def installed? File.directory?("#{rails_env.root}/vendor/plugins/#{name}") \ or rails_env.externals.detect{ |name, repo| self.uri == repo } end |
#svn_url? ⇒ Boolean
20 21 22 |
# File 'lib/commands/plugin/plugin.rb', line 20 def svn_url? @uri =~ /svn(?:\+ssh)?:\/\/*/ end |
#to_s ⇒ Object
16 17 18 |
# File 'lib/commands/plugin/plugin.rb', line 16 def to_s "#{@name.ljust(30)}#{@uri}" end |
#uninstall ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/commands/plugin/plugin.rb', line 45 def uninstall path = "#{rails_env.root}/vendor/plugins/#{name}" if File.directory?(path) puts "Removing 'vendor/plugins/#{name}'" if $verbose run_uninstall_hook rm_r path else puts "Plugin doesn't exist: #{path}" end # clean up svn:externals externals = rails_env.externals externals.reject!{|n,u| name == n or name == u} rails_env.externals = externals end |