blob: d74b1be400521213d6b53d301ced4c6b61d4a4c5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
module Convert
# allows different paths for searching to be set
def self.view_path=(path)
@@view_path = path
end
def self.view_path
@@view_path ||= RAILS_ROOT+'/app/views/'
end
# Given a file extension will search for all files recursively in a directory
# and move the files using the move command or subversion move command
#
# Example:
#
# Convert::Mover.find(:rhtml).each do |rhtml|
# rhtml.move :erb, :scm => :svn
# end
#
# This will find all .rhtml files within the views directory and move each file
# to a erb extension using subversion
class Mover
def self.find(file_extension)
files = File.join(Convert::view_path,'**', "*.#{file_extension}")
Dir.glob(files).collect do |path|
self.new(path, file_extension)
end
end
def initialize(file_path, file_extension)
@file_path = file_path
@file_extension = file_extension
end
def move_command(move_to_extension, options = {})
original_path = File.expand_path(@file_path)
new_path = original_path.gsub(".#{@file_extension}", ".#{move_to_extension}")
"#{options[:scm]} mv #{original_path} #{new_path}".lstrip
end
def move(move_to_extension, options = {})
system self.move_command(move_to_extension, options)
end
end
end
|