Class: Plugin

Inherits:
Object show all
Defined in:
railties/lib/rails/commands/plugin.rb

Instance Attribute Summary (collapse)

Class Method Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Plugin) initialize(uri, name = nil)

Returns a new instance of Plugin



118
119
120
121
# File 'railties/lib/rails/commands/plugin.rb', line 118

def initialize(uri, name = nil)
  @uri = uri
  guess_name(uri)
end

Instance Attribute Details

- (Object) name (readonly)

Returns the value of attribute name



116
117
118
# File 'railties/lib/rails/commands/plugin.rb', line 116

def name
  @name
end

- (Object) uri (readonly)

Returns the value of attribute uri



116
117
118
# File 'railties/lib/rails/commands/plugin.rb', line 116

def uri
  @uri
end

Class Method Details

+ (Object) find(name)



123
124
125
# File 'railties/lib/rails/commands/plugin.rb', line 123

def self.find(name)
  new(name)
end

Instance Method Details

- (Boolean) git_url?

Returns:

  • (Boolean)


135
136
137
# File 'railties/lib/rails/commands/plugin.rb', line 135

def git_url?
  @uri =~ /^git:\/\// || @uri =~ /\.git$/
end

- (Object) info



179
180
181
182
183
184
185
186
187
188
189
190
191
# File 'railties/lib/rails/commands/plugin.rb', line 179

def info
  tmp = "#{rails_env.root}/_tmp_about.yml"
  if svn_url?
    cmd = "svn export #{@uri} \"#{rails_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

- (Object) install(method = nil, options = {})



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'railties/lib/rails/commands/plugin.rb', line 144

def install(method=nil, options = {})
  method ||= rails_env.best_install_method?
  if :http == method
    method = :export if svn_url?
    method = :git    if git_url?
  end

  uninstall if installed? and options[:force]

  unless installed?
    send("install_using_#{method}", options)
    run_install_hook
  else
    puts "already installed: #{name} (#{uri}).  pass --force to reinstall"
  end
end

- (Boolean) installed?

Returns:

  • (Boolean)


139
140
141
142
# File 'railties/lib/rails/commands/plugin.rb', line 139

def installed?
  File.directory?("#{rails_env.root}/vendor/plugins/#{name}") \
    or rails_env.externals.detect{ |name, repo| self.uri == repo }
end

- (Boolean) svn_url?

Returns:

  • (Boolean)


131
132
133
# File 'railties/lib/rails/commands/plugin.rb', line 131

def svn_url?
  @uri =~ /svn(?:\+ssh)?:\/\/*/
end

- (Object) to_s



127
128
129
# File 'railties/lib/rails/commands/plugin.rb', line 127

def to_s
  "#{@name.ljust(30)}#{@uri}"
end

- (Object) uninstall



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'railties/lib/rails/commands/plugin.rb', line 161

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

  if rails_env.use_externals?
    # clean up svn:externals
    externals = rails_env.externals
    externals.reject!{|n, u| name == n or name == u}
    rails_env.externals = externals
  end
end