dir_dsl 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MzE5NmM3YjgxNjFiNzA2NWVmZThhNjk2NmM1NWFjMjE1NmZiZWFiMw==
4
+ MzZlZDc2YTZmYmE3NzRiYzE3OTQ2MDI4MTVkNDI2ZjRjNDQ0MTQ2NQ==
5
5
  data.tar.gz: !binary |-
6
- NGUzNjZjMGJlZjgyNDY3ODNjM2IwMTJkMjMxOGQyN2ViZjgwMTYyNQ==
6
+ OGRiOTZhODNhMDI1ZDNiYmYwNzBjNDliODhjMzMxOTFhMDRiOWU5OA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- N2ZjNWQ2NWYwOTBhMDIwMmM3YTM5YWFiYjgwYjhiZjUwMWI4MTYwODdkZmQw
10
- N2U2MzgzZmY0ZGRjMDkxYWYyZTRmMjUwNmE5OTZlMTBkMjBjYzk5NjMyNTIx
11
- NTAyZDA2ZTMyYTI4NWEyMDljNTFmMTcwYzQyNWNjNDVkMGVhNGU=
9
+ MmFlN2MxOTU5MTMzYTE1ODZlZmMyNGE3NWU2NzFiM2IxZjJmMzM2OGQxZWMw
10
+ NTNiOTAxMTFhNWZkMjE1YmUxMjE4NWMyYzAxYTdhYWY3MmNhNTVjYzUyY2Nh
11
+ NGQ0OTBmYjYyMGMyNjIzMjNmZWZkMDdkNTM3MmQyZmY4YzE1MDE=
12
12
  data.tar.gz: !binary |-
13
- YThlYWYzZTE2YmIxMjgwZTJiZWVhYzI1OTNlZWZkNjBiMGM0ODE0N2RmZWFh
14
- Yzk1NmY0NDA4OWE4MmIxMTM3ODk2MWE5Njg0ZWUwNzc1MTZhZjkxYWYxZTI2
15
- MzBmODE1ZjhhMmY5NDY2ODQ2MzAyZjlhZjk4YWFjMWYzMzI4OGY=
13
+ ZDViMTJiMTFiNjZkMzgxOTFhYzQzN2RhYzQ0YzE5N2JkNzMxYTQ2ZjVhYTRl
14
+ MTM3NTc0Zjc1YmNkZjdjNDZmNzkwMzg1YzQxZDQwZjM4NDY4MTUxMTQ4ZGI0
15
+ OTY5YzU3OGM0NmVjZDcyNDZhOGNmYTJlNTBiMjM3ZDNkNjExOTk=
data/CHANGES CHANGED
@@ -6,4 +6,8 @@
6
6
 
7
7
  == Version 1.0.1
8
8
 
9
+ * Bug fixes.
10
+
11
+ == Version 1.0.2
12
+
9
13
  * Bug fixes.
@@ -8,12 +8,17 @@ class DirDSL
8
8
  def initialize from_root, to_root
9
9
  @from_root = File.expand_path(from_root)
10
10
  @to_root = File.expand_path(to_root)
11
+ @global_ignores = []
11
12
  end
12
13
 
13
14
  def build(&block)
14
15
  self.instance_eval(&block)
15
16
  end
16
17
 
18
+ def global_ignore ignore
19
+ @global_ignores << ignore
20
+ end
21
+
17
22
  def entry_exist? entry_name
18
23
  File.exist? "#{to_root}/#{entry_name}"
19
24
  end
@@ -30,7 +35,7 @@ class DirDSL
30
35
  end
31
36
 
32
37
  def list dir="."
33
- list = pattern_to_files"#{from_root}/#{dir}", "**/*"
38
+ list = pattern_to_files "#{from_root}/#{dir}", "**/*"
34
39
 
35
40
  list.each_with_index do |name, index|
36
41
  list[index] = name["#{from_root}/#{dir}".length+1..-1]
@@ -59,11 +64,7 @@ class DirDSL
59
64
  end
60
65
 
61
66
  def directory params
62
- if params[:from_dir].nil?
63
- to_dir = "#{to_root}/#{params[:to_dir]}"
64
-
65
- create_directory to_dir unless File.exist? to_dir
66
- else
67
+ if params[:from_dir]
67
68
  if params[:to_dir] == "." || params[:to_dir].nil?
68
69
  to_dir = params[:from_dir]
69
70
  else
@@ -71,22 +72,74 @@ class DirDSL
71
72
  end
72
73
 
73
74
  filter = params[:filter].nil? ? "**/*" : params[:filter]
75
+ excludes = parse_excludes(params[:excludes])
76
+
77
+ copy_files_with_excludes "#{from_root}/#{params[:from_dir]}", "#{to_root}/#{to_dir}", filter, excludes
78
+ else
79
+ to_dir = "#{to_root}/#{params[:to_dir]}"
74
80
 
75
- copy_files "#{from_root}/#{params[:from_dir]}", "#{to_root}/#{to_dir}", filter
81
+ create_directory to_dir unless File.exist? to_dir
76
82
  end
77
83
  end
78
84
 
79
85
  private
80
86
 
81
87
  def to_dir dir, name
82
- if dir.nil?
83
- from_dir = File.dirname(name)
84
- to_dir = (from_dir == ".") ? to_root : "#{to_root}/#{from_dir}"
88
+ dir = File.dirname(name) unless dir
89
+
90
+ if dir == "."
91
+ to_root
92
+ else
93
+ "#{to_root}/#{dir}"
94
+ end
95
+ end
96
+
97
+ def parse_excludes excludes
98
+ if excludes
99
+ excludes.split(",").map(&:strip)
85
100
  else
86
- to_dir = (dir == ".") ? to_root : "#{to_root}/#{dir}"
101
+ []
102
+ end
103
+ end
104
+
105
+ def copy_files_with_excludes from_dir, to_dir, pattern, excludes
106
+ create_directory to_dir
107
+
108
+ files = pattern_to_files from_dir, pattern
109
+
110
+ files.each do |file|
111
+ if File.file? file and not file_excluded(file, excludes)
112
+ FileUtils.cp(file, to_dir)
113
+ elsif File.directory?(file) and not dir_in_global_ignores(file, @global_ignores)
114
+ FileUtils.mkdir_p file
115
+ end
116
+ end
117
+ end
118
+
119
+ def dir_in_global_ignores dir, global_ignores
120
+ ignored = false
121
+
122
+ global_ignores.each do |exclude|
123
+ if dir =~ /#{exclude}/
124
+ ignored = true
125
+ break
126
+ end
127
+ end
128
+
129
+ ignored
130
+ end
131
+
132
+ def file_excluded(file, excludes)
133
+ excluded = false
134
+
135
+ excludes.each do |exclude|
136
+ if file =~ /#{exclude}/
137
+ excluded = true
138
+ break
139
+ end
87
140
  end
88
141
 
89
- to_dir
142
+ excluded
90
143
  end
91
144
 
92
145
  end
@@ -1,3 +1,3 @@
1
1
  class DirDSL
2
- VERSION = "1.0.1"
2
+ VERSION = "1.0.2"
3
3
  end
data/spec/dir_dsl_spec.rb CHANGED
@@ -69,7 +69,7 @@ describe DirDSL do
69
69
  directory :from_dir => "spec"
70
70
  end
71
71
 
72
- subject.list("spec").should include "spec_helper.rb"
72
+ subject.entry_exist?("spec/spec_helper.rb").should be_true
73
73
  end
74
74
 
75
75
  it "should display files in specified subdirectory" do
@@ -77,7 +77,15 @@ describe DirDSL do
77
77
  directory :from_dir => "lib"
78
78
  end
79
79
 
80
- subject.list("lib/dir_dsl").first.should =~ %r{dir_dsl.rb}
80
+ subject.entry_exist?("lib/dir_dsl.rb").should be_true
81
+ end
82
+
83
+ it "should exclude files from result" do
84
+ subject.build do
85
+ directory :from_dir => "lib", :excludes => "version.rb"
86
+ end
87
+
88
+ subject.entry_exist?("lib/version.rb").should be_false
81
89
  end
82
90
 
83
91
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dir_dsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander Shvets