banzai 0.1.1 → 0.1.2
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 +4 -4
- data/README.md +6 -0
- data/lib/banzai.rb +3 -0
- data/lib/banzai/filter.rb +13 -5
- data/lib/banzai/pipeline.rb +3 -3
- data/spec/filter_spec.rb +16 -15
- data/spec/pipeline_spec.rb +22 -11
- data/spec/spec_helper.rb +0 -87
- metadata +36 -12
- data/.gitignore +0 -17
- data/.rspec +0 -2
- data/Gemfile +0 -10
- data/Rakefile +0 -12
- data/banzai.gemspec +0 -19
- data/lib/banzai/version.rb +0 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 33df5d09bd02ee144ba10a0b34d13071ba1d3855
|
4
|
+
data.tar.gz: ab729868341e7b5145c3f70fdf263099dd079fc1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 864fba492a923a8ff6c24b4ce8e5ea56d8b8b47d8a1b414722ded28d5c20aea51228c975e04071e9f30f81537918f46a6190abc1556949e81a97d9e6b053b552
|
7
|
+
data.tar.gz: 34c9122ab610c73c9b91bcc8dcf2454d7f6fb06d7877c3fb0ecf5c6c55ee3dfbaecb4e9e25501a4f496e6056e99f4a849041464bacea12575d62425fe13fdb41
|
data/README.md
CHANGED
data/lib/banzai.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
# Banzai is a simple toolkit for processing any input using filters.
|
2
|
+
# Multiple filters can be combined into a pipeline that will transform input
|
3
|
+
# by appliyng filters in chain feeding next one with the output of the previous.
|
1
4
|
module Banzai
|
2
5
|
autoload :Version, 'banzai/version'
|
3
6
|
autoload :Filter, 'banzai/filter'
|
data/lib/banzai/filter.rb
CHANGED
@@ -1,20 +1,28 @@
|
|
1
1
|
module Banzai
|
2
|
+
# Filter transforms an input into desired output. The process of
|
3
|
+
# transformation should be implemented in the {#call} method.
|
2
4
|
class Filter
|
3
|
-
|
4
5
|
attr_reader :options
|
5
6
|
|
6
|
-
|
7
|
+
# @param options [Hash] filter parameters that method {#call} can utilize
|
8
|
+
# to make processing customizable
|
9
|
+
def initialize(options = {})
|
7
10
|
@options = options
|
8
11
|
end
|
9
12
|
|
10
|
-
#
|
13
|
+
# Subclass should redefine this method to transform input to desired output
|
14
|
+
#
|
15
|
+
# @param input [Object] the type of the input is not defined since it will
|
16
|
+
# depend on the (re)implementation of the method
|
11
17
|
def call(input)
|
12
|
-
|
18
|
+
input
|
13
19
|
end
|
14
20
|
|
21
|
+
# Delegates to {#call} by creating an instance with default options
|
22
|
+
#
|
23
|
+
# @param input [Object]
|
15
24
|
def self.call(input)
|
16
25
|
new.call(input)
|
17
26
|
end
|
18
|
-
|
19
27
|
end
|
20
28
|
end
|
data/lib/banzai/pipeline.rb
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
module Banzai
|
2
|
+
# Pipeline is a filter that accept an array of filters that will be applied
|
3
|
+
# to input sequentially.
|
2
4
|
class Pipeline < Filter
|
3
|
-
|
4
5
|
def initialize(*filters)
|
5
6
|
@filters = filters.flatten
|
6
7
|
end
|
7
|
-
|
8
|
+
|
8
9
|
def call(input)
|
9
10
|
@filters.inject(input) do |content, filter|
|
10
11
|
filter.call(content)
|
11
12
|
end
|
12
13
|
end
|
13
|
-
|
14
14
|
end
|
15
15
|
end
|
data/spec/filter_spec.rb
CHANGED
@@ -1,26 +1,27 @@
|
|
1
|
-
describe Banzai::Filter, 'subclass' do
|
2
|
-
|
3
|
-
class
|
1
|
+
RSpec.describe Banzai::Filter, 'subclass' do
|
2
|
+
# A simple Filter implementation for testing
|
3
|
+
class Yell < Banzai::Filter
|
4
4
|
def call(input)
|
5
|
-
input.
|
5
|
+
input.to_s.upcase + '!' * level
|
6
6
|
end
|
7
|
-
end
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
filter = LeetFilter.new(:mode => 'hardcore')
|
12
|
-
expect(filter.options[:mode]).to eq 'hardcore'
|
8
|
+
def level
|
9
|
+
options[:level] || 1
|
13
10
|
end
|
11
|
+
end
|
14
12
|
|
15
|
-
|
16
|
-
|
13
|
+
subject { Yell }
|
14
|
+
let(:input) { 'chunky bacon' }
|
15
|
+
|
16
|
+
describe '.call' do
|
17
|
+
it 'filters the input' do
|
18
|
+
expect(subject.call(input)).to eq 'CHUNKY BACON!'
|
17
19
|
end
|
18
20
|
end
|
19
21
|
|
20
|
-
|
21
|
-
it '
|
22
|
-
expect(
|
22
|
+
describe '#call' do
|
23
|
+
it 'filters the input using options' do
|
24
|
+
expect(subject.new(level: 3).call(input)).to eq 'CHUNKY BACON!!!'
|
23
25
|
end
|
24
26
|
end
|
25
|
-
|
26
27
|
end
|
data/spec/pipeline_spec.rb
CHANGED
@@ -1,25 +1,36 @@
|
|
1
|
-
describe Banzai::Pipeline do
|
2
|
-
|
3
|
-
class
|
1
|
+
RSpec.describe Banzai::Pipeline do
|
2
|
+
# Simple filter implementation for testing
|
3
|
+
class Strip < Banzai::Filter
|
4
4
|
def call(input)
|
5
5
|
input.strip
|
6
6
|
end
|
7
7
|
end
|
8
8
|
|
9
|
-
|
9
|
+
# Simple filter implementation for testing
|
10
|
+
class Upcase < Banzai::Filter
|
10
11
|
def call(input)
|
11
12
|
input.upcase
|
12
13
|
end
|
13
14
|
end
|
14
15
|
|
15
|
-
|
16
|
-
|
17
|
-
expect(pipeline.call(' ohai ')).to eq 'OHAI'
|
18
|
-
end
|
16
|
+
let(:input) { ' ohai ' }
|
17
|
+
let(:output) { 'OHAI' }
|
19
18
|
|
20
|
-
|
21
|
-
|
22
|
-
|
19
|
+
describe 'initialized with array of filters' do
|
20
|
+
subject { Banzai::Pipeline.new([Strip, Upcase]) }
|
21
|
+
describe '.call' do
|
22
|
+
it 'filters the input' do
|
23
|
+
expect(subject.call(input)).to eq output
|
24
|
+
end
|
25
|
+
end
|
23
26
|
end
|
24
27
|
|
28
|
+
describe 'initialized with splatted array of filters' do
|
29
|
+
subject { Banzai::Pipeline.new(Strip, Upcase) }
|
30
|
+
describe '.call' do
|
31
|
+
it 'filters the input' do
|
32
|
+
expect(subject.call(input)).to eq output
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
25
36
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,98 +1,11 @@
|
|
1
1
|
require 'banzai'
|
2
2
|
|
3
|
-
# This file was generated by the `rspec --init` command. Conventionally, all
|
4
|
-
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
5
|
-
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
6
|
-
# this file to always be loaded, without a need to explicitly require it in any
|
7
|
-
# files.
|
8
|
-
#
|
9
|
-
# Given that it is always loaded, you are encouraged to keep this file as
|
10
|
-
# light-weight as possible. Requiring heavyweight dependencies from this file
|
11
|
-
# will add to the boot time of your test suite on EVERY test run, even for an
|
12
|
-
# individual file that may not need all of that loaded. Instead, consider making
|
13
|
-
# a separate helper file that requires the additional dependencies and performs
|
14
|
-
# the additional setup, and require it from the spec files that actually need
|
15
|
-
# it.
|
16
|
-
#
|
17
|
-
# The `.rspec` file also contains a few flags that are not defaults but that
|
18
|
-
# users commonly want.
|
19
|
-
#
|
20
|
-
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
21
3
|
RSpec.configure do |config|
|
22
|
-
# rspec-expectations config goes here. You can use an alternate
|
23
|
-
# assertion/expectation library such as wrong or the stdlib/minitest
|
24
|
-
# assertions if you prefer.
|
25
4
|
config.expect_with :rspec do |expectations|
|
26
|
-
# This option will default to `true` in RSpec 4. It makes the `description`
|
27
|
-
# and `failure_message` of custom matchers include text for helper methods
|
28
|
-
# defined using `chain`, e.g.:
|
29
|
-
# be_bigger_than(2).and_smaller_than(4).description
|
30
|
-
# # => "be bigger than 2 and smaller than 4"
|
31
|
-
# ...rather than:
|
32
|
-
# # => "be bigger than 2"
|
33
5
|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
34
6
|
end
|
35
7
|
|
36
|
-
# rspec-mocks config goes here. You can use an alternate test double
|
37
|
-
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
38
8
|
config.mock_with :rspec do |mocks|
|
39
|
-
# Prevents you from mocking or stubbing a method that does not exist on
|
40
|
-
# a real object. This is generally recommended, and will default to
|
41
|
-
# `true` in RSpec 4.
|
42
9
|
mocks.verify_partial_doubles = true
|
43
10
|
end
|
44
|
-
|
45
|
-
# The settings below are suggested to provide a good initial experience
|
46
|
-
# with RSpec, but feel free to customize to your heart's content.
|
47
|
-
=begin
|
48
|
-
# These two settings work together to allow you to limit a spec run
|
49
|
-
# to individual examples or groups you care about by tagging them with
|
50
|
-
# `:focus` metadata. When nothing is tagged with `:focus`, all examples
|
51
|
-
# get run.
|
52
|
-
config.filter_run :focus
|
53
|
-
config.run_all_when_everything_filtered = true
|
54
|
-
|
55
|
-
# Allows RSpec to persist some state between runs in order to support
|
56
|
-
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
57
|
-
# you configure your source control system to ignore this file.
|
58
|
-
config.example_status_persistence_file_path = "spec/examples.txt"
|
59
|
-
|
60
|
-
# Limits the available syntax to the non-monkey patched syntax that is
|
61
|
-
# recommended. For more details, see:
|
62
|
-
# - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
|
63
|
-
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
64
|
-
# - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
|
65
|
-
config.disable_monkey_patching!
|
66
|
-
|
67
|
-
# This setting enables warnings. It's recommended, but in some cases may
|
68
|
-
# be too noisy due to issues in dependencies.
|
69
|
-
config.warnings = true
|
70
|
-
|
71
|
-
# Many RSpec users commonly either run the entire suite or an individual
|
72
|
-
# file, and it's useful to allow more verbose output when running an
|
73
|
-
# individual spec file.
|
74
|
-
if config.files_to_run.one?
|
75
|
-
# Use the documentation formatter for detailed output,
|
76
|
-
# unless a formatter has already been configured
|
77
|
-
# (e.g. via a command-line flag).
|
78
|
-
config.default_formatter = 'doc'
|
79
|
-
end
|
80
|
-
|
81
|
-
# Print the 10 slowest examples and example groups at the
|
82
|
-
# end of the spec run, to help surface which specs are running
|
83
|
-
# particularly slow.
|
84
|
-
config.profile_examples = 10
|
85
|
-
|
86
|
-
# Run specs in random order to surface order dependencies. If you find an
|
87
|
-
# order dependency and want to debug it, you can fix the order by providing
|
88
|
-
# the seed, which is printed after each run.
|
89
|
-
# --seed 1234
|
90
|
-
config.order = :random
|
91
|
-
|
92
|
-
# Seed global randomization in this process using the `--seed` CLI option.
|
93
|
-
# Setting this allows you to use `--seed` to deterministically reproduce
|
94
|
-
# test failures related to randomization by passing the same `--seed` value
|
95
|
-
# as the one that triggered the failure.
|
96
|
-
Kernel.srand config.seed
|
97
|
-
=end
|
98
11
|
end
|
metadata
CHANGED
@@ -1,37 +1,60 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: banzai
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dejan Simic
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
12
|
-
dependencies:
|
13
|
-
|
11
|
+
date: 2015-10-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rubocop
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: yard
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Toolkit for processing input using filters and pipelines
|
14
42
|
email:
|
15
43
|
- desimic@gmail.com
|
16
44
|
executables: []
|
17
45
|
extensions: []
|
18
46
|
extra_rdoc_files: []
|
19
47
|
files:
|
20
|
-
- ".gitignore"
|
21
|
-
- ".rspec"
|
22
|
-
- Gemfile
|
23
48
|
- README.md
|
24
|
-
- Rakefile
|
25
|
-
- banzai.gemspec
|
26
49
|
- lib/banzai.rb
|
27
50
|
- lib/banzai/filter.rb
|
28
51
|
- lib/banzai/pipeline.rb
|
29
|
-
- lib/banzai/version.rb
|
30
52
|
- spec/filter_spec.rb
|
31
53
|
- spec/pipeline_spec.rb
|
32
54
|
- spec/spec_helper.rb
|
33
55
|
homepage: https://github.com/dejan/banzai
|
34
|
-
licenses:
|
56
|
+
licenses:
|
57
|
+
- MIT
|
35
58
|
metadata: {}
|
36
59
|
post_install_message:
|
37
60
|
rdoc_options: []
|
@@ -52,8 +75,9 @@ rubyforge_project:
|
|
52
75
|
rubygems_version: 2.4.5
|
53
76
|
signing_key:
|
54
77
|
specification_version: 4
|
55
|
-
summary:
|
78
|
+
summary: Toolkit for processing input using filters and pipelines
|
56
79
|
test_files:
|
57
80
|
- spec/filter_spec.rb
|
58
81
|
- spec/pipeline_spec.rb
|
59
82
|
- spec/spec_helper.rb
|
83
|
+
has_rdoc:
|
data/.gitignore
DELETED
data/.rspec
DELETED
data/Gemfile
DELETED
data/Rakefile
DELETED
data/banzai.gemspec
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
lib = File.expand_path('../lib', __FILE__)
|
3
|
-
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
-
require 'banzai/version'
|
5
|
-
|
6
|
-
Gem::Specification.new do |gem|
|
7
|
-
gem.name = "banzai"
|
8
|
-
gem.version = Banzai::VERSION
|
9
|
-
gem.authors = ["Dejan Simic"]
|
10
|
-
gem.email = ["desimic@gmail.com"]
|
11
|
-
gem.description = %q{Simple toolkit for processing input using filter/pipeline concept}
|
12
|
-
gem.summary = %q{Simple toolkit for processing input using filter/pipeline concept}
|
13
|
-
gem.homepage = "https://github.com/dejan/banzai"
|
14
|
-
|
15
|
-
gem.files = `git ls-files`.split($/)
|
16
|
-
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
-
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
-
gem.require_paths = ["lib"]
|
19
|
-
end
|
data/lib/banzai/version.rb
DELETED