data-pipeline 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 1eb0de763402a41bcefac5aac42158fc5107e4cf773b6fa15712426ece38985f
4
+ data.tar.gz: c4741176a480a08e8c651f1305038200c08dadaa2a328bf18a92b92ca0f3cd24
5
+ SHA512:
6
+ metadata.gz: b6bbf4e0d2c0ffb95ea55999e624fde5de72221116d1ecceafe5991588daf2f44a2b38ca561a06d5f252d09a3f60313c5640237f54fbab265891ce6ce6234300
7
+ data.tar.gz: 0ad3de0e821e851bd55800d29d4752a58bee46e9ef28c4a494f9614624d8cda8bc4541e513c25176e2291ce2aa4b564efb72e9ba0f6b77983fd1463b8c93bb09
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.1
7
+ before_install: gem install bundler -v 1.16.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at ckyeo.1@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in pipeline.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,50 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ data-pipeline (0.1.0)
5
+
6
+ GEM
7
+ remote: https://rubygems.org/
8
+ specs:
9
+ ansi (1.5.0)
10
+ diff-lcs (1.3)
11
+ docile (1.3.1)
12
+ hirb (0.7.3)
13
+ json (2.1.0)
14
+ rake (10.5.0)
15
+ rspec (3.8.0)
16
+ rspec-core (~> 3.8.0)
17
+ rspec-expectations (~> 3.8.0)
18
+ rspec-mocks (~> 3.8.0)
19
+ rspec-core (3.8.0)
20
+ rspec-support (~> 3.8.0)
21
+ rspec-expectations (3.8.1)
22
+ diff-lcs (>= 1.2.0, < 2.0)
23
+ rspec-support (~> 3.8.0)
24
+ rspec-mocks (3.8.0)
25
+ diff-lcs (>= 1.2.0, < 2.0)
26
+ rspec-support (~> 3.8.0)
27
+ rspec-support (3.8.0)
28
+ simplecov (0.16.1)
29
+ docile (~> 1.1)
30
+ json (>= 1.8, < 3)
31
+ simplecov-html (~> 0.10.0)
32
+ simplecov-console (0.4.2)
33
+ ansi
34
+ hirb
35
+ simplecov
36
+ simplecov-html (0.10.2)
37
+
38
+ PLATFORMS
39
+ ruby
40
+
41
+ DEPENDENCIES
42
+ bundler (~> 1.16)
43
+ data-pipeline!
44
+ rake (~> 10.0)
45
+ rspec (~> 3.0)
46
+ simplecov (~> 0.16.1)
47
+ simplecov-console (~> 0.4.2)
48
+
49
+ BUNDLED WITH
50
+ 1.16.4
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Chee Yeo
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,141 @@
1
+ # Pipeline
2
+
3
+ Pipeline is a gem that enables you to build `operations` to transform data from one state to another using `pipelines`
4
+
5
+ This is based on the [chain-of-responsibility pattern](https://en.wikipedia.org/wiki/Chain-of-responsibility_pattern)
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'data-pipeline'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install data-pipeline
22
+
23
+ ## Usage
24
+
25
+ Load the pipeline gem into your project:
26
+ ```ruby
27
+ require 'pipeline'
28
+ ```
29
+
30
+ Before we can create a pipeline, we need operation objects for processing the data.
31
+
32
+ Start by creating a simple `Operation` object by inheriting from `Pipeline::Operation` class:
33
+
34
+ ```ruby
35
+ class HelloWorld < Pipeline::Operation
36
+ def call(env)
37
+ # env is the data passed in from the pipeline
38
+ # do your data processing here ...
39
+
40
+ "Hello, #{env}"
41
+
42
+ super
43
+ end
44
+ end
45
+ ```
46
+
47
+ The example `HelloWorld` operation appends `'Hello'` to every string passed in.
48
+
49
+ Next, we need to create a `pipeline`. Within a pipeline, we can chain multiple operations to transform the data into the desired state.
50
+
51
+ Suppose we create a `HelloWorld` pipeline to use the `HelloWorld` operation, we can do it as follows:
52
+
53
+ ```ruby
54
+ Pipeline::Builder.new do |b|
55
+ b.use HelloWorld
56
+ end.call('World')
57
+ ```
58
+
59
+ The above will return `'Hello World'`
60
+
61
+ We can also add operation classes as procs. From the above example, we can wrap the string in another by using an additional proc:
62
+
63
+ ```ruby
64
+ Pipeline::Builder.new do |b|
65
+ b.use HelloWorld
66
+ b.use ->(str) { "More processing: #{str}" }
67
+ end.call('World')
68
+ ```
69
+
70
+ The above will return `'More processing: Hello World'`
71
+
72
+ We can also pass additional data into the operation classes:
73
+
74
+ ```ruby
75
+ Pipeline::Builder.new do |b|
76
+ b.use HelloWorld, 'Additional args'
77
+ end.call('World')
78
+ ```
79
+ Within the operation class we can access it using the `data` attribute.
80
+
81
+ ```ruby
82
+ class HelloWorld < Pipeline::Operation
83
+ def call(env)
84
+ # env is the data passed in from the pipeline
85
+ # data is passed in to the operation #=> 'Additional args'
86
+ # ....
87
+ super
88
+ end
89
+ end
90
+ ```
91
+
92
+ ## Using custom operation classes
93
+
94
+ Operation classes have a very simple interface.
95
+
96
+ To create your own operation classes, you need to implement the following methods:
97
+
98
+ ```ruby
99
+ initialize(next_op, data=nil)
100
+
101
+ call(env)
102
+ ```
103
+
104
+ `initialize` takes 2 arguments: the next operation to call; and any optional data the operation accepts
105
+
106
+ `call` performs the processing on the passed in data from the builder e.g. `builder.call(mydata)`
107
+
108
+ An example custom operation class:
109
+ ```ruby
110
+ class CustomOp
111
+ attr_reader :next_op, :data
112
+
113
+ def initialize(next_op, data=nil)
114
+ @next_op = next_op
115
+ @data = data
116
+ end
117
+
118
+ def call(env)
119
+ # Data processing here...
120
+ @next_op.call(env)
121
+ end
122
+ end
123
+ ```
124
+
125
+ ## Development
126
+
127
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
128
+
129
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
130
+
131
+ ## Contributing
132
+
133
+ Bug reports and pull requests are welcome on GitHub at https://github.com/cheeyeo/pipeline. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
134
+
135
+ ## License
136
+
137
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
138
+
139
+ ## Code of Conduct
140
+
141
+ Everyone interacting in the Pipeline project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/pipeline/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "pipeline"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,19 @@
1
+ require "pipeline"
2
+
3
+ class HelloWorld < Pipeline::Operation
4
+ def call(env)
5
+ # env is the data passed in from the pipeline
6
+ # do your data processing here ...
7
+
8
+ env = "Hello, #{env}"
9
+
10
+ super
11
+ end
12
+ end
13
+
14
+ res = Pipeline::Builder.new do |b|
15
+ b.use HelloWorld
16
+ b.use ->(str) { "More processing: #{str}" }
17
+ end.call('World')
18
+
19
+ puts res
data/lib/pipeline.rb ADDED
@@ -0,0 +1,3 @@
1
+ require "pipeline/version"
2
+ require "pipeline/builder"
3
+ require "pipeline/operation"
@@ -0,0 +1,61 @@
1
+ module Pipeline
2
+ class Builder
3
+ def initialize(&block)
4
+ if block_given?
5
+ if block.arity == 1
6
+ yield self
7
+ else
8
+ instance_eval(&block)
9
+ end
10
+ end
11
+ end
12
+
13
+ # Adds an operation to the internal stack
14
+ # @param [Class] operation - The operation class
15
+ # @param [Array] args - Arguments for the operation
16
+ # @param [Proc] block - Optional block for the operation
17
+ def use(operation, *args, &block)
18
+ stack << [operation, args, block]
19
+ self
20
+ end
21
+
22
+ # Calls the operations in the stack
23
+ # @param [Object] env - Optional initial input to the pipeline
24
+ def call(env)
25
+ build_operation_chain(stack.dup).
26
+ call(env.dup)
27
+ end
28
+
29
+ # Returns the internal stack array for reading as a frozen object
30
+ def inspect_stack
31
+ stack.freeze
32
+ end
33
+
34
+ private
35
+
36
+ def stack
37
+ @stack ||= []
38
+ end
39
+
40
+ # Iterate through the stack and build a single
41
+ # callable object which consists of each operation
42
+ # referencing the next one in the chain
43
+ def build_operation_chain(stack)
44
+ empty_op = EmptyOperation.new(nil)
45
+
46
+ stack.reverse.reduce(empty_op) do |next_op, current_op|
47
+ klass, args, block = current_op
48
+
49
+ if Class === klass
50
+ klass.new(next_op, *args, &block)
51
+ elsif Proc === klass
52
+ lambda do |env|
53
+ next_op.call(klass.call(env, *args))
54
+ end
55
+ else
56
+ raise StandardError, "Invalid operation, doesn't respond to `call`: #{klass.inspect}"
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,21 @@
1
+ module Pipeline
2
+ class Operation
3
+ attr_reader :next_op, :data
4
+
5
+ def initialize(next_op, data=nil)
6
+ @next_op = next_op
7
+ @data = data
8
+ end
9
+
10
+ def call(env)
11
+ @next_op.call(env)
12
+ end
13
+ end
14
+
15
+ class EmptyOperation < Operation
16
+ def call(env)
17
+ # NOOP
18
+ env
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module Pipeline
2
+ VERSION = "0.1.0"
3
+ end
data/pipeline.gemspec ADDED
@@ -0,0 +1,40 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "pipeline/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "data-pipeline"
8
+ spec.version = Pipeline::VERSION
9
+ spec.authors = ["Chee Yeo"]
10
+ spec.email = ["ckyeo.1@gmail.com"]
11
+ spec.date = '2018-09-01'
12
+ spec.summary = 'Ruby data pipeline'
13
+ spec.description = 'Process data using pipelines and operations'
14
+ spec.homepage = 'https://github.com/cheeyeo/pipeline'
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = "https://rubygems.org"
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ # Specify which files should be added to the gem when it is released.
27
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
28
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
29
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
30
+ end
31
+ spec.bindir = "exe"
32
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
33
+ spec.require_paths = ["lib"]
34
+
35
+ spec.add_development_dependency "bundler", "~> 1.16"
36
+ spec.add_development_dependency "rake", "~> 10.0"
37
+ spec.add_development_dependency "rspec", "~> 3.0"
38
+ spec.add_development_dependency "simplecov", "~> 0.16.1"
39
+ spec.add_development_dependency 'simplecov-console', '~> 0.4.2'
40
+ end
metadata ADDED
@@ -0,0 +1,132 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: data-pipeline
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Chee Yeo
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-09-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.16.1
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.16.1
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov-console
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 0.4.2
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 0.4.2
83
+ description: Process data using pipelines and operations
84
+ email:
85
+ - ckyeo.1@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rspec"
92
+ - ".travis.yml"
93
+ - CODE_OF_CONDUCT.md
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - bin/console
100
+ - bin/setup
101
+ - examples/simple.rb
102
+ - lib/pipeline.rb
103
+ - lib/pipeline/builder.rb
104
+ - lib/pipeline/operation.rb
105
+ - lib/pipeline/version.rb
106
+ - pipeline.gemspec
107
+ homepage: https://github.com/cheeyeo/pipeline
108
+ licenses:
109
+ - MIT
110
+ metadata:
111
+ allowed_push_host: https://rubygems.org
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubyforge_project:
128
+ rubygems_version: 2.7.6
129
+ signing_key:
130
+ specification_version: 4
131
+ summary: Ruby data pipeline
132
+ test_files: []