tesler 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/.document +5 -0
  2. data/.gitignore +23 -0
  3. data/LICENSE +20 -0
  4. data/README.md +27 -0
  5. data/Rakefile +53 -0
  6. data/VERSION +1 -0
  7. data/example/dest/file1 +0 -0
  8. data/example/dest/file2 +0 -0
  9. data/example/dest/file4 +0 -0
  10. data/example/dest/renamed/file6 +0 -0
  11. data/example/dest/renamed/file7 +1 -0
  12. data/example/dest/subdir1/file3 +0 -0
  13. data/example/dest/subdir1/file5 +0 -0
  14. data/example/dest/subdir1/subdir3/file8 +0 -0
  15. data/example/dest/subdir1/subdir3/renamed +0 -0
  16. data/example/dest/subdir2/file6 +0 -0
  17. data/example/dest/subdir2/file7 +1 -0
  18. data/example/main.rb +41 -0
  19. data/example/src/file1 +0 -0
  20. data/example/src/file2 +0 -0
  21. data/example/src/file3 +0 -0
  22. data/example/src/file8 +0 -0
  23. data/example/src/file9 +0 -0
  24. data/example/src/subdir1/file4 +0 -0
  25. data/example/src/subdir1/file5 +0 -0
  26. data/example/src/subdir2/file6 +0 -0
  27. data/example/src/subdir2/file7 +1 -0
  28. data/lib/tesler/commands/base.rb +11 -0
  29. data/lib/tesler/commands/logger.rb +38 -0
  30. data/lib/tesler/commands/run.rb +35 -0
  31. data/lib/tesler/config.rb +11 -0
  32. data/lib/tesler/copier.rb +29 -0
  33. data/lib/tesler/dsl.rb +14 -0
  34. data/lib/tesler/ext.rb +6 -0
  35. data/lib/tesler.rb +8 -0
  36. data/test/helper.rb +10 -0
  37. data/test/src/file1 +0 -0
  38. data/test/src/file2 +0 -0
  39. data/test/src/file3 +0 -0
  40. data/test/src/file8 +0 -0
  41. data/test/src/file9 +0 -0
  42. data/test/src/subdir1/file4 +0 -0
  43. data/test/src/subdir1/file5 +0 -0
  44. data/test/src/subdir2/file6 +0 -0
  45. data/test/src/subdir2/file7 +1 -0
  46. data/test/test_tesler.rb +71 -0
  47. metadata +127 -0
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+
21
+ ## PROJECT::SPECIFIC
22
+ test/dest
23
+ *.gemspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Rawane ZOSSOU
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,27 @@
1
+ # tesler #
2
+
3
+ Tesler is a small DSl which allows you to describe a directory/file hierarchy where to copy some files.
4
+
5
+ ## Installation ##
6
+
7
+ Just run the following command :
8
+
9
+ gem install tesler
10
+
11
+ ## Usage ##
12
+
13
+ Look at the example in the gem directory for details.
14
+
15
+ ## Note on Patches/Pull Requests ##
16
+
17
+ * Fork the project.
18
+ * Make your feature addition or bug fix.
19
+ * Add tests for it. This is important so I don't break it in a
20
+ future version unintentionally.
21
+ * Commit, do not mess with rakefile, version, or history.
22
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
23
+ * Send me a pull request. Bonus points for topic branches.
24
+
25
+ ## Copyright ##
26
+
27
+ Copyright (c) 2010 Rawane ZOSSOU. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "tesler"
8
+ gem.summary = "A little DSL to describe how to copy files inside a directory."
9
+ gem.description = "Tesler is a DSL which allows you to describe a directory hierarchy where to copy some files."
10
+ gem.email = "dev@raw1z.fr"
11
+ gem.homepage = "http://github.com/raw1z/tesler"
12
+ gem.authors = ["Rawane ZOSSOU"]
13
+ gem.add_development_dependency "shoulda", ">= 0"
14
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
15
+ end
16
+ Jeweler::GemcutterTasks.new
17
+ rescue LoadError
18
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
19
+ end
20
+
21
+ require 'rake/testtask'
22
+ Rake::TestTask.new(:test) do |test|
23
+ test.libs << 'lib' << 'test'
24
+ test.pattern = 'test/**/test_*.rb'
25
+ test.verbose = true
26
+ end
27
+
28
+ begin
29
+ require 'rcov/rcovtask'
30
+ Rcov::RcovTask.new do |test|
31
+ test.libs << 'test'
32
+ test.pattern = 'test/**/test_*.rb'
33
+ test.verbose = true
34
+ end
35
+ rescue LoadError
36
+ task :rcov do
37
+ abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
38
+ end
39
+ end
40
+
41
+ task :test => :check_dependencies
42
+
43
+ task :default => :test
44
+
45
+ require 'rake/rdoctask'
46
+ Rake::RDocTask.new do |rdoc|
47
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
48
+
49
+ rdoc.rdoc_dir = 'rdoc'
50
+ rdoc.title = "tesler #{version}"
51
+ rdoc.rdoc_files.include('README*')
52
+ rdoc.rdoc_files.include('lib/**/*.rb')
53
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1 @@
1
+ aaaaaaaaaaaaaa
File without changes
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1 @@
1
+ aaaaaaaaaaaaaa
data/example/main.rb ADDED
@@ -0,0 +1,41 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+
3
+ require 'tesler'
4
+
5
+ # on supprime le repertoire de destination
6
+ FileUtils.rm_r("dest") if File.exists?("dest")
7
+
8
+ directory 'dest' do
9
+
10
+ # copie de fichiers dans le dossier de destination
11
+ copy 'src\file1'
12
+ copy 'src\file2'
13
+ copy 'src\subdir1\file4'
14
+
15
+ # creation d'un sous-dossier dans le dossier de destination
16
+ directory 'subdir1' do
17
+ copy 'src\file3'
18
+ copy 'src\subdir1\file5'
19
+
20
+ # copie avec un chemin absolu
21
+ copy 'c:\temp'
22
+
23
+ # sous-dossier dans le sous-dossier
24
+ directory 'subdir3' do
25
+ copy 'src\file8'
26
+
27
+ # copie d'un fichier en le renommant
28
+ copy 'src\file9', :rename => 'renamed'
29
+ end
30
+ end
31
+
32
+ # copie d'un dossier entier
33
+ copy 'src\subdir2'
34
+
35
+ # copie d'un dossier entier en le renommant
36
+ copy 'src\subdir2', :rename => 'renamed'
37
+
38
+ end
39
+
40
+
41
+
data/example/src/file1 ADDED
File without changes
data/example/src/file2 ADDED
File without changes
data/example/src/file3 ADDED
File without changes
data/example/src/file8 ADDED
File without changes
data/example/src/file9 ADDED
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1 @@
1
+ aaaaaaaaaaaaaa
@@ -0,0 +1,11 @@
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
@@ -0,0 +1,38 @@
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
+
@@ -0,0 +1,35 @@
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
+
@@ -0,0 +1,11 @@
1
+ module Tesler
2
+ module Config
3
+ def self.output
4
+ @output ||= STDOUT
5
+ end
6
+
7
+ def self.output=(output)
8
+ @output = output
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,29 @@
1
+ module Tesler
2
+ class Copier
3
+ include Tesler::Commands::Run
4
+
5
+ def initialize(directory_name)
6
+ @directory_name = directory_name
7
+ set_directory(@directory_name)
8
+ end
9
+
10
+ def copy(file_name, options={})
11
+ if File.directory? file_name.to_unix
12
+ copy_dir(file_name.to_unix, options)
13
+ else
14
+ copy_file(file_name.to_unix, options)
15
+ end
16
+ end
17
+
18
+ def directory(directory_name, &block)
19
+ copier = Copier.new("#{@directory_name}/#{directory_name}")
20
+ copier.instance_eval(&block)
21
+ end
22
+
23
+ def self.directory(directory_name, &block)
24
+ copier = Copier.new(directory_name)
25
+ copier.instance_eval(&block)
26
+ end
27
+ end
28
+ end
29
+
data/lib/tesler/dsl.rb ADDED
@@ -0,0 +1,14 @@
1
+ def directory(directory_name, &block)
2
+ Tesler::Copier.directory(directory_name.to_unix, &block)
3
+ end
4
+
5
+ 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
13
+ end
14
+
data/lib/tesler/ext.rb ADDED
@@ -0,0 +1,6 @@
1
+ class String
2
+ def to_unix
3
+ File.join self.split("\\")
4
+ end
5
+ end
6
+
data/lib/tesler.rb ADDED
@@ -0,0 +1,8 @@
1
+ require File.join(File.dirname(__FILE__), "tesler", "ext")
2
+ 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")
6
+ require File.join(File.dirname(__FILE__), "tesler", "copier")
7
+ require File.join(File.dirname(__FILE__), "tesler", "dsl")
8
+
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'tesler'
8
+
9
+ class Test::Unit::TestCase
10
+ end
data/test/src/file1 ADDED
File without changes
data/test/src/file2 ADDED
File without changes
data/test/src/file3 ADDED
File without changes
data/test/src/file8 ADDED
File without changes
data/test/src/file9 ADDED
File without changes
File without changes
File without changes
File without changes
@@ -0,0 +1 @@
1
+ aaaaaaaaaaaaaa
@@ -0,0 +1,71 @@
1
+ require 'helper'
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
+ class TestTesler < Test::Unit::TestCase
14
+ def setup
15
+ FileUtils.rm_r("dest") if File.exists?("dest")
16
+
17
+ @output = Output.new
18
+ Tesler::Config.output = @output
19
+
20
+ directory 'test\dest' do
21
+ copy 'test\src\file1'
22
+ copy 'test\src\file2'
23
+ copy 'test\src\subdir1\file4'
24
+
25
+ directory 'subdir1' do
26
+ copy 'test\src\file3'
27
+ copy 'test\src\subdir1\file5'
28
+ copy 'c:\temp'
29
+
30
+ directory 'subdir3' do
31
+ copy 'test\src\file8'
32
+ copy 'test\src\file9', :rename => 'renamed'
33
+ end
34
+ end
35
+
36
+ copy 'test\src\subdir2'
37
+ copy 'test\src\subdir2', :rename => 'renamed'
38
+ end
39
+ end
40
+
41
+ should "copy files" do
42
+ assert File.exists?("test/dest")
43
+ assert File.exists?("test/dest/file1")
44
+ assert File.exists?("test/dest/file2")
45
+ assert File.exists?("test/dest/file4")
46
+ assert File.exists?("test/dest/subdir1")
47
+ assert File.exists?("test/dest/subdir1/file3")
48
+ assert File.exists?("test/dest/subdir1/file5")
49
+ assert File.exists?("test/dest/subdir1/temp")
50
+ assert File.exists?("test/dest/subdir1/subdir3")
51
+ assert File.exists?("test/dest/subdir1/subdir3/file8")
52
+ assert File.exists?("test/dest/subdir1/subdir3/renamed")
53
+ assert File.exists?("test/dest/subdir2")
54
+ assert File.exists?("test/dest/renamed")
55
+
56
+ messages = @output.messages.map { |m| m.strip }
57
+ assert_match messages[0], /(create|exists)\ttest\/dest/
58
+ assert_equal messages[1], "copy\ttest/dest/file1"
59
+ assert_equal messages[2], "copy\ttest/dest/file2"
60
+ assert_equal messages[3], "copy\ttest/dest/file4"
61
+ assert_match messages[4], /(create|exists)\ttest\/dest\/subdir1/
62
+ assert_equal messages[5], "copy\ttest/dest/subdir1/file3"
63
+ assert_equal messages[6], "copy\ttest/dest/subdir1/file5"
64
+ assert_equal messages[7], "copy\ttest/dest/subdir1/temp"
65
+ assert_match messages[8], /(create|exists)\ttest\/dest\/subdir1\/subdir3/
66
+ assert_equal messages[9], "copy\ttest/dest/subdir1/subdir3/file8"
67
+ assert_equal messages[10], "copy\ttest/dest/subdir1/subdir3/renamed"
68
+ assert_equal messages[11], "copy\ttest/dest/subdir2"
69
+ assert_equal messages[12], "copy\ttest/dest/renamed"
70
+ end
71
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tesler
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Rawane ZOSSOU
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-06-25 00:00:00 +02:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: shoulda
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :development
34
+ version_requirements: *id001
35
+ description: Tesler is a DSL which allows you to describe a directory hierarchy where to copy some files.
36
+ email: dev@raw1z.fr
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - LICENSE
43
+ - README.md
44
+ files:
45
+ - .document
46
+ - .gitignore
47
+ - LICENSE
48
+ - README.md
49
+ - Rakefile
50
+ - VERSION
51
+ - example/dest/file1
52
+ - example/dest/file2
53
+ - example/dest/file4
54
+ - example/dest/renamed/file6
55
+ - example/dest/renamed/file7
56
+ - example/dest/subdir1/file3
57
+ - example/dest/subdir1/file5
58
+ - example/dest/subdir1/subdir3/file8
59
+ - example/dest/subdir1/subdir3/renamed
60
+ - example/dest/subdir2/file6
61
+ - example/dest/subdir2/file7
62
+ - example/main.rb
63
+ - example/src/file1
64
+ - example/src/file2
65
+ - example/src/file3
66
+ - example/src/file8
67
+ - example/src/file9
68
+ - example/src/subdir1/file4
69
+ - example/src/subdir1/file5
70
+ - example/src/subdir2/file6
71
+ - example/src/subdir2/file7
72
+ - lib/tesler.rb
73
+ - lib/tesler/commands/base.rb
74
+ - lib/tesler/commands/logger.rb
75
+ - lib/tesler/commands/run.rb
76
+ - lib/tesler/config.rb
77
+ - lib/tesler/copier.rb
78
+ - lib/tesler/dsl.rb
79
+ - lib/tesler/ext.rb
80
+ - test/helper.rb
81
+ - test/src/file1
82
+ - test/src/file2
83
+ - test/src/file3
84
+ - test/src/file8
85
+ - test/src/file9
86
+ - test/src/subdir1/file4
87
+ - test/src/subdir1/file5
88
+ - test/src/subdir2/file6
89
+ - test/src/subdir2/file7
90
+ - test/test_tesler.rb
91
+ has_rdoc: true
92
+ homepage: http://github.com/raw1z/tesler
93
+ licenses: []
94
+
95
+ post_install_message:
96
+ rdoc_options:
97
+ - --charset=UTF-8
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ hash: 3
106
+ segments:
107
+ - 0
108
+ version: "0"
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ hash: 3
115
+ segments:
116
+ - 0
117
+ version: "0"
118
+ requirements: []
119
+
120
+ rubyforge_project:
121
+ rubygems_version: 1.3.7
122
+ signing_key:
123
+ specification_version: 3
124
+ summary: A little DSL to describe how to copy files inside a directory.
125
+ test_files:
126
+ - test/helper.rb
127
+ - test/test_tesler.rb