Navigation Menu

Skip to content

Commit

Permalink
auto-generate templates
Browse files Browse the repository at this point in the history
  • Loading branch information
TAKEI Yuya committed Feb 26, 2015
1 parent 9f1d85e commit ae08d6b
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
@@ -0,0 +1,5 @@
*~
/pkg/
/tmp/
/.bundle/
/Gemfile.lock
2 changes: 2 additions & 0 deletions Gemfile
@@ -0,0 +1,2 @@
source 'https://rubygems.org/'
gemspec
21 changes: 21 additions & 0 deletions LICENSE.txt
@@ -0,0 +1,21 @@

MIT License

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 changes: 31 additions & 0 deletions README.md
@@ -0,0 +1,31 @@
# Jsonl formatter plugin for Embulk

TODO: Write short description here

## Overview

* **Plugin type**: formatter
* **Load all or nothing**: yes
* **Resume supported**: no

## Configuration

- **property1**: description (string, required)
- **property2**: description (integer, default: default-value)

## Example

```yaml
out:
type: any output input plugin type
formatter:
type: jsonl
property1: example1
property2: example2
```

## Build

```
$ rake
```
1 change: 1 addition & 0 deletions Rakefile
@@ -0,0 +1 @@
require "bundler/gem_tasks"
19 changes: 19 additions & 0 deletions embulk-formatter-jsonl.gemspec
@@ -0,0 +1,19 @@

Gem::Specification.new do |spec|
spec.name = "embulk-formatter-jsonl"
spec.version = "0.1.0"
spec.authors = ["TAKEI Yuya"]
spec.summary = "Jsonl formatter plugin for Embulk"
spec.description = ""
spec.email = ["takei+github@preferred.jp"]
spec.licenses = ["MIT"]
# TODO: spec.homepage = "https://github.com/takei+github/embulk-formatter-jsonl"

spec.files = `git ls-files`.split("\n") + Dir["classpath/*.jar"]
spec.test_files = spec.files.grep(%r{^(test|spec)/})
spec.require_paths = ["lib"]

#spec.add_dependency 'YOUR_GEM_DEPENDENCY', ['~> YOUR_GEM_DEPENDENCY_VERSION']
spec.add_development_dependency 'bundler', ['~> 1.0']
spec.add_development_dependency 'rake', ['>= 10.0']
end
47 changes: 47 additions & 0 deletions lib/embulk/formatter/jsonl.rb
@@ -0,0 +1,47 @@
module Embulk
module Formatter

class JsonlFormatterPlugin < FormatterPlugin
Plugin.register_formatter("jsonl", self)

def self.transaction(config, schema, &control)
# configuration code:
task = {
"property1" => config.param("property1", :string),
"property2" => config.param("property2", :integer, default: 0),
}

yield(task)
end

def init
# initialization code:
@property1 = task["property1"]
@property2 = task["property2"]

# your data
@current_file == nil
@current_file_size = 0
end

def close
end

def add(page)
# output code:
page.each do |record|
if @current_file == nil || @current_file_size > 32*1024
@current_file = file_output.next_file
@current_file_size = 0
end
@current_file.write "|mydata|"
end
end

def finish
file_output.finish
end
end

end
end

0 comments on commit ae08d6b

Please sign in to comment.