Class: ZipDirectory
Constant Summary
collapse
- TaskName =
:zip
Instance Attribute Summary collapse
Attributes included from Logging
#current_log_device, #logger
Instance Method Summary
collapse
clean_dirname, create_rake_task, include_config, included
#<<, #update_attributes
Methods included from YAMLConfig
#configure, #load_config_by_task_name
Methods included from Logging
#create_logger, #log_device=, #log_level, #log_level=
Methods included from Failure
#fail_with_message
Constructor Details
Returns a new instance of ZipDirectory.
14
15
16
17
18
19
|
# File 'lib/albacore/zipdirectory.rb', line 14
def initialize
@flatten_zip = true
@exclusions = []
super()
update_attributes Albacore.configuration.zip.to_hash
end
|
Instance Attribute Details
#flatten_zip ⇒ Object
Returns the value of attribute flatten_zip.
11
12
13
|
# File 'lib/albacore/zipdirectory.rb', line 11
def flatten_zip
@flatten_zip
end
|
#output_file ⇒ Object
Returns the value of attribute output_file.
10
11
12
|
# File 'lib/albacore/zipdirectory.rb', line 10
def output_file
@output_file
end
|
#output_path ⇒ Object
Returns the value of attribute output_path.
10
11
12
|
# File 'lib/albacore/zipdirectory.rb', line 10
def output_path
@output_path
end
|
Instance Method Details
#clean_directories_names ⇒ Object
34
35
36
37
|
# File 'lib/albacore/zipdirectory.rb', line 34
def clean_directories_names
return if @directories_to_zip.nil?
@directories_to_zip.each { |d| d.sub!(%r[/$],'')}
end
|
#execute ⇒ Object
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/albacore/zipdirectory.rb', line 21
def execute()
fail_with_message 'Output File cannot be empty' if @output_file.nil?
return if @output_file.nil?
clean_directories_names
remove zip_name
ZipFile.open(zip_name, 'w') do |zipfile|
zip_directory(zipfile)
zip_additional(zipfile)
end
end
|
#expanded_exclusions ⇒ Object
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
|
# File 'lib/albacore/zipdirectory.rb', line 54
def expanded_exclusions
return @expanded_exclusions unless @expanded_exclusions.nil?
regexp_exclusions, string_exclusions = @exclusions.partition {|x| x.respond_to? '~' }
@expanded_exclusions = [].concat(regexp_exclusions)
@directories_to_zip.each do |dir|
Dir.chdir(dir) do
string_exclusions.each do |ex|
exclusions = Dir.glob(ex)
exclusions = exclusions.map {|x| File.join(dir, x) } unless exclusions[0] == ex
exclusions << ex if exclusions.empty?
@expanded_exclusions += exclusions
end
end
end
@expanded_exclusions
end
|
#is_excluded(f) ⇒ Object
47
48
49
50
51
52
|
# File 'lib/albacore/zipdirectory.rb', line 47
def is_excluded(f)
expanded_exclusions.any? do |e|
return true if e.respond_to? '~' and f =~ e
e == f
end
end
|
#reject_file(f) ⇒ Object
43
44
45
|
# File 'lib/albacore/zipdirectory.rb', line 43
def reject_file(f)
f == zip_name || is_excluded(f)
end
|
#remove(filename) ⇒ Object
39
40
41
|
# File 'lib/albacore/zipdirectory.rb', line 39
def remove(filename)
FileUtils.rm filename, :force=>true
end
|
#set_output_path ⇒ Object
79
80
81
82
83
84
|
# File 'lib/albacore/zipdirectory.rb', line 79
def set_output_path()
path = ''
path = @directories_to_zip.first unless @directories_to_zip.nil?
path = @output_path unless @output_path.nil?
return path
end
|
#zip_additional(zipfile) ⇒ Object
98
99
100
101
102
103
104
105
|
# File 'lib/albacore/zipdirectory.rb', line 98
def zip_additional(zipfile)
return if @additional_files.nil?
@additional_files = Array.[](@additional_files).flatten
@additional_files.reject{|f| reject_file(f)}.each do |file_path|
file_name = file_path.split('/').last if @flatten_zip
zipfile.add(file_name, file_path)
end
end
|
#zip_directory(zipfile) ⇒ Object
87
88
89
90
91
92
93
94
95
96
|
# File 'lib/albacore/zipdirectory.rb', line 87
def zip_directory(zipfile)
return if @directories_to_zip.nil?
@directories_to_zip.each do |d|
Dir["#{d}/**/**"].reject{|f| reject_file(f)}.each do |file_path|
file_name = file_path
file_name = file_path.sub(d + '/','') if @flatten_zip
zipfile.add(file_name, file_path)
end
end
end
|
#zip_name ⇒ Object
74
75
76
77
|
# File 'lib/albacore/zipdirectory.rb', line 74
def zip_name()
@output_path = set_output_path
File.join(@output_path, @output_file)
end
|