tesler 0.1.2 → 0.2.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.2.6
data/example/main.rb CHANGED
@@ -23,6 +23,9 @@ directory 'dest' do
23
23
 
24
24
  # copy a file and rename it
25
25
  copy 'src\file9', :rename => 'renamed'
26
+
27
+ # copie d'un ensemble de fichiers
28
+ copy 'test\src\*.test'
26
29
  end
27
30
  end
28
31
 
@@ -32,6 +35,8 @@ directory 'dest' do
32
35
  # copy an entire directory and rename it
33
36
  copy 'src\subdir2', :rename => 'renamed'
34
37
 
38
+ # file pattern support
39
+ copy 'test\src\reg_*.test'
35
40
  end
36
41
 
37
42
 
data/lib/tesler/as.rb ADDED
@@ -0,0 +1,23 @@
1
+ module Kernel
2
+
3
+ # Stolen from Facets. Allows one two execute a specific ancestor's method
4
+ def as(ancestor, &blk)
5
+ @__as ||= {}
6
+ unless r = @__as[ancestor]
7
+ r = (@__as[ancestor] = As.new(self, ancestor))
8
+ end
9
+ r.instance_eval(&blk) if block_given?
10
+ r
11
+ end
12
+ end
13
+
14
+ class As < BasicObject #:nodoc:
15
+ def initialize(subject, ancestor)
16
+ @subject = subject
17
+ @ancestor = ancestor
18
+ end
19
+
20
+ def method_missing(sym, *args, &blk)
21
+ @ancestor.instance_method(sym).bind(@subject).call(*args,&blk)
22
+ end
23
+ end
data/lib/tesler/config.rb CHANGED
@@ -1,11 +1,42 @@
1
1
  module Tesler
2
+ # This module contains all the configuration variables used by tesler
2
3
  module Config
4
+
5
+ # Get the standard output. The output is an object who must respond to the 'puts' method. By default it is set to STDOUT
3
6
  def self.output
4
7
  @output ||= STDOUT
5
8
  end
6
9
 
10
+ # Set the standard output.
7
11
  def self.output=(output)
8
12
  @output = output
9
13
  end
14
+
15
+ # Get the source directory. It is the directory where all the files that we are copying , are taken from.
16
+ def self.source_directory
17
+ @source_directory ||= ''
18
+ end
19
+
20
+ # Set the source directory
21
+ def self.source_directory=(directory_name)
22
+ @source_directory = directory_name.tesler
23
+ end
24
+
25
+ # get the module which performs the copy operations
26
+ def self.operator
27
+ @operator ||= Tesler::Operators::Run
28
+ end
29
+
30
+ # define the module which performs the copy operations
31
+ def self.operator=(op)
32
+ @operator = op
33
+ end
34
+
35
+ # Reinitializes the configuration
36
+ def self.reset
37
+ @output = nil
38
+ @source_directory = nil
39
+ @operator = nil
40
+ end
10
41
  end
11
42
  end
data/lib/tesler/copier.rb CHANGED
@@ -1,29 +1,81 @@
1
1
  module Tesler
2
+ # This the class which receives the DSL commands.
2
3
  class Copier
3
- include Tesler::Commands::Run
4
+ include Tesler::Operators::Base
5
+ include Tesler::Operators::Logger
6
+ include Tesler::Operators::Run
4
7
 
5
8
  def initialize(directory_name)
6
9
  @directory_name = directory_name
7
- set_directory(@directory_name)
10
+ self.as(Tesler::Config.operator).set_directory(@directory_name)
8
11
  end
9
12
 
13
+ # Method called by the DSL method 'copy'
10
14
  def copy(file_name, options={})
11
- if File.directory? file_name.to_unix
12
- copy_dir(file_name.to_unix, options)
15
+ filename = file_name.tesler
16
+ if not Tesler::Config.source_directory.blank?
17
+ filename = "#{Tesler::Config.source_directory}/#{filename}"
18
+ end
19
+
20
+ # if the file's name contains a star, then it is considered as a regular expression
21
+ if filename.include? "*"
22
+ regexp_copy(filename, options)
23
+
24
+ # the file's name is not a regular expression, so we copy it directly
13
25
  else
14
- copy_file(file_name.to_unix, options)
26
+ direct_copy(filename, options)
15
27
  end
16
28
  end
17
29
 
30
+ # This method create a sub-directory
18
31
  def directory(directory_name, &block)
19
32
  copier = Copier.new("#{@directory_name}/#{directory_name}")
20
33
  copier.instance_eval(&block)
21
34
  end
22
35
 
36
+ # Method called by the DSL method 'directory'
23
37
  def self.directory(directory_name, &block)
24
38
  copier = Copier.new(directory_name)
25
39
  copier.instance_eval(&block)
26
40
  end
41
+
42
+ private
43
+
44
+ # Analyses a regular expression and generate the list of file to copy
45
+ def regexp_copy(filename, options)
46
+ dirname = File.dirname(filename)
47
+ basename = File.basename(filename)
48
+
49
+ # generation of the ruby regexp corresponding to the file regexp
50
+ r = Regexp.new('^' + basename.gsub(/\./, '\.').gsub(/\*/, '(.*)') + '$')
51
+
52
+ # check if the directory exists
53
+ if not File.exists?(dirname)
54
+ Tesler::Config.output.puts "\tnot found\t#{dirname}"
55
+ return
56
+ end
57
+
58
+ Dir.entries(dirname).each do |entry|
59
+ next if %(. ..).include?(entry)
60
+
61
+ # when were processing regular expressions, the :rename option is ignored
62
+ options.delete(:rename)
63
+ direct_copy("#{dirname}/#{entry}", options) if entry =~ r
64
+ end
65
+ end
66
+
67
+ # This method checks if we're working whith a file or a directory and perform the corresponding copy operation
68
+ def direct_copy(filename, options)
69
+ if File.directory? filename
70
+ self.as(Tesler::Config.operator).copy_dir(filename, options)
71
+
72
+ elsif File.exists? filename
73
+ self.as(Tesler::Config.operator).copy_file(filename, options)
74
+
75
+ else
76
+ Tesler::Config.output.puts "\tnot found\t#{filename}"
77
+ end
78
+ end
27
79
  end
28
80
  end
29
81
 
data/lib/tesler/dsl.rb CHANGED
@@ -1,14 +1,20 @@
1
+ # sets a directory where to copy files. If this directory doesn't exist, it is created
1
2
  def directory(directory_name, &block)
2
- Tesler::Copier.directory(directory_name.to_unix, &block)
3
+ Tesler::Copier.directory(directory_name.tesler, &block)
3
4
  end
4
5
 
6
+ # sets the directory where the file that we are copying, are taken from
7
+ def source_directory(directory_name)
8
+ Tesler::Config.source_directory = directory_name
9
+ end
10
+
11
+ # reinitializes the configuration
12
+ def reset_config
13
+ Tesler::Config.reset
14
+ end
15
+
16
+ # in test mode, tesler only logs its actions without effectively copying the files
5
17
  def run_in_test_mode
6
- eval <<-EOV
7
- module Tesler
8
- class Copier
9
- include Tesler::Commands::Logger
10
- end
11
- end
12
- EOV
18
+ Tesler::Config.operator = Tesler::Operators::Logger
13
19
  end
14
20
 
data/lib/tesler/ext.rb CHANGED
@@ -1,6 +1,29 @@
1
+ # define an extension for the Object class
2
+ class Object
3
+ # stolen from activesupport.
4
+ def blank?
5
+ respond_to?(:empty?) ? empty? : !self
6
+ end
7
+ end
8
+
9
+ # define an extension for the String class
1
10
  class String
2
- def to_unix
3
- File.join self.split("\\")
11
+ # actions :
12
+ # * replace the Windows directory separtor (\) by the unix separator (/)
13
+ # * replace tokens matching the format %TOKEN% by an environment variable
14
+ def tesler
15
+ # replace separators
16
+ s = File.join self.split("\\")
17
+
18
+ # environment variables
19
+ env_vars = self.scan(/%([a-zA-Z_]+)%/).map { |array| array.first }
20
+ env_vars.each do |var|
21
+ s.gsub!(Regexp.new("%#{var}%"), ENV[var])
22
+ end
23
+
24
+ File.join s.split("\\")
4
25
  end
26
+
27
+
5
28
  end
6
29
 
@@ -0,0 +1,19 @@
1
+ module Tesler
2
+ module Operators
3
+ module Base
4
+ def destination_name(file_name, options)
5
+ base_name = options[:rename]
6
+ base_name = File.basename(file_name) if base_name.nil?
7
+ destination = "#{@directory_name}/#{base_name}"
8
+
9
+ # if the directory option is set, create the sub-directory if necessary
10
+ if options[:directory]
11
+ FileUtils.mkdir_p "#{@directory_name}/#{options[:directory]}"
12
+ destination = "#{@directory_name}/#{options[:directory]}/#{base_name}"
13
+ end
14
+
15
+ destination
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,39 @@
1
+ module Tesler
2
+ module Operators
3
+ # This module only logs the actions
4
+ module Logger
5
+ extend self
6
+
7
+ def set_directory(directory_name)
8
+ if File.exists? directory_name
9
+ Tesler::Config.output.puts "\texists\t#{directory_name}"
10
+ else
11
+ Tesler::Config.output.puts "\tcreate\t#{directory_name}"
12
+ end
13
+ end
14
+
15
+ def copy_file(file_name, options)
16
+ self.as(Tesler::Config.operator).copy_dir(file_name, options)
17
+ end
18
+
19
+ def copy_dir(file_name, options)
20
+ Tesler::Config.output.puts "\tcopy\t#{file_name}\t#{destination_name(file_name, options)}"
21
+ end
22
+
23
+ def self.destination_name(file_name, options)
24
+ base_name = options[:rename]
25
+ base_name = File.basename(file_name) if base_name.nil?
26
+ destination = "#{options[:destination]}/#{base_name}"
27
+
28
+ # if the directory option is set, create the sub-directory if necessary
29
+ if options[:directory]
30
+ FileUtils.mkdir_p "#{options[:destination]}/#{options[:directory]}"
31
+ destination = "#{options[:destination]}/#{options[:directory]}/#{base_name}"
32
+ end
33
+
34
+ destination
35
+ end
36
+ end
37
+ end
38
+ end
39
+
@@ -0,0 +1,26 @@
1
+ require 'fileutils'
2
+
3
+ module Tesler
4
+ module Operators
5
+ # This class defines the effective copy operations
6
+ module Run
7
+ def set_directory(directory_name)
8
+ Tesler::Operators::Logger.set_directory(directory_name)
9
+ FileUtils.mkdir_p @directory_name
10
+ end
11
+
12
+ def copy_file(file_name, options)
13
+ self.as(Tesler::Config.operator).copy_dir(file_name, options)
14
+ end
15
+
16
+ def copy_dir(file_name, options)
17
+ # we add the destination in the options for the logger because it can't find it itself
18
+ Tesler::Operators::Logger.copy_dir(file_name, options.merge({:destination => @directory_name}))
19
+
20
+ # recursive copy
21
+ FileUtils.cp_r file_name, "#{destination_name(file_name, options)}"
22
+ end
23
+ end
24
+ end
25
+ end
26
+
data/lib/tesler.rb CHANGED
@@ -1,8 +1,9 @@
1
1
  require File.join(File.dirname(__FILE__), "tesler", "ext")
2
+ require File.join(File.dirname(__FILE__), "tesler", "as")
2
3
  require File.join(File.dirname(__FILE__), "tesler", "config")
3
- require File.join(File.dirname(__FILE__), "tesler", "commands", "base")
4
- require File.join(File.dirname(__FILE__), "tesler", "commands", "logger")
5
- require File.join(File.dirname(__FILE__), "tesler", "commands", "run")
4
+ require File.join(File.dirname(__FILE__), "tesler", "operators", "base")
5
+ require File.join(File.dirname(__FILE__), "tesler", "operators", "logger")
6
+ require File.join(File.dirname(__FILE__), "tesler", "operators", "run")
6
7
  require File.join(File.dirname(__FILE__), "tesler", "copier")
7
8
  require File.join(File.dirname(__FILE__), "tesler", "dsl")
8
9
 
data/test/helper.rb CHANGED
@@ -8,3 +8,15 @@ require 'tesler'
8
8
 
9
9
  class Test::Unit::TestCase
10
10
  end
11
+
12
+ # This class simulate the standard output
13
+ class Output
14
+ def messages
15
+ @messages ||= []
16
+ end
17
+
18
+ def puts(message)
19
+ messages << message
20
+ end
21
+ end
22
+
File without changes
File without changes
File without changes
File without changes
File without changes
data/test/test_tesler.rb CHANGED
@@ -1,23 +1,20 @@
1
1
  require 'helper'
2
2
 
3
- class Output
4
- def messages
5
- @messages ||= []
6
- end
7
-
8
- def puts(message)
9
- messages << message
10
- end
11
- end
12
-
13
3
  class TestTesler < Test::Unit::TestCase
14
4
  def setup
15
- FileUtils.rm_r("dest") if File.exists?("dest")
5
+ # reinitialize tesler
6
+ reset_config
16
7
 
8
+ # assign a mock of the standar output to tesler
17
9
  @output = Output.new
18
10
  Tesler::Config.output = @output
11
+ end
19
12
 
20
- directory 'test\dest' do
13
+ should "copy files" do
14
+ # We delete the destination if it exists
15
+ FileUtils.rm_r("test/dest/1") if File.exists?("test/dest/1")
16
+
17
+ directory 'test\dest\1' do
21
18
  copy 'test\src\file1'
22
19
  copy 'test\src\file2'
23
20
  copy 'test\src\subdir1\file4'
@@ -27,14 +24,127 @@ class TestTesler < Test::Unit::TestCase
27
24
  copy 'test\src\subdir1\file5'
28
25
 
29
26
  directory 'subdir3' do
30
- copy 'test\src\file8'
31
- copy 'test\src\file9', :rename => 'renamed'
27
+ copy 'test\src\file1'
32
28
  end
33
29
  end
30
+
31
+ copy 'test\src\file2', :directory => 'subdir4'
32
+ end
33
+
34
+ assert File.exists?("test/dest/1/file1")
35
+ assert File.exists?("test/dest/1/file2")
36
+ assert File.exists?("test/dest/1/file4")
37
+ assert File.exists?("test/dest/1/subdir1/file3")
38
+ assert File.exists?("test/dest/1/subdir1/file5")
39
+ assert File.exists?("test/dest/1/subdir1/subdir3/file1")
40
+ assert File.exists?("test/dest/1/subdir4/file2")
41
+ end
42
+
43
+ should "copy entire directories" do
44
+ # We delete the destination if it exists
45
+ FileUtils.rm_r("test/dest/2") if File.exists?("test/dest/2")
46
+
47
+ directory 'test\dest\2' do
48
+ copy 'test\src\subdir2'
49
+ end
50
+
51
+ assert File.exists?("test/dest/2/subdir2")
52
+ end
53
+
54
+ should "support the renaming of the files and directories which are copied" do
55
+ # We delete the destination if it exists
56
+ FileUtils.rm_r("test/dest/3") if File.exists?("test/dest/3")
57
+
58
+ directory 'test\dest\3' do
59
+ directory 'subdir1' do
60
+ directory 'subdir3' do
61
+ copy 'test\src\file1', :rename => 'file1_renamed'
62
+ end
63
+ end
64
+
65
+ copy 'test\src\subdir2', :rename => 'subdir2_renamed'
66
+ end
67
+
68
+ assert File.exists?("test/dest/3/subdir1/subdir3/file1_renamed")
69
+ assert File.exists?("test/dest/3/subdir2_renamed")
70
+ end
71
+
72
+ should "support regular expressions on the filenames" do
73
+ # We delete the destination if it exists
74
+ FileUtils.rm_r("test/dest/4") if File.exists?("test/dest/4")
75
+
76
+ directory 'test\dest\4' do
77
+ directory 'subdir1' do
78
+ directory 'subdir3' do
79
+ copy 'test\src\*.test'
80
+ end
81
+ end
82
+
83
+ copy 'test\src\reg_*.test'
84
+ copy 'test\src\reg_*.test', :directory => 'subdir2'
85
+ end
86
+
87
+ assert File.exists?("test/dest/4/subdir1/subdir3/noreg_1.test")
88
+ assert File.exists?("test/dest/4/subdir1/subdir3/noreg_2.test")
89
+ assert File.exists?("test/dest/4/subdir1/subdir3/reg_1.test")
90
+ assert File.exists?("test/dest/4/subdir1/subdir3/reg_2.test")
91
+ assert File.exists?("test/dest/4/subdir1/subdir3/reg_3.test")
92
+ assert File.exists?("test/dest/4/reg_1.test")
93
+ assert File.exists?("test/dest/4/reg_2.test")
94
+ assert File.exists?("test/dest/4/reg_3.test")
95
+ assert File.exists?("test/dest/4/subdir2/reg_1.test")
96
+ assert File.exists?("test/dest/4/subdir2/reg_2.test")
97
+ assert File.exists?("test/dest/4/subdir2/reg_3.test")
98
+ end
99
+
100
+ should "log its actions" do
101
+ # We delete the destination if it exists
102
+ FileUtils.rm_r("test/dest/5") if File.exists?("test/dest/5")
103
+
104
+ directory 'test\dest\5' do
105
+ copy 'test\src\file1'
106
+ copy 'test\src\file2'
107
+ copy 'test\src\subdir1\file4'
34
108
 
109
+ directory 'subdir1' do
110
+ copy 'test\src\file3'
111
+ copy 'test\src\subdir1\file5'
112
+
113
+ directory 'subdir3' do
114
+ copy 'test\src\file1'
115
+ copy 'test\src\file2', :rename => 'file2_renamed'
116
+ copy 'test\src\*.test'
117
+ end
118
+ end
119
+
35
120
  copy 'test\src\subdir2'
36
- copy 'test\src\subdir2', :rename => 'renamed'
121
+ copy 'test\src\subdir2', :rename => 'subdir2_renamed'
122
+ copy 'test\src\reg_*.test'
123
+ copy 'test\src\file2', :directory => 'subdir4'
37
124
  end
125
+
126
+ messages = @output.messages.map { |m| m.strip }
127
+ assert_match /(create|exists)\ttest\/dest\/5/, messages[0]
128
+ assert_equal "copy\ttest/src/file1\ttest/dest/5/file1", messages[1]
129
+ assert_equal "copy\ttest/src/file2\ttest/dest/5/file2", messages[2]
130
+ assert_equal "copy\ttest/src/subdir1/file4\ttest/dest/5/file4", messages[3]
131
+ assert_match /(create|exists)\ttest\/dest\/5\/subdir1/, messages[4]
132
+ assert_equal "copy\ttest/src/file3\ttest/dest/5/subdir1/file3", messages[5]
133
+ assert_equal "copy\ttest/src/subdir1/file5\ttest/dest/5/subdir1/file5", messages[6]
134
+ assert_match /(create|exists)\ttest\/dest\/5\/subdir1\/subdir3/, messages[7]
135
+ assert_equal "copy\ttest/src/file1\ttest/dest/5/subdir1/subdir3/file1", messages[8]
136
+ assert_equal "copy\ttest/src/file2\ttest/dest/5/subdir1/subdir3/file2_renamed", messages[9]
137
+ assert_equal "copy\ttest/src/noreg_1.test\ttest/dest/5/subdir1/subdir3/noreg_1.test", messages[10]
138
+ assert_equal "copy\ttest/src/noreg_2.test\ttest/dest/5/subdir1/subdir3/noreg_2.test", messages[11]
139
+ assert_equal "copy\ttest/src/reg_1.test\ttest/dest/5/subdir1/subdir3/reg_1.test", messages[12]
140
+ assert_equal "copy\ttest/src/reg_2.test\ttest/dest/5/subdir1/subdir3/reg_2.test", messages[13]
141
+ assert_equal "copy\ttest/src/reg_3.test\ttest/dest/5/subdir1/subdir3/reg_3.test", messages[14]
142
+ assert_equal "copy\ttest/src/subdir2\ttest/dest/5/subdir2", messages[15]
143
+ assert_equal "copy\ttest/src/subdir2\ttest/dest/5/subdir2_renamed", messages[16]
144
+ assert_equal "copy\ttest/src/reg_1.test\ttest/dest/5/reg_1.test", messages[17]
145
+ assert_equal "copy\ttest/src/reg_2.test\ttest/dest/5/reg_2.test", messages[18]
146
+ assert_equal "copy\ttest/src/reg_3.test\ttest/dest/5/reg_3.test", messages[19]
147
+ assert_equal "copy\ttest/src/file2\ttest/dest/5/subdir4/file2", messages[20]
38
148
  end
39
149
 
40
150
  should "copy files" do
@@ -51,6 +161,27 @@ class TestTesler < Test::Unit::TestCase
51
161
  assert File.exists?("test/dest/subdir2")
52
162
  assert File.exists?("test/dest/renamed")
53
163
 
164
+ assert File.exists?("test/dest/6")
165
+ assert File.exists?("test/dest/6/file1")
166
+ assert File.exists?("test/dest/6/file2")
167
+ assert File.exists?("test/dest/6/file4")
168
+ assert File.exists?("test/dest/6/subdir1")
169
+ assert File.exists?("test/dest/6/subdir1/file3")
170
+ assert File.exists?("test/dest/6/subdir1/file5")
171
+ assert File.exists?("test/dest/6/subdir1/subdir3")
172
+ assert File.exists?("test/dest/6/subdir1/subdir3/file1")
173
+ assert File.exists?("test/dest/6/subdir1/subdir3/file2_renamed")
174
+ assert File.exists?("test/dest/6/subdir2")
175
+ assert File.exists?("test/dest/6/subdir2_renamed")
176
+ assert File.exists?("test/dest/6/subdir1/subdir3/noreg_1.test")
177
+ assert File.exists?("test/dest/6/subdir1/subdir3/noreg_2.test")
178
+ assert File.exists?("test/dest/6/subdir1/subdir3/reg_1.test")
179
+ assert File.exists?("test/dest/6/subdir1/subdir3/reg_2.test")
180
+ assert File.exists?("test/dest/6/subdir1/subdir3/reg_3.test")
181
+ assert File.exists?("test/dest/6/reg_1.test")
182
+ assert File.exists?("test/dest/6/reg_2.test")
183
+ assert File.exists?("test/dest/6/reg_3.test")
184
+
54
185
  messages = @output.messages.map { |m| m.strip }
55
186
  assert_match messages[0], /(create|exists)\ttest\/dest/
56
187
  assert_equal messages[1], "copy\ttest/dest/file1"
@@ -65,4 +196,130 @@ class TestTesler < Test::Unit::TestCase
65
196
  assert_equal messages[10], "copy\ttest/dest/subdir2"
66
197
  assert_equal messages[11], "copy\ttest/dest/renamed"
67
198
  end
199
+
200
+ should "be able to run in test mode" do
201
+ # We delete the destination if it exists
202
+ FileUtils.rm_r("test/dest/7") if File.exists?("test/dest/7")
203
+
204
+ # when running in test mode, the files are not copied but the logger displays the results
205
+ run_in_test_mode
206
+ source_directory 'test\src'
207
+
208
+ directory 'test\dest\7' do
209
+ copy 'file1'
210
+ copy 'file2'
211
+ copy 'subdir1\file4'
212
+
213
+ directory 'subdir1' do
214
+ copy 'file3'
215
+ copy 'subdir1\file5'
216
+
217
+ directory 'subdir3' do
218
+ copy 'file1'
219
+ copy 'file2', :rename => 'file2_renamed'
220
+ copy '*.test'
221
+ end
222
+ end
223
+
224
+ copy 'subdir2'
225
+ copy 'subdir2', :rename => 'subdir2_renamed'
226
+ copy 'reg_*.test'
227
+ end
228
+
229
+ assert !File.exists?("test/dest/7")
230
+ assert !File.exists?("test/dest/7/file1")
231
+ assert !File.exists?("test/dest/7/file2")
232
+ assert !File.exists?("test/dest/7/file4")
233
+ assert !File.exists?("test/dest/7/subdir1")
234
+ assert !File.exists?("test/dest/7/subdir1/file3")
235
+ assert !File.exists?("test/dest/7/subdir1/file5")
236
+ assert !File.exists?("test/dest/7/subdir1/subdir3")
237
+ assert !File.exists?("test/dest/7/subdir1/subdir3/file1")
238
+ assert !File.exists?("test/dest/7/subdir1/subdir3/file2_renamed")
239
+ assert !File.exists?("test/dest/7/subdir2")
240
+ assert !File.exists?("test/dest/7/subdir2_renamed")
241
+ assert !File.exists?("test/dest/7/subdir1/subdir3/noreg_1.test")
242
+ assert !File.exists?("test/dest/7/subdir1/subdir3/noreg_2.test")
243
+ assert !File.exists?("test/dest/7/subdir1/subdir3/reg_1.test")
244
+ assert !File.exists?("test/dest/7/subdir1/subdir3/reg_2.test")
245
+ assert !File.exists?("test/dest/7/subdir1/subdir3/reg_3.test")
246
+ assert !File.exists?("test/dest/7/reg_1.test")
247
+ assert !File.exists?("test/dest/7/reg_2.test")
248
+ assert !File.exists?("test/dest/7/reg_3.test")
249
+
250
+ messages = @output.messages.map { |m| m.strip }
251
+ assert_match /(create|exists)\ttest\/dest\/7/, messages[0]
252
+ assert_equal "copy\ttest/src/file1\ttest/dest/7/file1", messages[1]
253
+ assert_equal "copy\ttest/src/file2\ttest/dest/7/file2", messages[2]
254
+ assert_equal "copy\ttest/src/subdir1/file4\ttest/dest/7/file4", messages[3]
255
+ assert_match /(create|exists)\ttest\/dest\/7\/subdir1/, messages[4]
256
+ assert_equal "copy\ttest/src/file3\ttest/dest/7/subdir1/file3", messages[5]
257
+ assert_equal "copy\ttest/src/subdir1/file5\ttest/dest/7/subdir1/file5", messages[6]
258
+ assert_match /(create|exists)\ttest\/dest\/7\/subdir1\/subdir3/, messages[7]
259
+ assert_equal "copy\ttest/src/file1\ttest/dest/7/subdir1/subdir3/file1", messages[8]
260
+ assert_equal "copy\ttest/src/file2\ttest/dest/7/subdir1/subdir3/file2_renamed", messages[9]
261
+ assert_equal "copy\ttest/src/noreg_1.test\ttest/dest/7/subdir1/subdir3/noreg_1.test", messages[10]
262
+ assert_equal "copy\ttest/src/noreg_2.test\ttest/dest/7/subdir1/subdir3/noreg_2.test", messages[11]
263
+ assert_equal "copy\ttest/src/reg_1.test\ttest/dest/7/subdir1/subdir3/reg_1.test", messages[12]
264
+ assert_equal "copy\ttest/src/reg_2.test\ttest/dest/7/subdir1/subdir3/reg_2.test", messages[13]
265
+ assert_equal "copy\ttest/src/reg_3.test\ttest/dest/7/subdir1/subdir3/reg_3.test", messages[14]
266
+ assert_equal "copy\ttest/src/subdir2\ttest/dest/7/subdir2", messages[15]
267
+ assert_equal "copy\ttest/src/subdir2\ttest/dest/7/subdir2_renamed", messages[16]
268
+ assert_equal "copy\ttest/src/reg_1.test\ttest/dest/7/reg_1.test", messages[17]
269
+ assert_equal "copy\ttest/src/reg_2.test\ttest/dest/7/reg_2.test", messages[18]
270
+ assert_equal "copy\ttest/src/reg_3.test\ttest/dest/7/reg_3.test", messages[19]
271
+ end
272
+
273
+ should "log when it can't find a source file" do
274
+ # We delete the destination if it exists
275
+ FileUtils.rm_r("test/dest/8") if File.exists?("test/dest/8")
276
+
277
+ source_directory 'test\src'
278
+
279
+ directory 'test\dest\8' do
280
+ copy 'unknown_file'
281
+ end
282
+
283
+ assert File.exists?("test/dest/8")
284
+ messages = @output.messages.map { |m| m.strip }
285
+ assert_match /(create|exists)\ttest\/dest\/8/, messages[0]
286
+ assert_equal "not found\ttest/src/unknown_file", messages[1]
287
+ end
288
+
289
+ should "detect and replace environment variables" do
290
+ # We delete the destination if it exists
291
+ FileUtils.rm_r("test/dest/9") if File.exists?("test/dest/9")
292
+
293
+ # create a new environment variable
294
+ ENV['TESLER_TEST'] = File.dirname(__FILE__)
295
+
296
+ directory '%TESLER_TEST%\dest\9' do
297
+ copy '%TESLER_TEST%\src\file1'
298
+ copy '%TESLER_TEST%\src\*.test'
299
+ end
300
+
301
+ assert File.exists?("test/dest/9")
302
+ assert File.exists?("test/dest/9/file1")
303
+ assert File.exists?("test/dest/9/noreg_1.test")
304
+ assert File.exists?("test/dest/9/noreg_2.test")
305
+ assert File.exists?("test/dest/9/reg_1.test")
306
+ assert File.exists?("test/dest/9/reg_2.test")
307
+ assert File.exists?("test/dest/9/reg_3.test")
308
+ end
309
+
310
+ should "log when it can't find a source file's directory (regular expressions case only)" do
311
+ # We delete the destination if it exists
312
+ FileUtils.rm_r("test/dest/10") if File.exists?("test/dest/10")
313
+
314
+ source_directory 'unknown\src'
315
+
316
+ directory 'test\dest\10' do
317
+ copy '*.file'
318
+ end
319
+
320
+ assert File.exists?("test/dest/10")
321
+ messages = @output.messages.map { |m| m.strip }
322
+ assert_match /(create|exists)\ttest\/dest\/10/, messages[0]
323
+ assert_equal "not found\tunknown/src", messages[1]
324
+ end
68
325
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tesler
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 27
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
8
  - 2
10
- version: 0.1.2
9
+ - 6
10
+ version: 0.2.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Rawane ZOSSOU
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-26 00:00:00 +02:00
18
+ date: 2010-07-02 00:00:00 +02:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -59,19 +59,23 @@ files:
59
59
  - example/src/subdir2/file6
60
60
  - example/src/subdir2/file7
61
61
  - lib/tesler.rb
62
- - lib/tesler/commands/base.rb
63
- - lib/tesler/commands/logger.rb
64
- - lib/tesler/commands/run.rb
62
+ - lib/tesler/as.rb
65
63
  - lib/tesler/config.rb
66
64
  - lib/tesler/copier.rb
67
65
  - lib/tesler/dsl.rb
68
66
  - lib/tesler/ext.rb
67
+ - lib/tesler/operators/base.rb
68
+ - lib/tesler/operators/logger.rb
69
+ - lib/tesler/operators/run.rb
69
70
  - test/helper.rb
70
71
  - test/src/file1
71
72
  - test/src/file2
72
73
  - test/src/file3
73
- - test/src/file8
74
- - test/src/file9
74
+ - test/src/noreg_1.test
75
+ - test/src/noreg_2.test
76
+ - test/src/reg_1.test
77
+ - test/src/reg_2.test
78
+ - test/src/reg_3.test
75
79
  - test/src/subdir1/file4
76
80
  - test/src/subdir1/file5
77
81
  - test/src/subdir2/file6
@@ -1,11 +0,0 @@
1
- module Tesler
2
- module Commands
3
- module Base
4
- def self.get_name(file_name, options)
5
- option_rename = options.delete(:rename)
6
- return file_name if option_rename.nil?
7
- "#{File.dirname(file_name)}/#{option_rename}"
8
- end
9
- end
10
- end
11
- end
@@ -1,38 +0,0 @@
1
- module Tesler
2
- module Commands
3
- module Logger
4
- extend Tesler::Commands::Base
5
- extend self
6
-
7
- def set_directory(directory_name)
8
- if File.exists? directory_name
9
- Tesler::Config.output.puts "\texists\t#{directory_name}"
10
- else
11
- Tesler::Config.output.puts "\tcreate\t#{directory_name}"
12
- end
13
- end
14
-
15
- def copy_file(file_name, options)
16
- if @directory_name
17
- # When included itself in the copier
18
- base_name = options[:rename]
19
- base_name = File.basename(file_name) if base_name.nil?
20
- Tesler::Config.output.puts "\tcopy\t#{@directory_name}/#{base_name}"
21
- else
22
- # When used by another module included in the copier
23
- output = file_name
24
- if options[:rename]
25
- output = "#{File.dirname(file_name)}/#{options[:rename]}"
26
- end
27
-
28
- Tesler::Config.output.puts "\tcopy\t#{output}"
29
- end
30
- end
31
-
32
- def copy_dir(file_name, options)
33
- copy_file(file_name, options)
34
- end
35
- end
36
- end
37
- end
38
-
@@ -1,35 +0,0 @@
1
- require 'fileutils'
2
-
3
- module Tesler
4
- module Commands
5
- module Run
6
- extend Tesler::Commands::Base
7
-
8
- def set_directory(directory_name)
9
- Tesler::Commands::Logger.set_directory(directory_name)
10
-
11
- # create the directory if it doesn't exist
12
- FileUtils.mkdir_p @directory_name
13
- end
14
-
15
- def copy_file(file_name, options)
16
- copy_dir(file_name, options)
17
- end
18
-
19
- def copy_dir(file_name, options)
20
- # even if the rename option is set, we send the old filename and the rename option to the logger. It will rename the file itself.
21
- dest_file_name = "#{@directory_name}/#{File.basename(file_name)}"
22
- Tesler::Commands::Logger.copy_dir(dest_file_name, options)
23
-
24
- # change the destination filename if needed
25
- if options[:rename]
26
- dest_file_name = "#{@directory_name}/#{options[:rename]}"
27
- end
28
-
29
- # recursive copy
30
- FileUtils.cp_r file_name, dest_file_name
31
- end
32
- end
33
- end
34
- end
35
-