Class: Classifile::Execute
- Inherits:
-
Object
- Object
- Classifile::Execute
- Defined in:
- lib/classifile/execute.rb
Overview
execute
Instance Method Summary collapse
-
#classify(dsl_path, from_paths, to_path) ⇒ Object
Classify files by DSL and return an array of MoveFile classes.
-
#copy(dsl_path, from_paths, to_path) ⇒ Object
Classify the files by DSL.
-
#move(dsl_path, from_paths, to_path) ⇒ Object
Classify the files by DSL.
-
#test(dsl_path, from_paths, to_path) ⇒ Object
Classify the files by DSL.
Instance Method Details
#classify(dsl_path, from_paths, to_path) ⇒ Object
Classify files by DSL and return an array of MoveFile classes.
48 49 50 51 52 53 54 55 56 |
# File 'lib/classifile/execute.rb', line 48 def classify(dsl_path, from_paths, to_path) arr = [] dsl = FileTools.read_dsl(dsl_path) Dir.glob(from_paths).each do |from_path| arr |= _classify(dsl, from_path, to_path) end arr end |
#copy(dsl_path, from_paths, to_path) ⇒ Object
Classify the files by DSL. However, the original file will remain.
36 37 38 39 40 41 42 43 44 |
# File 'lib/classifile/execute.rb', line 36 def copy(dsl_path, from_paths, to_path) classify(dsl_path, from_paths, to_path).each do |result| if result.is_a? MoveFile FileTools.move(result.from, result.to, copy: true) result.after_save_procs.each(&:call) end result.after_save_procs.each(&:call) if result.is_a? RemoveFile end end |
#move(dsl_path, from_paths, to_path) ⇒ Object
Classify the files by DSL.
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/classifile/execute.rb', line 20 def move(dsl_path, from_paths, to_path) classify(dsl_path, from_paths, to_path).each do |result| if result.is_a? MoveFile FileTools.move(result.from, result.to) result.after_save_procs.each(&:call) end if result.is_a? RemoveFile FileUtils.remove(result.from) result.after_save_procs.each(&:call) end end end |
#test(dsl_path, from_paths, to_path) ⇒ Object
Classify the files by DSL. However, it does not actually move the file, but outputs the mv command as a string.
11 12 13 14 15 16 |
# File 'lib/classifile/execute.rb', line 11 def test(dsl_path, from_paths, to_path) classify(dsl_path, from_paths, to_path).each do |result| puts "mv \"#{result.from}\" \"#{result.to}\" " if result.is_a? MoveFile puts "rm \"#{result.from}\" " if result.is_a? RemoveFile end end |