fragile 0.0.5 → 0.0.6
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/lib/fragile/application.rb +3 -1
- data/lib/fragile/plugin/sort_filter.rb +30 -0
- data/lib/fragile/version.rb +1 -1
- data/spec/plugin/sort_filter_spec.rb +48 -0
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0eac94fd588d850f785c1c5195fe41062976f365
|
4
|
+
data.tar.gz: ec585e017094e9c3ad4ca92dabedfb7f056c0b89
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a192ad3342d728a10375552ff11f92ad3b345d4398f17e883508bc943eb13e25532c9c0c90501c8b924a3726dbcb4dd06056af7e833851fe42da212b4ecdc787
|
7
|
+
data.tar.gz: 08858c40a36b192d48fb00be9d9a831a10d02ad04439a707ec0882eb740b4bef41738ffc1ba8954cc0630f3090368c37b3eaccfefb0592200401ebebeeed4938
|
data/lib/fragile/application.rb
CHANGED
@@ -13,13 +13,15 @@ require "fragile/plugin_manager"
|
|
13
13
|
|
14
14
|
module Fragile
|
15
15
|
class Application
|
16
|
+
DEFAULT_FILE_NAME = "Pipefile"
|
17
|
+
|
16
18
|
include Fragile::PipelineManager
|
17
19
|
include Fragile::PluginManager
|
18
20
|
|
19
21
|
attr_reader :logger
|
20
22
|
|
21
23
|
def initialize
|
22
|
-
@recipe_file = File.join(Dir.pwd,
|
24
|
+
@recipe_file = File.join(Dir.pwd, DEFAULT_FILE_NAME)
|
23
25
|
@logger = Logger.new(STDOUT)
|
24
26
|
@logger.level = Logger::WARN
|
25
27
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
module Fragile
|
4
|
+
module Plugin
|
5
|
+
# @example
|
6
|
+
# pipeline :sample do
|
7
|
+
# use "direct_input", :data => [2, 1, 4, 3, 5]
|
8
|
+
# use "sort_filter", :proc => ->(x, y){ x <=> y }
|
9
|
+
# use "console_output"
|
10
|
+
# end
|
11
|
+
class SortFilter
|
12
|
+
attr_reader :proc
|
13
|
+
|
14
|
+
def initialize(options={})
|
15
|
+
@proc = options[:proc]
|
16
|
+
end
|
17
|
+
|
18
|
+
def call(data)
|
19
|
+
if @proc
|
20
|
+
data.sort do |x, y|
|
21
|
+
@proc.call(x, y)
|
22
|
+
end
|
23
|
+
else
|
24
|
+
data
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
data/lib/fragile/version.rb
CHANGED
@@ -0,0 +1,48 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
require_relative "../spec_helper"
|
3
|
+
require "fragile/plugin/sort_filter"
|
4
|
+
|
5
|
+
describe Fragile::Plugin::SortFilter do
|
6
|
+
describe "#initialize" do
|
7
|
+
context "option を省略したとき" do
|
8
|
+
it "@proc が nil であるべき" do
|
9
|
+
@filter = described_class.new
|
10
|
+
expect(@filter.proc).to be_nil
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
context "option で proc を指定したとき" do
|
15
|
+
it "@proc に proc が設定されているべき" do
|
16
|
+
@filter = described_class.new(:proc => ->(x, y){ x <=> y })
|
17
|
+
expect(@filter.proc).to_not be_nil
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
context "option で proc を指定しなかったとき" do
|
22
|
+
it "@proc が nil であるべき" do
|
23
|
+
@filter = described_class.new(:name => "foo")
|
24
|
+
expect(@filter.proc).to be_nil
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#call" do
|
30
|
+
context "@proc が設定されているとき" do
|
31
|
+
it "data をソートした結果を返す" do
|
32
|
+
@filter = described_class.new(:proc => ->(x, y){ x <=> y })
|
33
|
+
result = @filter.call([2, 1, 5, 3, 4])
|
34
|
+
expect(result).to eq([1, 2, 3, 4, 5])
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
context "@proc が設定されていないとき" do
|
39
|
+
it "data をそのまま返す" do
|
40
|
+
data = [2, 1, 5, 3, 4]
|
41
|
+
@filter = described_class.new
|
42
|
+
result = @filter.call(data)
|
43
|
+
expect(result).to eq(data)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fragile
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- tnakamura
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-10-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -55,6 +55,7 @@ files:
|
|
55
55
|
- lib/fragile/plugin/map_filter.rb
|
56
56
|
- lib/fragile/plugin/rss_input.rb
|
57
57
|
- lib/fragile/plugin/select_filter.rb
|
58
|
+
- lib/fragile/plugin/sort_filter.rb
|
58
59
|
- lib/fragile/plugin_manager.rb
|
59
60
|
- lib/fragile/version.rb
|
60
61
|
- spec/dsl_spec.rb
|
@@ -62,6 +63,7 @@ files:
|
|
62
63
|
- spec/pipeline_spec.rb
|
63
64
|
- spec/plugin/direct_input_spec.rb
|
64
65
|
- spec/plugin/im_kayac_output_spec.rb
|
66
|
+
- spec/plugin/sort_filter_spec.rb
|
65
67
|
- spec/plugin_manager_spec.rb
|
66
68
|
- spec/spec_helper.rb
|
67
69
|
homepage: https://github.com/tnakamura/fragile
|
@@ -93,5 +95,6 @@ test_files:
|
|
93
95
|
- spec/pipeline_spec.rb
|
94
96
|
- spec/plugin/direct_input_spec.rb
|
95
97
|
- spec/plugin/im_kayac_output_spec.rb
|
98
|
+
- spec/plugin/sort_filter_spec.rb
|
96
99
|
- spec/plugin_manager_spec.rb
|
97
100
|
- spec/spec_helper.rb
|