Class: Root
- Inherits:
-
Object
- Object
- Root
- Defined in:
- lib/sub/root.rb
Defined Under Namespace
Classes: Processes
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#root_path ⇒ Object
readonly
Returns the value of attribute root_path.
Instance Method Summary collapse
- #checkout_external(external) ⇒ Object
- #directories_containing_externals ⇒ Object
- #externals ⇒ Object
-
#initialize(root_path, app, clean = false) ⇒ Root
constructor
A new instance of Root.
- #remove_unversioned ⇒ Object
- #run(cmd, return_output = false) ⇒ Object
- #say(msg) ⇒ Object
- #status ⇒ Object
- #svn(cmd) ⇒ Object
- #update ⇒ Object
- #update_external(external) ⇒ Object
Constructor Details
#initialize(root_path, app, clean = false) ⇒ Root
Returns a new instance of Root.
4 5 6 7 8 9 |
# File 'lib/sub/root.rb', line 4 def initialize(root_path, app, clean = false) @root_path = root_path @app = app @clean = clean @status = nil end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
2 3 4 |
# File 'lib/sub/root.rb', line 2 def app @app end |
#root_path ⇒ Object (readonly)
Returns the value of attribute root_path.
2 3 4 |
# File 'lib/sub/root.rb', line 2 def root_path @root_path end |
Instance Method Details
#checkout_external(external) ⇒ Object
87 88 89 90 91 |
# File 'lib/sub/root.rb', line 87 def checkout_external(external) @processes.launch do external.checkout end end |
#directories_containing_externals ⇒ Object
116 117 118 119 120 121 122 123 124 |
# File 'lib/sub/root.rb', line 116 def directories_containing_externals status.externals.collect do |path| if (path !~ /\//) "." else path.gsub(/\/[^\/]*$/, '') end end.uniq end |
#externals ⇒ Object
108 109 110 111 112 113 114 |
# File 'lib/sub/root.rb', line 108 def externals exts = [] directories_containing_externals.collect do |parent| exts += External.externals_in_directory(parent, app) end exts end |
#remove_unversioned ⇒ Object
93 94 95 96 97 98 99 100 101 102 |
# File 'lib/sub/root.rb', line 93 def remove_unversioned status.unversioned.each do |path| if File.directory?(path) say "Removing unversioned directory #{path}" else say "Removing unversioned file #{path}" end FileUtils.rm_rf(path) end end |
#run(cmd, return_output = false) ⇒ Object
19 20 21 |
# File 'lib/sub/root.rb', line 19 def run(cmd, return_output = false) app.run(cmd, return_output) end |
#say(msg) ⇒ Object
11 12 13 |
# File 'lib/sub/root.rb', line 11 def say(msg) app.say(msg) end |
#status ⇒ Object
104 105 106 |
# File 'lib/sub/root.rb', line 104 def status @status ||= Status.new(run("svn st #{root_path}", true)) end |
#svn(cmd) ⇒ Object
15 16 17 |
# File 'lib/sub/root.rb', line 15 def svn(cmd) app.svn(cmd) end |
#update ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/sub/root.rb', line 41 def update if @clean remove_unversioned end externals_before = externals svn("up --ignore-externals #{root_path}") # for some reason (array - array) doesn't work right here # so i had to write my own subtract method removed_externals = externals_before.subtract(externals) removed_externals.each do |ext| say "Removed external #{ext}" FileUtils.rm_rf(ext.path) end @processes = Processes.new already_up_to_date = [] externals.each do |external| if external.should_update? if File.exists?(external.path) update_external(external) else checkout_external(external) end else already_up_to_date << external end end unless already_up_to_date.empty? say("External#{'s' if already_up_to_date.size > 1} " + already_up_to_date.collect {|external| external.name}.join(", ") + " already up to date") end @processes.join end |
#update_external(external) ⇒ Object
81 82 83 84 85 |
# File 'lib/sub/root.rb', line 81 def update_external(external) @processes.launch do external.update end end |