Class: Coherent::Plugin
- Inherits:
-
Object
- Object
- Coherent::Plugin
- Defined in:
- lib/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.
Class Method Summary collapse
Instance Method Summary collapse
- #git_url? ⇒ Boolean
- #info ⇒ Object
-
#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 |
# File 'lib/plugin/plugin.rb', line 6 def initialize(uri, name=nil) @uri = uri guess_name(uri) end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
4 5 6 |
# File 'lib/plugin/plugin.rb', line 4 def name @name end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
4 5 6 |
# File 'lib/plugin/plugin.rb', line 4 def uri @uri end |
Class Method Details
.find(name) ⇒ Object
11 12 13 |
# File 'lib/plugin/plugin.rb', line 11 def self.find(name) name =~ /\// ? new(name) : Repositories.instance.find_plugin(name) end |
Instance Method Details
#git_url? ⇒ Boolean
23 24 25 |
# File 'lib/plugin/plugin.rb', line 23 def git_url? @uri =~ /^git:\/\// || @uri =~ /\.git$/ end |
#info ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/plugin/plugin.rb', line 64 def info tmp = "#{project_env.root}/_tmp_about.yml" if svn_url? cmd = "svn export #{@uri} \"#{project_env.root}/#{tmp}\"" puts cmd if $verbose system(cmd) end open(svn_url? ? tmp : File.join(@uri, 'about.yml')) do |stream| stream.read end rescue "No about.yml found in #{uri}" ensure FileUtils.rm_rf tmp if svn_url? end |
#install(method = nil, options = {}) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/plugin/plugin.rb', line 32 def install(method=nil, = {}) method ||= project_env.best_install_method? if :http == method method = :export if svn_url? method = :git if git_url? end 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
27 28 29 30 |
# File 'lib/plugin/plugin.rb', line 27 def installed? File.directory?("#{project_env.root}/vendor/plugins/#{name}") \ or project_env.externals.detect{ |name, repo| self.uri == repo } end |
#svn_url? ⇒ Boolean
19 20 21 |
# File 'lib/plugin/plugin.rb', line 19 def svn_url? @uri =~ /svn(?:\+ssh)?:\/\/*/ end |
#to_s ⇒ Object
15 16 17 |
# File 'lib/plugin/plugin.rb', line 15 def to_s "#{@name.ljust(30)}#{@uri}" end |
#uninstall ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/plugin/plugin.rb', line 49 def uninstall path = "#{project_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 = project_env.externals externals.reject!{|n,u| name == n or name == u} project_env.externals = externals end |