fragile 0.0.1
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.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE +23 -0
- data/Rakefile +1 -0
- data/bin/fragile +19 -0
- data/examples/example.rb +15 -0
- data/examples/plugins/bar.rb +14 -0
- data/examples/plugins/foo.rb +14 -0
- data/examples/plugins/hoge.rb +13 -0
- data/fragile.gemspec +24 -0
- data/lib/fragile.rb +14 -0
- data/lib/fragile/application.rb +61 -0
- data/lib/fragile/dsl.rb +18 -0
- data/lib/fragile/pipeline.rb +53 -0
- data/lib/fragile/pipeline_manager.rb +36 -0
- data/lib/fragile/plugin_manager.rb +49 -0
- data/lib/fragile/version.rb +11 -0
- data/test/dsl_test.rb +21 -0
- data/test/pipeline_manager_test.rb +97 -0
- data/test/pipeline_test.rb +109 -0
- data/test/plugin_manager_test.rb +96 -0
- data/test/test_helper.rb +7 -0
- metadata +68 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Copyright (c) 2012 Takashi Nakamura
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person
|
4
|
+
obtaining a copy of this software and associated documentation
|
5
|
+
files (the "Software"), to deal in the Software without
|
6
|
+
restriction, including without limitation the rights to use,
|
7
|
+
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
copies of the Software, and to permit persons to whom the
|
9
|
+
Software is furnished to do so, subject to the following
|
10
|
+
conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be
|
13
|
+
included in all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
17
|
+
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
18
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
19
|
+
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
20
|
+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
21
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
22
|
+
OTHER DEALINGS IN THE SOFTWARE.
|
23
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/bin/fragile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# coding: utf-8
|
3
|
+
# Name:: Fragile
|
4
|
+
# Author:: tnakamura <http://d.hatena.ne.jp/griefworker>
|
5
|
+
# Created:: Jun 15, 2012
|
6
|
+
# Updated:: Jun 15, 2012
|
7
|
+
# Copyright:: tnakamura Copyright (c) 2012
|
8
|
+
# License:: Licensed under the MIT LICENSE.
|
9
|
+
|
10
|
+
begin
|
11
|
+
require "rubygems"
|
12
|
+
gem "fragile"
|
13
|
+
rescue LoadError
|
14
|
+
end
|
15
|
+
|
16
|
+
require "fragile"
|
17
|
+
|
18
|
+
Fragile.application.run
|
19
|
+
|
data/examples/example.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
pipeline :foobar do
|
2
|
+
use :foo, :name => "hoge"
|
3
|
+
use :bar, :suffix => "fuga"
|
4
|
+
use :bar, :suffix => "moga"
|
5
|
+
use :hoge
|
6
|
+
end
|
7
|
+
|
8
|
+
pipeline :hogefuga do
|
9
|
+
retry_count 3
|
10
|
+
|
11
|
+
use :foo, :name => "aaa"
|
12
|
+
use :bar, :suffix => "bbb"
|
13
|
+
use :hoge
|
14
|
+
end
|
15
|
+
|
data/fragile.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "fragile/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "fragile"
|
7
|
+
s.version = Fragile::VERSION
|
8
|
+
s.authors = ["tnakamura"]
|
9
|
+
s.email = ["griefworker@gmail.com"]
|
10
|
+
s.homepage = "https://github.com/tnakamura/fragile"
|
11
|
+
s.summary = %q{Ruby Pipeline Framework}
|
12
|
+
s.description = %q{Ruby Pipeline Framework}
|
13
|
+
|
14
|
+
s.rubyforge_project = "fragile"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
# s.add_development_dependency "rspec"
|
23
|
+
# s.add_runtime_dependency "rest-client"
|
24
|
+
end
|
data/lib/fragile.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# Name:: Fragile
|
3
|
+
# Author:: tnakamura <http://d.hatena.ne.jp/griefworker>
|
4
|
+
# Created:: Jun 15, 2012
|
5
|
+
# Updated:: Jun 15, 2012
|
6
|
+
# Copyright:: tnakamura Copyright (c) 2012
|
7
|
+
# License:: Licensed under the MIT LICENSE.
|
8
|
+
require "fragile/version"
|
9
|
+
require "fragile/plugin_manager"
|
10
|
+
require "fragile/pipeline"
|
11
|
+
require "fragile/pipeline_manager"
|
12
|
+
require "fragile/dsl"
|
13
|
+
require "fragile/application"
|
14
|
+
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# Name:: Fragile
|
3
|
+
# Author:: tnakamura <http://d.hatena.ne.jp/griefworker>
|
4
|
+
# Created:: Jun 15, 2012
|
5
|
+
# Updated:: Jun 15, 2012
|
6
|
+
# Copyright:: tnakamura Copyright (c) 2012
|
7
|
+
# License:: Licensed under the MIT LICENSE.
|
8
|
+
require "optparse"
|
9
|
+
require "fragile/version"
|
10
|
+
require "fragile/pipeline_manager"
|
11
|
+
require "fragile/plugin_manager"
|
12
|
+
|
13
|
+
module Fragile
|
14
|
+
class Application
|
15
|
+
include Fragile::PipelineManager
|
16
|
+
include Fragile::PluginManager
|
17
|
+
|
18
|
+
def initialize
|
19
|
+
@spcfile = File.join(Dir.pwd, "Spcfile")
|
20
|
+
end
|
21
|
+
|
22
|
+
def run
|
23
|
+
handle_options
|
24
|
+
load_plugins
|
25
|
+
load_spcfile
|
26
|
+
run_pipeline(ARGV)
|
27
|
+
end
|
28
|
+
|
29
|
+
def load_spcfile
|
30
|
+
load @spcfile
|
31
|
+
end
|
32
|
+
|
33
|
+
def handle_options
|
34
|
+
opts = OptionParser.new
|
35
|
+
opts.version = Fragile::VERSION
|
36
|
+
opts.banner = "fragile [-f RECIPE_FILE] {options} targets..."
|
37
|
+
opts.separator ""
|
38
|
+
opts.separator "Options are ..."
|
39
|
+
opts.on_tail("-h", "--help", "-H", "Display this help message.") do
|
40
|
+
puts opts
|
41
|
+
exit
|
42
|
+
end
|
43
|
+
opts.on("-f", "--recipefile=RECIPE_FILE", "Recipe file path") { |v|
|
44
|
+
@spcfile = v
|
45
|
+
@plugin_dir ||= File.join(File.dirname(@spcfile), "plugins")
|
46
|
+
}
|
47
|
+
opts.on("-p", "--plugindir=plugin_dir", "Plugin directory") { |v| @plugin_dir = v }
|
48
|
+
opts.parse!(ARGV)
|
49
|
+
|
50
|
+
unless 0 < ARGV.count
|
51
|
+
puts opts
|
52
|
+
exit
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def self.application
|
58
|
+
@application ||= Application.new
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
data/lib/fragile/dsl.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# Name:: Fragile
|
3
|
+
# Author:: tnakamura <http://d.hatena.ne.jp/griefworker>
|
4
|
+
# Created:: Jun 15, 2012
|
5
|
+
# Updated:: Jun 15, 2012
|
6
|
+
# Copyright:: tnakamura Copyright (c) 2012
|
7
|
+
# License:: Licensed under the MIT LICENSE.
|
8
|
+
|
9
|
+
module Fragile
|
10
|
+
module DSL
|
11
|
+
def pipeline(name, &block)
|
12
|
+
Fragile.application.define_pipeline(name, &block)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
self.extend Fragile::DSL
|
18
|
+
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# Name:: Fragile
|
3
|
+
# Author:: tnakamura <http://d.hatena.ne.jp/griefworker>
|
4
|
+
# Created:: Jun 15, 2012
|
5
|
+
# Updated:: Jun 15, 2012
|
6
|
+
# Copyright:: tnakamura Copyright (c) 2012
|
7
|
+
# License:: Licensed under the MIT LICENSE.
|
8
|
+
|
9
|
+
module Fragile
|
10
|
+
class PipelineError < Exception
|
11
|
+
end
|
12
|
+
|
13
|
+
class Pipeline
|
14
|
+
attr_reader :name
|
15
|
+
|
16
|
+
def initialize(name)
|
17
|
+
@name = name
|
18
|
+
@retry_count = 3
|
19
|
+
@plugins = []
|
20
|
+
end
|
21
|
+
|
22
|
+
def retry_count(count)
|
23
|
+
@retry_count = count
|
24
|
+
end
|
25
|
+
|
26
|
+
def use(plugin, config={})
|
27
|
+
@plugins << Fragile.application.create_plugin(plugin, config)
|
28
|
+
end
|
29
|
+
|
30
|
+
def run
|
31
|
+
data = nil
|
32
|
+
@plugins.each do |plugin|
|
33
|
+
retry_handler do
|
34
|
+
data = plugin.call(data)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
def retry_handler(&block)
|
41
|
+
count = 0
|
42
|
+
begin
|
43
|
+
block.call
|
44
|
+
rescue
|
45
|
+
if @retry_count < count
|
46
|
+
raise PipelineError.new("retry over error.")
|
47
|
+
end
|
48
|
+
count += 1
|
49
|
+
retry
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# Name:: Fragile
|
3
|
+
# Author:: tnakamura <http://d.hatena.ne.jp/griefworker>
|
4
|
+
# Created:: Jun 15, 2012
|
5
|
+
# Updated:: Jun 15, 2012
|
6
|
+
# Copyright:: tnakamura Copyright (c) 2012
|
7
|
+
# License:: Licensed under the MIT LICENSE.
|
8
|
+
require "fragile/pipeline"
|
9
|
+
|
10
|
+
module Fragile
|
11
|
+
module PipelineManager
|
12
|
+
def pipelines
|
13
|
+
@pipelines ||= {}
|
14
|
+
end
|
15
|
+
|
16
|
+
def define_pipeline(name, &block)
|
17
|
+
p = Pipeline.new(name.to_s)
|
18
|
+
p.instance_eval(&block)
|
19
|
+
self.pipelines[name.to_s] = p
|
20
|
+
end
|
21
|
+
|
22
|
+
def pipeline_exist?(name)
|
23
|
+
self.pipelines.has_key?(name.to_s)
|
24
|
+
end
|
25
|
+
|
26
|
+
def run_pipeline(*names)
|
27
|
+
names.flatten.each do |name|
|
28
|
+
unless pipeline_exist?(name)
|
29
|
+
raise Fragile::PipelineError.new("Pipeline #{name} not found.")
|
30
|
+
end
|
31
|
+
self.pipelines[name.to_s].run
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
@@ -0,0 +1,49 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# Name:: Fragile
|
3
|
+
# Author:: tnakamura <http://d.hatena.ne.jp/griefworker>
|
4
|
+
# Created:: Jun 15, 2012
|
5
|
+
# Updated:: Jun 15, 2012
|
6
|
+
# Copyright:: tnakamura Copyright (c) 2012
|
7
|
+
# License:: Licensed under the MIT LICENSE.
|
8
|
+
|
9
|
+
module Fragile
|
10
|
+
module Plugin; end
|
11
|
+
|
12
|
+
class PluginError < Exception
|
13
|
+
end
|
14
|
+
|
15
|
+
module PluginManager
|
16
|
+
attr_accessor :plugin_dir
|
17
|
+
|
18
|
+
def load_plugins
|
19
|
+
return unless Dir.exist?(@plugin_dir)
|
20
|
+
|
21
|
+
pattern = File.join(@plugin_dir, "*.rb")
|
22
|
+
Dir.glob(pattern) do |path|
|
23
|
+
load path
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def create_plugin(plugin, config)
|
28
|
+
if plugin.instance_of?(Class)
|
29
|
+
# クラスなら直接 new する
|
30
|
+
plugin.new(config)
|
31
|
+
else
|
32
|
+
# 文字列かシンボルならクラスを取得して new する
|
33
|
+
plugin_name = classify(plugin.to_s)
|
34
|
+
create_plugin_instance(plugin_name, config)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
def create_plugin_instance(class_name, config)
|
40
|
+
klass = Fragile::Plugin.const_get(class_name)
|
41
|
+
klass.new(config)
|
42
|
+
end
|
43
|
+
|
44
|
+
def classify(name)
|
45
|
+
name.split("_").map{ |s| s.capitalize }.join
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
@@ -0,0 +1,11 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
# Name:: Fragile
|
3
|
+
# Author:: tnakamura <http://d.hatena.ne.jp/griefworker>
|
4
|
+
# Created:: Jun 15, 2012
|
5
|
+
# Updated:: Jun 15, 2012
|
6
|
+
# Copyright:: tnakamura Copyright (c) 2012
|
7
|
+
# License:: Licensed under the MIT LICENSE.
|
8
|
+
|
9
|
+
module Fragile
|
10
|
+
VERSION = "0.0.1"
|
11
|
+
end
|
data/test/dsl_test.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require_relative "test_helper"
|
3
|
+
require "minitest/spec"
|
4
|
+
require "minitest/autorun"
|
5
|
+
require "fragile"
|
6
|
+
|
7
|
+
describe "DSL" do
|
8
|
+
describe "#pipeline" do
|
9
|
+
include Fragile::DSL
|
10
|
+
|
11
|
+
after do
|
12
|
+
Fragile.application.pipelines.clear
|
13
|
+
end
|
14
|
+
|
15
|
+
it "パイプラインを登録できるべき" do
|
16
|
+
pipeline "foo" do;end
|
17
|
+
assert_equal true, Fragile.application.pipelines.has_key?("foo")
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
@@ -0,0 +1,97 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require_relative "test_helper"
|
3
|
+
require "minitest/spec"
|
4
|
+
require "minitest/autorun"
|
5
|
+
require "fragile"
|
6
|
+
|
7
|
+
class TestApp
|
8
|
+
include Fragile::PipelineManager
|
9
|
+
end
|
10
|
+
|
11
|
+
class TestPlugin
|
12
|
+
def initialize(config)
|
13
|
+
@config = config
|
14
|
+
end
|
15
|
+
|
16
|
+
def call(data)
|
17
|
+
@config[:called] = true
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "PipelineManager" do
|
22
|
+
describe "#define_pipeline" do
|
23
|
+
before do
|
24
|
+
@manager = TestApp.new
|
25
|
+
end
|
26
|
+
|
27
|
+
it "パイプラインを登録できるべき" do
|
28
|
+
@manager.define_pipeline :foo do;end
|
29
|
+
assert_equal true, @manager.pipelines.has_key?("foo")
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe "#pipeline_exist?" do
|
34
|
+
describe "存在しないパイプライン名のとき" do
|
35
|
+
before do
|
36
|
+
@manager = TestApp.new
|
37
|
+
end
|
38
|
+
|
39
|
+
it "false を返すべき" do
|
40
|
+
assert_equal false, @manager.pipeline_exist?("foo")
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe "存在するパイプライン名のとき" do
|
45
|
+
before do
|
46
|
+
@manager = TestApp.new
|
47
|
+
@manager.define_pipeline "bar" do;end
|
48
|
+
end
|
49
|
+
|
50
|
+
it "true を返すべき" do
|
51
|
+
assert_equal true, @manager.pipeline_exist?("bar")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe "#pipelines" do
|
57
|
+
describe "パイプラインが登録されていないとき" do
|
58
|
+
before do
|
59
|
+
@manager = TestApp.new
|
60
|
+
end
|
61
|
+
|
62
|
+
it "空であるべき" do
|
63
|
+
assert_equal true, @manager.pipelines.empty?
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "#run_pipeline" do
|
69
|
+
describe "登録されていないパイプラインを指定したとき" do
|
70
|
+
before do
|
71
|
+
@manager = TestApp.new
|
72
|
+
end
|
73
|
+
|
74
|
+
it "PipelineError が発生するべき" do
|
75
|
+
assert_raises Fragile::PipelineError do
|
76
|
+
@manager.run_pipeline("hoge")
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "登録されているパイプラインを指定したとき" do
|
82
|
+
before do
|
83
|
+
@config = config = {}
|
84
|
+
@manager = TestApp.new
|
85
|
+
@manager.define_pipeline "hoge" do
|
86
|
+
use TestPlugin, config
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
it "パイプラインを実行できるべき" do
|
91
|
+
@manager.run_pipeline("hoge")
|
92
|
+
assert_equal true, @config[:called]
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require_relative "test_helper"
|
3
|
+
require "minitest/spec"
|
4
|
+
require "minitest/autorun"
|
5
|
+
require "fragile"
|
6
|
+
|
7
|
+
describe "Pipeline" do
|
8
|
+
describe "#name" do
|
9
|
+
before do
|
10
|
+
@pipeline = Fragile::Pipeline.new("test")
|
11
|
+
end
|
12
|
+
|
13
|
+
it "設定した値を取得できるべき" do
|
14
|
+
assert_equal "test", @pipeline.name
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#retry_count" do
|
19
|
+
before do
|
20
|
+
@pipeline = Fragile::Pipeline.new("test")
|
21
|
+
end
|
22
|
+
|
23
|
+
it "値を設定できるべき" do
|
24
|
+
@pipeline.retry_count 5
|
25
|
+
|
26
|
+
actual = nil
|
27
|
+
@pipeline.instance_eval { actual = @retry_count }
|
28
|
+
assert_equal 5, actual
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#use" do
|
33
|
+
class TestPlugin
|
34
|
+
attr_accessor :config
|
35
|
+
|
36
|
+
def initialize(config)
|
37
|
+
@config = config
|
38
|
+
end
|
39
|
+
|
40
|
+
def call(data)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
before do
|
45
|
+
@pipeline = Fragile::Pipeline.new("test")
|
46
|
+
end
|
47
|
+
|
48
|
+
it "プラグインを設定できるべき" do
|
49
|
+
@pipeline.use TestPlugin
|
50
|
+
|
51
|
+
actual_count = nil
|
52
|
+
@pipeline.instance_eval { actual_count = @plugins.count }
|
53
|
+
assert_equal 1, actual_count
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
describe "#run" do
|
58
|
+
class TestPlugin
|
59
|
+
attr_accessor :config
|
60
|
+
|
61
|
+
def initialize(config)
|
62
|
+
@config = config
|
63
|
+
@max_error_count = config[:max_error_count] || 0
|
64
|
+
@error_count = 0
|
65
|
+
end
|
66
|
+
|
67
|
+
def call(data)
|
68
|
+
if @error_count < @max_error_count
|
69
|
+
@error_count += 1
|
70
|
+
raise "Error #{@error_count}"
|
71
|
+
end
|
72
|
+
@config[:called] = true
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
it "パイプラインを実行できるべき" do
|
77
|
+
@data = {}
|
78
|
+
@pipeline = Fragile::Pipeline.new("test")
|
79
|
+
@pipeline.use TestPlugin, @data
|
80
|
+
|
81
|
+
@pipeline.run
|
82
|
+
|
83
|
+
assert_equal true, @data[:called]
|
84
|
+
end
|
85
|
+
|
86
|
+
it "@retry_count 回リトライできるべき" do
|
87
|
+
@data = {:max_error_count => 3}
|
88
|
+
@pipeline = Fragile::Pipeline.new("test")
|
89
|
+
@pipeline.use TestPlugin, @data
|
90
|
+
@pipeline.retry_count 2
|
91
|
+
|
92
|
+
@pipeline.run
|
93
|
+
|
94
|
+
assert_equal true, @data[:called]
|
95
|
+
end
|
96
|
+
|
97
|
+
it "@retry_count 回以上失敗すると PipelineError が発生するべき" do
|
98
|
+
@data = {:max_error_count => 4}
|
99
|
+
@pipeline = Fragile::Pipeline.new("test")
|
100
|
+
@pipeline.use TestPlugin, @data
|
101
|
+
@pipeline.retry_count 2
|
102
|
+
|
103
|
+
assert_raises Fragile::PipelineError do
|
104
|
+
@pipeline.run
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require_relative "test_helper"
|
3
|
+
require "minitest/spec"
|
4
|
+
require "minitest/autorun"
|
5
|
+
require "fragile"
|
6
|
+
|
7
|
+
class TestApp
|
8
|
+
include Fragile::PluginManager
|
9
|
+
|
10
|
+
def initialize(plugin_dir)
|
11
|
+
@plugin_dir = plugin_dir
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
module Fragile::Plugin
|
16
|
+
class TestPlugin
|
17
|
+
def initialize(config)
|
18
|
+
@config = config
|
19
|
+
end
|
20
|
+
|
21
|
+
def call(data)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe "PluginManager" do
|
27
|
+
describe "#load_plugins" do
|
28
|
+
describe "プラグインディレクトリが存在するとき" do
|
29
|
+
before do
|
30
|
+
@plugin_dir = File.join(File.dirname(__FILE__), "../examples/plugins")
|
31
|
+
@manager = TestApp.new(@plugin_dir)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "プラグインをロードできるべき" do
|
35
|
+
@manager.load_plugins
|
36
|
+
Fragile::Plugin.const_get("Foo")
|
37
|
+
pass
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe "#create_plugin" do
|
43
|
+
describe "クラスを指定したとき" do
|
44
|
+
before do
|
45
|
+
@plugin_dir = File.join(File.dirname(__FILE__), "../examples/plugins")
|
46
|
+
@manager = TestApp.new(@plugin_dir)
|
47
|
+
end
|
48
|
+
|
49
|
+
it "プラグインのインスタンスを生成できるべき" do
|
50
|
+
obj = @manager.create_plugin(Fragile::Plugin::TestPlugin, {})
|
51
|
+
assert_equal Fragile::Plugin::TestPlugin, obj.class
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe "存在しないプラグイン名を指定したとき" do
|
56
|
+
before do
|
57
|
+
@plugin_dir = File.join(File.dirname(__FILE__), "../examples/plugins")
|
58
|
+
@manager = TestApp.new(@plugin_dir)
|
59
|
+
end
|
60
|
+
|
61
|
+
it "NameError が発生するべき" do
|
62
|
+
assert_raises NameError do
|
63
|
+
@manager.create_plugin("foo_bar_hoge_fuga", {})
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "存在するプラグイン名を指定したとき" do
|
69
|
+
before do
|
70
|
+
@plugin_dir = File.join(File.dirname(__FILE__), "../examples/plugins")
|
71
|
+
@manager = TestApp.new(@plugin_dir)
|
72
|
+
@manager.load_plugins
|
73
|
+
end
|
74
|
+
|
75
|
+
it "プラグインのインスタンスを生成できるべき" do
|
76
|
+
obj = @manager.create_plugin("foo", {})
|
77
|
+
assert_equal Fragile::Plugin::Foo, obj.class
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe "プラグインディレクトリが存在しないとき" do
|
82
|
+
before do
|
83
|
+
@plugin_dir = File.join(File.dirname(__FILE__), "not_exist")
|
84
|
+
@manager = TestApp.new(@plugin_dir)
|
85
|
+
end
|
86
|
+
|
87
|
+
it "何もしないべき" do
|
88
|
+
@manager.load_plugins
|
89
|
+
assert_raises NameError do
|
90
|
+
Fragile::Plugin.const_get("Foo")
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: fragile
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- tnakamura
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-15 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Ruby Pipeline Framework
|
15
|
+
email:
|
16
|
+
- griefworker@gmail.com
|
17
|
+
executables:
|
18
|
+
- fragile
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- .gitignore
|
23
|
+
- Gemfile
|
24
|
+
- MIT-LICENSE
|
25
|
+
- Rakefile
|
26
|
+
- bin/fragile
|
27
|
+
- examples/example.rb
|
28
|
+
- examples/plugins/bar.rb
|
29
|
+
- examples/plugins/foo.rb
|
30
|
+
- examples/plugins/hoge.rb
|
31
|
+
- fragile.gemspec
|
32
|
+
- lib/fragile.rb
|
33
|
+
- lib/fragile/application.rb
|
34
|
+
- lib/fragile/dsl.rb
|
35
|
+
- lib/fragile/pipeline.rb
|
36
|
+
- lib/fragile/pipeline_manager.rb
|
37
|
+
- lib/fragile/plugin_manager.rb
|
38
|
+
- lib/fragile/version.rb
|
39
|
+
- test/dsl_test.rb
|
40
|
+
- test/pipeline_manager_test.rb
|
41
|
+
- test/pipeline_test.rb
|
42
|
+
- test/plugin_manager_test.rb
|
43
|
+
- test/test_helper.rb
|
44
|
+
homepage: https://github.com/tnakamura/fragile
|
45
|
+
licenses: []
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
requirements: []
|
63
|
+
rubyforge_project: fragile
|
64
|
+
rubygems_version: 1.8.16
|
65
|
+
signing_key:
|
66
|
+
specification_version: 3
|
67
|
+
summary: Ruby Pipeline Framework
|
68
|
+
test_files: []
|