dnnbundler 0.1.4 → 0.1.5

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 38fb92f25f2f1562aa75bc843eefed30a8da7e67
4
- data.tar.gz: 75d959d795f88459d38a75d4825cbfed3d235c73
3
+ metadata.gz: 6cbe59e15b822d31c419850068808fed5beff93c
4
+ data.tar.gz: 81af67b4728e1b4b3faafc7f9e022f2f2f682c26
5
5
  SHA512:
6
- metadata.gz: ea1801bd3d89ec4b032576b978fef3db985ed9bc14f46df557cb2606bd7563f198ed29bbaa6f37b1b035590f3ff02f88573bb3b314afb1276df45a36f3f56158
7
- data.tar.gz: 8a5218f18c49447b8fe28fe487eadd284fd082bdbc249d35b9a05d3654169b85fdcdbc85093a420d2140e71c361e2aa28271223ae6ab953b8d34fa15a629d3c4
6
+ metadata.gz: cd9620df2a3ea1da99998d72c151c10b2f524dfa91f4a1d1867866953dcfdc3c5e9567c7dec110832d1d438fd77dddec8ae50a2f5ff21b0b497e7c6ed4de4527
7
+ data.tar.gz: 5a9e95a2486189732827739d50c7545f214fe3882bf4a703924446df7d551c4014d5a1802429bb3eee1ca61686038b691570378a67d36d14038e4fdcd6914e6b
data/README.md CHANGED
@@ -30,13 +30,13 @@ To configure packaging create a json config with the following schema:
30
30
  "path_to_file",
31
31
  "path_to_directory", // real path in file system to file or directory
32
32
  {
33
- "type": "file", // type of entry
33
+ "type": "file", // type of entry, if absent will be treated as 'file'
34
34
  "name": "test.json", // real path in file system to file or directory
35
35
  "path": "new_path_in_zip" // optional
36
36
  },
37
37
  {
38
38
  "type": "zip", // nested zip archive
39
- "name": "test.zip", // name of nested zip archive, can include directories
39
+ "name": "test.zip", // name of nested zip archive, can include directories. 'path' property is being ignored for this kind of entries
40
40
  "ignoreEntries": [ ... ] // local array of entries to ignore
41
41
  "entries": [ // array of entries for nested zip file, same format as above
42
42
  "file",
@@ -1,3 +1,3 @@
1
1
  module Dnnbundler
2
- VERSION = "0.1.4"
2
+ VERSION = "0.1.5"
3
3
  end
@@ -21,22 +21,23 @@ module Dnnbundler
21
21
  private
22
22
 
23
23
  # True if +fileEntry+ isn't included into +ignore_entries+ array'
24
- def filter_entries(fileEntry, ignore_entries)
24
+ def filter_entries(fileEntryName, fileEntryType, ignore_entries)
25
25
  return true if ignore_entries == nil
26
26
  ignore_entries.each do |entry|
27
- return false if (fileEntry.type.casecmp(FileEntryType::FILE) != 0) && (fileEntry.name.include? entry)
27
+ return false if (fileEntryType.casecmp(FileEntryType::FILE) == 0) && (fileEntryName.include? entry)
28
28
  end
29
+ return true
29
30
  end
30
31
 
31
32
  # Creates +FileEntry+ for file or array of entries for directory and subdirectories
32
33
  # Params:
33
34
  # +directory_or_file+:: path to directory or file
34
35
  # +entry_path+:: path with which the entry should be put into zip
35
- def get_entries(directory_or_file, entry_path)
36
+ def get_entries(directory_or_file, entry_path, ignore_entries)
36
37
  if File.directory? directory_or_file
37
- get_dir_entries_recursively directory_or_file, entry_path
38
+ get_dir_entries_recursively directory_or_file, entry_path, ignore_entries
38
39
  else
39
- FileEntry.new directory_or_file, entry_path
40
+ FileEntry.new directory_or_file, FileEntryType::FILE, false, entry_path
40
41
  end
41
42
  end
42
43
 
@@ -45,14 +46,13 @@ module Dnnbundler
45
46
  # +dir+:: start directory
46
47
  # +entry_path+:: path with which file should be placed into zip
47
48
  # +replace_path+:: part of path which is being replaced by +entry_path+
48
- def get_dir_entries_recursively(dir, entry_path, replace_path = nil)
49
- replace_path = dir if replace_path == nil
50
- (Dir.entries(dir) - %w(. ..)).map { |v|
51
- path = File.join(dir, v)
49
+ def get_dir_entries_recursively(dir, entry_path, ignore_entries, replace_path = nil)
50
+ replace_path = dir.clone if replace_path.nil?
51
+ (Dir.entries(dir) - %w(. ..)).map { |v| File.join(dir, v) }.select { |path| filter_entries path, FileEntryType::FILE, ignore_entries }.map { |path|
52
52
  if File.directory? path
53
- get_dir_entries_recursively(path, entry_path, replace_path)
53
+ get_dir_entries_recursively(path, entry_path, ignore_entries, replace_path)
54
54
  else
55
- entry_path_in_zip = path.sub(replace_path, entry_path).gsub(/^[\/\\]+/, "")
55
+ entry_path_in_zip = (entry_path.nil? ? path : path.sub(replace_path, entry_path)).gsub(/^[\/\\]+/, "")
56
56
  FileEntry.new path, FileEntryType::FILE, false, entry_path_in_zip
57
57
  end
58
58
  }
@@ -62,14 +62,14 @@ module Dnnbundler
62
62
  # Params:
63
63
  # +entries+:: array of +FileEntry+ objects
64
64
  def compress(entries)
65
- puts "adding the following entries into zip package"
66
- puts "#{ entries.map{ |x| x.name + ", " + x.path.to_s }.join("\n")}"
65
+ puts "\nadding the following entries into zip package"
66
+ puts "#{ entries.map{ |x| x.name + ", " + x.path.to_s + ", " + x.type.to_s }.join("\n")}"
67
67
  buffer = Zip::File.add_buffer do |zio|
68
68
  entries.each do |file|
69
69
  if file.type.casecmp(FileEntryType::FILE) == 0
70
70
  zio.add(file.path == nil ? file.name : file.path, file.name)
71
71
  else
72
- zio.get_output_stream(file.path == nil ? file.name : file.path) { |os| os.write file.buffer.string }
72
+ zio.get_output_stream(file.name) { |os| os.write file.buffer.string }
73
73
  end
74
74
  end
75
75
  end
@@ -79,15 +79,15 @@ module Dnnbundler
79
79
  def create_zip(entries, ignore_entries)
80
80
  compress entries.map { |x|
81
81
  if x.is_a? String
82
- get_entries x, nil
83
- elsif x[JsonConfig::Type].casecmp(FileEntryType::FILE) == 0
84
- get_entries x[JsonConfig::Name], x[JsonConfig::Path]
82
+ get_entries x, nil, ignore_entries
83
+ elsif x[JsonConfig::Type].nil? || x[JsonConfig::Type].casecmp(FileEntryType::FILE) == 0
84
+ get_entries x[JsonConfig::Name], x[JsonConfig::Path], ignore_entries
85
85
  elsif x[JsonConfig::Type].casecmp(FileEntryType::ZIP) == 0
86
86
  zip_file_entry = FileEntry.new x[JsonConfig::Name], FileEntryType::ZIP, false, x[JsonConfig::Path]
87
87
  zip_file_entry.add_buffer create_zip x[JsonConfig::Entries], x[JsonConfig::IgnoreEntries]
88
88
  result = zip_file_entry
89
89
  end
90
- }.flatten.select{ |f| filter_entries f, ignore_entries }.uniq{ |f| f.name }
90
+ }.flatten.select{ |f| filter_entries f.name, f.type, ignore_entries }.uniq{ |f| f.name }
91
91
  end
92
92
  end
93
93
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dnnbundler
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Le0Michine