class RailsEnvironment
Attributes
root[R]
Public Class Methods
default()
click to toggle source
# File lib/commands/plugin/rails_environment.rb, line 17 def self.default @default ||= find end
default=(rails_env)
click to toggle source
# File lib/commands/plugin/rails_environment.rb, line 21 def self.default=(rails_env) @default = rails_env end
find(dir=nil)
click to toggle source
# File lib/commands/plugin/rails_environment.rb, line 9 def self.find(dir=nil) dir ||= pwd while dir.length > 1 return new(dir) if File.exist?(File.join(dir, 'config', 'environment.rb')) dir = File.dirname(dir) end end
new(dir)
click to toggle source
# File lib/commands/plugin/rails_environment.rb, line 5 def initialize(dir) @root = dir end
Public Instance Methods
add_plugin_to_svn(plugin_name)
click to toggle source
# File lib/commands/plugin/rails_environment.rb, line 87 def add_plugin_to_svn(plugin_name) system("svn add #{root}/vendor/plugins/#{plugin_name}") end
best_install_method?()
click to toggle source
# File lib/commands/plugin/rails_environment.rb, line 59 def best_install_method? return :http unless use_svn? case when use_externals? then :externals when use_checkout? then :checkout else :export end end
externals()
click to toggle source
# File lib/commands/plugin/rails_environment.rb, line 68 def externals return [] unless use_externals? ext = %x`svn propget svn:externals "#{root}/vendor/plugins"` ext.reject{ |line| line.strip == '' }.map do |line| line.strip.split(/\s+/, 2) end end
externals=(items)
click to toggle source
# File lib/commands/plugin/rails_environment.rb, line 76 def externals=(items) unless items.is_a? String items = items.map{|name,uri| "#{name.ljust(29)} #{uri.chomp('/')}"}.join("\n") end Tempfile.open("svn-set-prop") do |file| file.write(items) file.flush system("svn propset -q svn:externals -F \"#{file.path}\" \"#{root}/vendor/plugins\"") end end
install(name_uri_or_plugin)
click to toggle source
# File lib/commands/plugin/rails_environment.rb, line 25 def install(name_uri_or_plugin) if name_uri_or_plugin.is_a? String if name_uri_or_plugin =~ /:\/\// plugin = Plugin.new(name_uri_or_plugin) else plugin = Plugins[name_uri_or_plugin] end else plugin = name_uri_or_plugin end unless plugin.nil? plugin.install else puts "plugin not found: #{name_uri_or_plugin}" end end
use_checkout?()
click to toggle source
# File lib/commands/plugin/rails_environment.rb, line 52 def use_checkout? # this is a bit of a guess. we assume that if the rails environment # is under subversion then they probably want the plugin checked out # instead of exported. This can be overridden on the command line File.directory?("#{root}/.svn") end
use_externals?()
click to toggle source
# File lib/commands/plugin/rails_environment.rb, line 48 def use_externals? use_svn? && File.directory?("#{root}/vendor/plugins/.svn") end
use_svn?()
click to toggle source
# File lib/commands/plugin/rails_environment.rb, line 42 def use_svn? require 'active_support/core_ext/kernel' silence_stderr {%x`svn --version` rescue nil} !$?.nil? && $?.success? end