metacrunch-file 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Readme.md +16 -2
- data/lib/metacrunch/file.rb +1 -0
- data/lib/metacrunch/file/destination.rb +36 -0
- data/lib/metacrunch/file/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c5561aee710c9450372e675cd2f528f0024d1b41
|
4
|
+
data.tar.gz: 960154bbd9225493784f55b6750ef08bc665c047
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf579706cde53758b82c5d833be4bc05e064532488c642600624c168f5cfb1eaeecd7cb80bbe006b58161633c4d7f7bdea0be9fb74655370308dc0fc167ebacf
|
7
|
+
data.tar.gz: c67526eb2803612c36940220554704c73238e7424168bfce67c9741baa163fee20992e4512e8b4085516c5c61fcb4cd5b2f27a8c850efffad35c8268993d03e3
|
data/Readme.md
CHANGED
@@ -14,7 +14,7 @@ Installation
|
|
14
14
|
Include the gem in your `Gemfile`
|
15
15
|
|
16
16
|
```ruby
|
17
|
-
gem "metacrunch-file", "~> 1.
|
17
|
+
gem "metacrunch-file", "~> 1.2.0"
|
18
18
|
```
|
19
19
|
|
20
20
|
and run `$ bundle install` to install it.
|
@@ -67,12 +67,26 @@ transformation ->(file_entry) do
|
|
67
67
|
end
|
68
68
|
```
|
69
69
|
|
70
|
+
### `Metacrunch::File::Destination`
|
71
|
+
|
72
|
+
This class provides a metacrunch `destination` to write data to a file. Every data that gets passed to the destination is appended to the given file. If the data is an `Array` every element of that array is appended to the file. Non existing files will be created automatically.
|
73
|
+
|
74
|
+
```ruby
|
75
|
+
# my_job.metacrunch
|
76
|
+
|
77
|
+
source Metacrunch::File::Destination.new("/tmp/my-data.txt" [, OPTIONS])
|
78
|
+
```
|
79
|
+
|
80
|
+
**Options**
|
81
|
+
|
82
|
+
* `override_existing_file`: Overrides an existing file if set to `true`. If set to `false` an error is raised if the file already exists. Defaults to `false`.
|
83
|
+
*
|
70
84
|
|
71
85
|
### `Metacrunch::File::XLSXDestination`
|
72
86
|
|
73
87
|
This class provides a metacrunch `destination` implementation to create simple Excel (xlsx) files.
|
74
88
|
|
75
|
-
To use this destination a transformation is required to format the data in a proper array that can be
|
89
|
+
To use this destination a transformation is required to format the data in a proper array that can be passed to the destination. When defining the destination you must provide an array of column names. Each data row passed to the destination must be an array of the same size as the column array.
|
76
90
|
|
77
91
|
```ruby
|
78
92
|
# my_job.metacrunch
|
data/lib/metacrunch/file.rb
CHANGED
@@ -0,0 +1,36 @@
|
|
1
|
+
require "metacrunch/file"
|
2
|
+
|
3
|
+
module Metacrunch
|
4
|
+
class File::Destination
|
5
|
+
|
6
|
+
DEFAULT_OPTIONS = {
|
7
|
+
override_existing_file: false
|
8
|
+
}
|
9
|
+
|
10
|
+
def initialize(filename, options = {})
|
11
|
+
@filename = ::File.expand_path(filename)
|
12
|
+
@options = DEFAULT_OPTIONS.deep_merge(options)
|
13
|
+
|
14
|
+
if ::File.exists?(@filename) && @options[:override_existing_file] == false
|
15
|
+
raise "File `#{@filename}` exists but `override_existing_file` option was set to `false`"
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def write(data)
|
20
|
+
return if data.blank?
|
21
|
+
|
22
|
+
if data.is_a?(Array)
|
23
|
+
::File.open(@filename, 'ab+') do |file|
|
24
|
+
data.each { |row| file.write(row) }
|
25
|
+
end
|
26
|
+
else
|
27
|
+
::File.open(@filename, 'ab+') { |file| file.write(data) }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def close
|
32
|
+
# noop
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: metacrunch-file
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- René Sprotte
|
@@ -53,6 +53,7 @@ files:
|
|
53
53
|
- Readme.md
|
54
54
|
- bin/console
|
55
55
|
- lib/metacrunch/file.rb
|
56
|
+
- lib/metacrunch/file/destination.rb
|
56
57
|
- lib/metacrunch/file/entry.rb
|
57
58
|
- lib/metacrunch/file/source.rb
|
58
59
|
- lib/metacrunch/file/version.rb
|