metacrunch-file 1.0.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 555569202d70aa4a0553d8d3c5ffa7396379e84d
4
+ data.tar.gz: f3709c10ca420fed0ab6e3ba9f8b6caf1f2ba6c4
5
+ SHA512:
6
+ metadata.gz: e89c3de4bde0f2c03962e44b061aa49069c96c8f7672a2f3954e97e00104977e28699defeb0741986f9379af1b86632b8613b5aad2580ed2e0e9a05e93c058b9
7
+ data.tar.gz: c8c17793d191d8aa21e76fc15505e82f3522a2df3009b108d83af8eb10e61112525337bc759a6bfcf3f2c4f3b39c1ac0d8c1e866c90febf32a35b0a3f79e3560
@@ -0,0 +1,24 @@
1
+ .DS_Store
2
+ /doc
3
+ *.gem
4
+ *.rbc
5
+ .bundle
6
+ .config
7
+ .yardoc
8
+ Gemfile.lock
9
+ InstalledFiles
10
+ _yardoc
11
+ coverage
12
+ doc/
13
+ lib/bundler/man
14
+ pkg
15
+ rdoc
16
+ spec/reports
17
+ test/tmp
18
+ test/version_tmp
19
+ tmp
20
+ *.bundle
21
+ *.so
22
+ *.o
23
+ *.a
24
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format documentation
3
+ --require spec_helper
data/Gemfile ADDED
@@ -0,0 +1,17 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ group :development do
6
+ gem "bundler", ">= 1.15"
7
+ gem "rake", ">= 12.1"
8
+ gem "rspec", ">= 3.5.0", "< 4.0.0"
9
+
10
+ if !ENV["CI"]
11
+ gem "pry-byebug", ">= 3.5.0"
12
+ end
13
+ end
14
+
15
+ group :test do
16
+ gem "simplecov", ">= 0.15.0"
17
+ end
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2017 René Sprotte
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,6 @@
1
+ require "rspec/core/rake_task"
2
+ require "bundler/gem_tasks"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ require "bundler/setup"
3
+ require "metacrunch/file"
4
+
5
+ begin
6
+ require "pry"
7
+ rescue LoadError ; end
8
+
9
+ if defined?(Pry)
10
+ Pry.start
11
+ else
12
+ require "irb"
13
+ IRB.start
14
+ end
@@ -0,0 +1,9 @@
1
+ require "active_support"
2
+ require "active_support/core_ext"
3
+
4
+ module Metacrunch
5
+ module File
6
+ require_relative "file/entry"
7
+ require_relative "file/source"
8
+ end
9
+ end
@@ -0,0 +1,19 @@
1
+ require "metacrunch/file"
2
+
3
+ module Metacrunch
4
+ class File::Entry
5
+
6
+ attr_reader :filename, :archive_filename, :contents
7
+
8
+ def initialize(filename:, archive_filename: nil, contents: nil)
9
+ @filename = filename
10
+ @archive_filename = archive_filename.presence
11
+ @contents = contents
12
+ end
13
+
14
+ def from_archive?
15
+ @archive_filename != nil
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,56 @@
1
+ require "metacrunch/file"
2
+ require "rubygems/package"
3
+
4
+ module Metacrunch
5
+ class File::Source
6
+
7
+ def initialize(filenames)
8
+ @filenames = [*filenames].map{|f| f.presence}.compact
9
+ end
10
+
11
+ def each(&block)
12
+ return enum_for(__method__) unless block_given?
13
+
14
+ @filenames.each do |filename|
15
+ if is_archive?(filename)
16
+ read_archive(filename, &block)
17
+ else
18
+ read_regular_file(filename, &block)
19
+ end
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def is_archive?(filename)
26
+ filename.ends_with?(".tar") || filename.ends_with?(".tar.gz") || filename.ends_with?(".tgz")
27
+ end
28
+
29
+ def is_gzip_file?(filename)
30
+ filename.ends_with?(".gz") || filename.ends_with?(".tgz")
31
+ end
32
+
33
+ def read_regular_file(filename, &block)
34
+ if ::File.file?(filename)
35
+ io = is_gzip_file?(filename) ? Zlib::GzipReader.open(filename) : ::File.open(filename, "r")
36
+ yield File::Entry.new(filename: filename, archive_filename: nil, contents: io.read)
37
+ end
38
+ end
39
+
40
+ def read_archive(filename, &block)
41
+ io = is_gzip_file?(filename) ? Zlib::GzipReader.open(filename) : ::File.open(filename, "r")
42
+ tarReader = Gem::Package::TarReader.new(io)
43
+
44
+ tarReader.each do |_tar_entry|
45
+ if _tar_entry.file?
46
+ yield File::Entry.new(
47
+ filename: filename,
48
+ archive_filename: _tar_entry.full_name,
49
+ contents: _tar_entry.read
50
+ )
51
+ end
52
+ end
53
+ end
54
+
55
+ end
56
+ end
@@ -0,0 +1,6 @@
1
+
2
+ module Metacrunch
3
+ module File
4
+ VERSION = "1.0.0"
5
+ end
6
+ end
@@ -0,0 +1,19 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "metacrunch/file/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "metacrunch-file"
8
+ spec.version = Metacrunch::File::VERSION
9
+ spec.authors = ["René Sprotte"]
10
+ spec.summary = %q{File package for the metacrunch ETL toolkit.}
11
+ spec.homepage = "http://github.com/ubpb/metacrunch-file"
12
+ spec.license = "MIT"
13
+
14
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
15
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
16
+ spec.require_paths = ["lib"]
17
+
18
+ spec.add_dependency "activesupport", ">= 5.1.0"
19
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: metacrunch-file
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - René Sprotte
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-09-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 5.1.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 5.1.0
27
+ description:
28
+ email:
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - ".gitignore"
34
+ - ".rspec"
35
+ - Gemfile
36
+ - License.txt
37
+ - Rakefile
38
+ - bin/console
39
+ - lib/metacrunch/file.rb
40
+ - lib/metacrunch/file/entry.rb
41
+ - lib/metacrunch/file/source.rb
42
+ - lib/metacrunch/file/version.rb
43
+ - metacrunch-file.gemspec
44
+ homepage: http://github.com/ubpb/metacrunch-file
45
+ licenses:
46
+ - MIT
47
+ metadata: {}
48
+ post_install_message:
49
+ rdoc_options: []
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ required_rubygems_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ requirements: []
63
+ rubyforge_project:
64
+ rubygems_version: 2.6.11
65
+ signing_key:
66
+ specification_version: 4
67
+ summary: File package for the metacrunch ETL toolkit.
68
+ test_files: []