Class: Mint::Copier
- Inherits:
-
Object
- Object
- Mint::Copier
- Defined in:
- lib/proutils/mint/copier.rb
Overview
Mint Copier provides a factility for performing interactive, managed copies.
Instance Attribute Summary collapse
-
#actions ⇒ Object
readonly
Stores actions to be performed upon commit.
-
#destination ⇒ Object
Directory (or a file, if copying one file) in which to store copied source.
-
#dryrun ⇒ Object
Just pretend to do the commit action.
-
#force ⇒ Object
Force provided an extra “dangerous” option of “(W)rite all”.
-
#skip ⇒ Object
Automatically skip all overwrites.
-
#source ⇒ Object
Source paths to copy.
-
#system ⇒ Object
Look for source file(s) in system locations?.
Instance Method Summary collapse
-
#common_lookup ⇒ Object
Non-system lookup.
-
#copies ⇒ Object
Files to copy.
-
#copy ⇒ Object
Copy files.
- #dryrun? ⇒ Boolean
- #force? ⇒ Boolean
-
#initialize(source, destination, options = nil) ⇒ Copier
constructor
New copier.
- #skip? ⇒ Boolean
- #system? ⇒ Boolean
-
#system_lookup ⇒ Object
Look up file in system locations.
Constructor Details
#initialize(source, destination, options = nil) ⇒ Copier
New copier.
72 73 74 75 76 77 78 79 80 81 |
# File 'lib/proutils/mint/copier.rb', line 72 def initialize(source, destination, =nil) @source = [source].flatten @destination = destination @actions = [] .each do |k,v| send("#{k}=",v) end end |
Instance Attribute Details
#actions ⇒ Object (readonly)
Stores actions to be performed upon commit.
68 69 70 |
# File 'lib/proutils/mint/copier.rb', line 68 def actions @actions end |
#destination ⇒ Object
Directory (or a file, if copying one file) in which to store copied source.
52 53 54 |
# File 'lib/proutils/mint/copier.rb', line 52 def destination @destination end |
#dryrun ⇒ Object
Just pretend to do the commit action.
56 57 58 |
# File 'lib/proutils/mint/copier.rb', line 56 def dryrun @dryrun end |
#force ⇒ Object
Force provided an extra “dangerous” option of “(W)rite all”.
60 61 62 |
# File 'lib/proutils/mint/copier.rb', line 60 def force @force end |
#skip ⇒ Object
Automatically skip all overwrites.
64 65 66 |
# File 'lib/proutils/mint/copier.rb', line 64 def skip @skip end |
#source ⇒ Object
Source paths to copy. This can be a glob or an array of globs.
48 49 50 |
# File 'lib/proutils/mint/copier.rb', line 48 def source @source end |
#system ⇒ Object
Look for source file(s) in system locations?
44 45 46 |
# File 'lib/proutils/mint/copier.rb', line 44 def system @system end |
Instance Method Details
#common_lookup ⇒ Object
Non-system lookup.
118 119 120 121 122 123 124 125 126 127 |
# File 'lib/proutils/mint/copier.rb', line 118 def common_lookup copies = [] source.each do |src| files = Dir.glob(File.join(path, src)) unless files.empty? copies << [nil, files] end end copies end |
#copies ⇒ Object
Files to copy.
91 92 93 94 95 96 97 |
# File 'lib/proutils/mint/copier.rb', line 91 def copies if system? system_lookup else common_lookup end end |
#copy ⇒ Object
Copy files.
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/proutils/mint/copier.rb', line 131 def copy puts "KEY: (d)iff (r)eplace (s)kip (a)ll (q)uit" copies.each do |dir, file| path = dir ? File.join(dir, file) : file if File.file?(path) copy_file(dir, file) elsif File.directory?(path) dirs, files = *partition(path) # make empty directories dirs.each do |d| if File.directory?(File.join(destination,d)) skip_dir(d) else pth = File.join(path,d) entries = Dir.entries(pth) - IGNORE make_dir(path, d) if entries.empty? end end # copy files in directories files.each do |f| copy_file(path, f) end else raise ArgumentError, "unsupported file object -- #{path}" end end commit end |
#dryrun? ⇒ Boolean
85 |
# File 'lib/proutils/mint/copier.rb', line 85 def dryrun? ; @dryrun ; end |
#force? ⇒ Boolean
86 |
# File 'lib/proutils/mint/copier.rb', line 86 def force? ; @force ; end |
#skip? ⇒ Boolean
87 |
# File 'lib/proutils/mint/copier.rb', line 87 def skip? ; @skip ; end |
#system? ⇒ Boolean
83 |
# File 'lib/proutils/mint/copier.rb', line 83 def system? ; @system ; end |
#system_lookup ⇒ Object
Look up file in system locations.
101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/proutils/mint/copier.rb', line 101 def system_lookup copies = [] Mint.paths.each do |path| source.each do |src| jpath = File.join(path, src) files = Dir.glob(jpath) files.each do |file| file = file.sub(path+'/','') copies << [path, file] end end end copies end |