Class: Coherent::Environment
- Inherits:
-
Object
- Object
- Coherent::Environment
- Defined in:
- lib/plugin/environment.rb
Instance Attribute Summary collapse
-
#root ⇒ Object
readonly
Returns the value of attribute root.
Class Method Summary collapse
Instance Method Summary collapse
- #best_install_method ⇒ Object
- #externals ⇒ Object
- #externals=(items) ⇒ Object
-
#initialize(dir) ⇒ Environment
constructor
A new instance of Environment.
- #install(name_uri_or_plugin) ⇒ Object
- #use_checkout? ⇒ Boolean
- #use_externals? ⇒ Boolean
- #use_svn? ⇒ Boolean
Constructor Details
#initialize(dir) ⇒ Environment
Returns a new instance of Environment.
6 7 8 |
# File 'lib/plugin/environment.rb', line 6 def initialize(dir) @root = dir end |
Instance Attribute Details
#root ⇒ Object (readonly)
Returns the value of attribute root.
4 5 6 |
# File 'lib/plugin/environment.rb', line 4 def root @root end |
Class Method Details
.default ⇒ Object
21 22 23 |
# File 'lib/plugin/environment.rb', line 21 def self.default @default ||= find end |
.default=(env) ⇒ Object
25 26 27 |
# File 'lib/plugin/environment.rb', line 25 def self.default=(env) @default = env end |
.find(dir = nil) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/plugin/environment.rb', line 10 def self.find(dir=nil) dir ||= pwd while dir.length > 1 return new(dir) if File.exist?(File.join(dir, 'distil.yml')) dir = File.dirname(dir) end puts "Unable to find environment" exit 1 end |
Instance Method Details
#best_install_method ⇒ Object
63 64 65 66 67 68 69 70 |
# File 'lib/plugin/environment.rb', line 63 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 ⇒ Object
72 73 74 75 76 77 78 79 |
# File 'lib/plugin/environment.rb', line 72 def externals return [] unless use_externals? ext = `svn propget svn:externals "#{root}/vendor/plugins"` lines = ext.respond_to?(:lines) ? ext.lines : ext lines.reject{ |line| line.strip == '' }.map do |line| line.strip.split(/\s+/, 2) end end |
#externals=(items) ⇒ Object
81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/plugin/environment.rb', line 81 def externals=(items) return unless use_externals? 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) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/plugin/environment.rb', line 29 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? ⇒ Boolean
56 57 58 59 60 61 |
# File 'lib/plugin/environment.rb', line 56 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? ⇒ Boolean
52 53 54 |
# File 'lib/plugin/environment.rb', line 52 def use_externals? use_svn? && File.directory?("#{root}/vendor/plugins/.svn") end |
#use_svn? ⇒ Boolean
46 47 48 49 50 |
# File 'lib/plugin/environment.rb', line 46 def use_svn? require 'active_support/core_ext/kernel' silence_stderr {`svn --version` rescue nil} !$?.nil? && $?.success? end |