ul-wukong 4.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +60 -0
- data/.gitmodules +6 -0
- data/.rspec +2 -0
- data/.travis.yml +19 -0
- data/.yardopts +6 -0
- data/CHANGELOG.md +7 -0
- data/Gemfile +17 -0
- data/Guardfile +12 -0
- data/LICENSE.md +95 -0
- data/NOTES-travis.md +31 -0
- data/README-old.md +422 -0
- data/README.md +1308 -0
- data/Rakefile +28 -0
- data/TODO.md +99 -0
- data/bin/cutc +30 -0
- data/bin/cuttab +5 -0
- data/bin/greptrue +6 -0
- data/bin/md5sort +20 -0
- data/bin/setcat +11 -0
- data/bin/tabchar +5 -0
- data/bin/uniq-ord +59 -0
- data/bin/uniqc +3 -0
- data/bin/wu +34 -0
- data/bin/wu-clean-encoding +31 -0
- data/bin/wu-date +13 -0
- data/bin/wu-datetime +13 -0
- data/bin/wu-hist +3 -0
- data/bin/wu-lign +186 -0
- data/bin/wu-local +4 -0
- data/bin/wu-plus +9 -0
- data/bin/wu-source +5 -0
- data/bin/wu-sum +31 -0
- data/diagrams/wu_local.dot +39 -0
- data/diagrams/wu_local.dot.png +0 -0
- data/examples/Gemfile +38 -0
- data/examples/README.md +9 -0
- data/examples/basic/string_reverser.rb +23 -0
- data/examples/basic/tiny_count.rb +8 -0
- data/examples/basic/word_count/accumulator.rb +26 -0
- data/examples/basic/word_count/tokenizer.rb +13 -0
- data/examples/basic/word_count/word_count.rb +6 -0
- data/examples/dataflow/scraper_macro_flow.rb +28 -0
- data/examples/deploy_pack/Gemfile +6 -0
- data/examples/deploy_pack/README.md +6 -0
- data/examples/deploy_pack/a/b/c/.gitkeep +0 -0
- data/examples/deploy_pack/app/processors/string_reverser.rb +5 -0
- data/examples/deploy_pack/config/environment.rb +1 -0
- data/examples/dsl/dataflow/fibonacci_series.rb +101 -0
- data/examples/dsl/dataflow/scraper_macro_flow.rb +28 -0
- data/examples/dsl/dataflow/simple.rb +12 -0
- data/examples/dsl/dataflow/telegram.rb +45 -0
- data/examples/dsl/workflow/cherry_pie.dot +97 -0
- data/examples/dsl/workflow/cherry_pie.md +104 -0
- data/examples/dsl/workflow/cherry_pie.png +0 -0
- data/examples/dsl/workflow/cherry_pie.rb +101 -0
- data/examples/empty/.gitkeep +0 -0
- data/examples/examples_helper.rb +9 -0
- data/examples/geo.rb +4 -0
- data/examples/geo/geo_grids.numbers +0 -0
- data/examples/geo/geolocated.rb +331 -0
- data/examples/geo/quadtile.rb +69 -0
- data/examples/geo/spec/geolocated_spec.rb +247 -0
- data/examples/geo/tile_fetcher.rb +77 -0
- data/examples/graph/implied_geolocation/README.md +63 -0
- data/examples/graph/minimum_spanning_tree/airfares_graphviz.rb +73 -0
- data/examples/improver/tweet_summary.rb +73 -0
- data/examples/loadable.rb +2 -0
- data/examples/munging/airline_flights/airline_flights.rake +83 -0
- data/examples/munging/airline_flights/airplane.rb +0 -0
- data/examples/munging/airline_flights/airport_id_unification.rb +129 -0
- data/examples/munging/airline_flights/airport_ok_chars.rb +4 -0
- data/examples/munging/airline_flights/indexable.rb +75 -0
- data/examples/munging/airline_flights/indexable_spec.rb +90 -0
- data/examples/munging/airline_flights/reconcile_airports.rb +142 -0
- data/examples/munging/airline_flights/tasks.rake +83 -0
- data/examples/munging/airline_flights/topcities.rb +167 -0
- data/examples/munging/geo/geo_json.rb +54 -0
- data/examples/munging/geo/geo_models.rb +69 -0
- data/examples/munging/geo/geonames_models.rb +107 -0
- data/examples/munging/geo/iso_codes.rb +172 -0
- data/examples/munging/geo/reconcile_countries.rb +124 -0
- data/examples/munging/geo/tasks.rake +71 -0
- data/examples/munging/wikipedia/articles/extract_articles-parsed.rb +79 -0
- data/examples/munging/wikipedia/articles/extract_articles-templated.rb +136 -0
- data/examples/munging/wikipedia/articles/textualize_articles.rb +54 -0
- data/examples/munging/wikipedia/articles/verify_structure.rb +43 -0
- data/examples/munging/wikipedia/articles/wp2txt-LICENSE.txt +22 -0
- data/examples/munging/wikipedia/articles/wp2txt_article.rb +259 -0
- data/examples/munging/wikipedia/articles/wp2txt_utils.rb +452 -0
- data/examples/munging/wikipedia/dbpedia/dbpedia_common.rb +5 -0
- data/examples/munging/wikipedia/dbpedia/dbpedia_extract_geocoordinates.rb +78 -0
- data/examples/munging/wikipedia/dbpedia/extract_links-cruft.rb +66 -0
- data/examples/munging/wikipedia/dbpedia/extract_links.rb +260 -0
- data/examples/munging/wikipedia/dbpedia/sameas_extractor.rb +20 -0
- data/examples/rake_helper.rb +97 -0
- data/examples/ruby_project/Gemfile +6 -0
- data/examples/ruby_project/README.md +6 -0
- data/examples/ruby_project/a/b/c/.gitkeep +0 -0
- data/examples/server_logs/geo_ip_mapping/munge_geolite.rb +82 -0
- data/examples/server_logs/logline.rb +95 -0
- data/examples/server_logs/models.rb +66 -0
- data/examples/server_logs/page_counts.pig +48 -0
- data/examples/server_logs/server_logs-01-parse-script.rb +13 -0
- data/examples/server_logs/server_logs-02-histograms-full.rb +33 -0
- data/examples/server_logs/server_logs-02-histograms-mapper.rb +14 -0
- data/examples/server_logs/server_logs-03-breadcrumbs-full.rb +71 -0
- data/examples/server_logs/server_logs-04-page_page_edges-full.rb +40 -0
- data/examples/serverlogs/geo_ip_mapping/munge_geolite.rb +82 -0
- data/examples/serverlogs/models/logline.rb +102 -0
- data/examples/serverlogs/parser/apache_parser_widget.rb +46 -0
- data/examples/serverlogs/visit_paths/common.rb +4 -0
- data/examples/serverlogs/visit_paths/page_counts.pig +48 -0
- data/examples/serverlogs/visit_paths/serverlogs-01-parse-script.rb +11 -0
- data/examples/serverlogs/visit_paths/serverlogs-02-histograms-full.rb +31 -0
- data/examples/serverlogs/visit_paths/serverlogs-02-histograms-mapper.rb +12 -0
- data/examples/serverlogs/visit_paths/serverlogs-03-breadcrumbs-full.rb +67 -0
- data/examples/serverlogs/visit_paths/serverlogs-04-page_page_edges-full.rb +38 -0
- data/examples/splitter.rb +94 -0
- data/examples/string_reverser.rb +7 -0
- data/examples/text/pig_latin/pig_latinizer.rb +35 -0
- data/examples/text/pig_latin/pig_latinizer_widget.rb +16 -0
- data/examples/text/regional_flavor/README.md +14 -0
- data/examples/text/regional_flavor/article_wordbags.pig +39 -0
- data/examples/text/regional_flavor/j01-article_wordbags.rb +4 -0
- data/examples/text/regional_flavor/simple_pig_script.pig +27 -0
- data/examples/twitter.rb +5 -0
- data/lib/hanuman.rb +36 -0
- data/lib/hanuman/graph.rb +97 -0
- data/lib/hanuman/graphvizzer.rb +206 -0
- data/lib/hanuman/graphvizzer/gv_models.rb +161 -0
- data/lib/hanuman/graphvizzer/gv_presenter.rb +97 -0
- data/lib/hanuman/link.rb +35 -0
- data/lib/hanuman/registry.rb +46 -0
- data/lib/hanuman/stage.rb +128 -0
- data/lib/hanuman/tree.rb +67 -0
- data/lib/wu/geo.rb +4 -0
- data/lib/wu/geo/geo_grids.numbers +0 -0
- data/lib/wu/geo/geolocated.rb +331 -0
- data/lib/wu/geo/quadtile.rb +69 -0
- data/lib/wu/graph/union_find.rb +62 -0
- data/lib/wu/model/reconcilable.rb +63 -0
- data/lib/wu/munging.rb +71 -0
- data/lib/wu/social/models/twitter.rb +31 -0
- data/lib/wu/wikipedia/models.rb +20 -0
- data/lib/wukong.rb +54 -0
- data/lib/wukong/dataflow.rb +43 -0
- data/lib/wukong/doc_helpers.rb +14 -0
- data/lib/wukong/doc_helpers/dataflow_handler.rb +29 -0
- data/lib/wukong/doc_helpers/field_handler.rb +91 -0
- data/lib/wukong/doc_helpers/processor_handler.rb +29 -0
- data/lib/wukong/driver.rb +214 -0
- data/lib/wukong/driver/event_machine_driver.rb +15 -0
- data/lib/wukong/driver/wiring.rb +68 -0
- data/lib/wukong/local.rb +42 -0
- data/lib/wukong/local/runner.rb +96 -0
- data/lib/wukong/local/stdio_driver.rb +104 -0
- data/lib/wukong/logger.rb +102 -0
- data/lib/wukong/model/faker.rb +136 -0
- data/lib/wukong/model/flatpack_parser/flat.rb +60 -0
- data/lib/wukong/model/flatpack_parser/flatpack.rb +4 -0
- data/lib/wukong/model/flatpack_parser/lang.rb +46 -0
- data/lib/wukong/model/flatpack_parser/parser.rb +55 -0
- data/lib/wukong/model/flatpack_parser/tokens.rb +130 -0
- data/lib/wukong/plugin.rb +48 -0
- data/lib/wukong/processor.rb +110 -0
- data/lib/wukong/rake_helper.rb +6 -0
- data/lib/wukong/runner.rb +169 -0
- data/lib/wukong/runner/boot_sequence.rb +123 -0
- data/lib/wukong/runner/code_loader.rb +52 -0
- data/lib/wukong/runner/command_runner.rb +44 -0
- data/lib/wukong/runner/deploy_pack_loader.rb +75 -0
- data/lib/wukong/runner/help_message.rb +42 -0
- data/lib/wukong/source.rb +33 -0
- data/lib/wukong/source/source_driver.rb +74 -0
- data/lib/wukong/source/source_runner.rb +38 -0
- data/lib/wukong/spec_helpers.rb +74 -0
- data/lib/wukong/spec_helpers/integration_tests.rb +150 -0
- data/lib/wukong/spec_helpers/integration_tests/integration_test_matchers.rb +207 -0
- data/lib/wukong/spec_helpers/integration_tests/integration_test_runner.rb +97 -0
- data/lib/wukong/spec_helpers/shared_examples.rb +22 -0
- data/lib/wukong/spec_helpers/unit_tests.rb +135 -0
- data/lib/wukong/spec_helpers/unit_tests/unit_test_driver.rb +132 -0
- data/lib/wukong/spec_helpers/unit_tests/unit_test_matchers.rb +169 -0
- data/lib/wukong/spec_helpers/unit_tests/unit_test_runner.rb +60 -0
- data/lib/wukong/version.rb +3 -0
- data/lib/wukong/widget/echo.rb +55 -0
- data/lib/wukong/widget/extract.rb +122 -0
- data/lib/wukong/widget/filters.rb +452 -0
- data/lib/wukong/widget/logger.rb +56 -0
- data/lib/wukong/widget/operators.rb +82 -0
- data/lib/wukong/widget/reducers.rb +10 -0
- data/lib/wukong/widget/reducers/accumulator.rb +73 -0
- data/lib/wukong/widget/reducers/bin.rb +368 -0
- data/lib/wukong/widget/reducers/count.rb +73 -0
- data/lib/wukong/widget/reducers/group.rb +128 -0
- data/lib/wukong/widget/reducers/group_concat.rb +98 -0
- data/lib/wukong/widget/reducers/improver.rb +71 -0
- data/lib/wukong/widget/reducers/join_xml.rb +37 -0
- data/lib/wukong/widget/reducers/moments.rb +72 -0
- data/lib/wukong/widget/reducers/sort.rb +180 -0
- data/lib/wukong/widget/reducers/uniq.rb +91 -0
- data/lib/wukong/widget/serializers.rb +317 -0
- data/lib/wukong/widget/utils.rb +46 -0
- data/lib/wukong/widgets.rb +7 -0
- data/spec/examples/dataflow/fibonacci_series_spec.rb +18 -0
- data/spec/examples/dataflow/parse_apache_logs_spec.rb +8 -0
- data/spec/examples/dataflow/parsing_spec.rb +14 -0
- data/spec/examples/dataflow/simple_spec.rb +34 -0
- data/spec/examples/dataflow/telegram_spec.rb +43 -0
- data/spec/examples/graph/minimum_spanning_tree_spec.rb +34 -0
- data/spec/examples/munging/airline_flights/identifiers_spec.rb +16 -0
- data/spec/examples/munging/airline_flights_spec.rb +202 -0
- data/spec/examples/text/pig_latin_spec.rb +18 -0
- data/spec/examples/workflow/cherry_pie_spec.rb +36 -0
- data/spec/hanuman/graph_spec.rb +119 -0
- data/spec/hanuman/hanuman_spec.rb +10 -0
- data/spec/hanuman/registry_spec.rb +123 -0
- data/spec/hanuman/stage_spec.rb +81 -0
- data/spec/hanuman/tree_spec.rb +119 -0
- data/spec/spec.opts +1 -0
- data/spec/spec_helper.rb +43 -0
- data/spec/support/example_test_helpers.rb +95 -0
- data/spec/support/hanuman_test_helpers.rb +92 -0
- data/spec/support/integration_helper.rb +38 -0
- data/spec/support/model_test_helpers.rb +115 -0
- data/spec/support/shared_context_for_graphs.rb +57 -0
- data/spec/support/shared_context_for_reducers.rb +37 -0
- data/spec/support/shared_examples_for_builders.rb +94 -0
- data/spec/support/shared_examples_for_shortcuts.rb +57 -0
- data/spec/wu/model/reconcilable_spec.rb +152 -0
- data/spec/wukong/dataflow_spec.rb +87 -0
- data/spec/wukong/driver_spec.rb +154 -0
- data/spec/wukong/local/runner_spec.rb +29 -0
- data/spec/wukong/local/stdio_driver_spec.rb +73 -0
- data/spec/wukong/local_spec.rb +6 -0
- data/spec/wukong/logger_spec.rb +49 -0
- data/spec/wukong/model/faker_spec.rb +132 -0
- data/spec/wukong/processor_spec.rb +21 -0
- data/spec/wukong/runner_spec.rb +132 -0
- data/spec/wukong/source_spec.rb +6 -0
- data/spec/wukong/widget/extract_spec.rb +101 -0
- data/spec/wukong/widget/filters_spec.rb +79 -0
- data/spec/wukong/widget/logger_spec.rb +23 -0
- data/spec/wukong/widget/operators_spec.rb +25 -0
- data/spec/wukong/widget/reducers/bin_spec.rb +92 -0
- data/spec/wukong/widget/reducers/count_spec.rb +11 -0
- data/spec/wukong/widget/reducers/group_spec.rb +21 -0
- data/spec/wukong/widget/reducers/join_xml_spec.rb +25 -0
- data/spec/wukong/widget/reducers/moments_spec.rb +36 -0
- data/spec/wukong/widget/reducers/sort_spec.rb +26 -0
- data/spec/wukong/widget/reducers/uniq_spec.rb +14 -0
- data/spec/wukong/widget/serializers_spec.rb +114 -0
- data/spec/wukong/widget/sink_spec.rb +19 -0
- data/spec/wukong/widget/source_spec.rb +65 -0
- data/spec/wukong/wu-local_spec.rb +109 -0
- data/spec/wukong/wu-source_spec.rb +32 -0
- data/spec/wukong/wu_spec.rb +14 -0
- data/spec/wukong/wukong_spec.rb +10 -0
- data/wukong.gemspec +35 -0
- metadata +465 -0
@@ -0,0 +1,37 @@
|
|
1
|
+
shared_context "reducers" do
|
2
|
+
|
3
|
+
let(:strings) { %w[apple banana apple cookie] }
|
4
|
+
let(:nums) { %w[7 7 0 10 3 5 7 6 3 7 3 5 3 1 9 8 3 9 4 2 6 10 9 0 7 7 9 5 2 0 4 9 9 5 9 6 10 2 0 8 4 0 0 1 7 9 5 6 3 0] }
|
5
|
+
let(:json) do
|
6
|
+
[
|
7
|
+
'{"data":{}}',
|
8
|
+
'{"data":{"n":1,"inner":"snap"},"outer":"apple"}',
|
9
|
+
'{"data":{"n":100,"inner":"crackle"},"outer":"banana"}',
|
10
|
+
'{"data":{"n":5,"inner":"crackle"},"outer":"apple"}',
|
11
|
+
'{"data":{"n":10,"inner":"pop"},"outer":"cookie"}',
|
12
|
+
'{"data":{}}'
|
13
|
+
]
|
14
|
+
end
|
15
|
+
|
16
|
+
let(:json_sorted_n) do
|
17
|
+
json.map { |j| MultiJson.load(j) }.sort_by { |o| o['data']['n'].to_i }.map { |o| MultiJson.dump(o) }
|
18
|
+
end
|
19
|
+
|
20
|
+
let(:json_sorted_outer) do
|
21
|
+
json.map { |j| MultiJson.load(j) }.sort_by { |o| o['outer'] || '' }.map { |o| MultiJson.dump(o) }
|
22
|
+
end
|
23
|
+
|
24
|
+
let(:tsv) do
|
25
|
+
[
|
26
|
+
"\tb\t",
|
27
|
+
"apple\tsnap\t1",
|
28
|
+
"banana\tcrackle\t100",
|
29
|
+
"apple\tcrackle\t5",
|
30
|
+
"cookie\tpop\t10",
|
31
|
+
"b"
|
32
|
+
]
|
33
|
+
end
|
34
|
+
|
35
|
+
let(:tsv_sorted) { tsv.sort_by { |t| t.split("\t")[2].to_i } }
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
shared_examples_for 'a Stage::Builder' do
|
2
|
+
before(:each) do
|
3
|
+
@registry = Hanuman::GlobalRegistry.show
|
4
|
+
Hanuman::GlobalRegistry.clear!
|
5
|
+
end
|
6
|
+
|
7
|
+
after(:each) do
|
8
|
+
Hanuman::GlobalRegistry.merge! @registry
|
9
|
+
end
|
10
|
+
|
11
|
+
context '.receive' do
|
12
|
+
it 'extra arguments are stored in the :args attribute' do
|
13
|
+
subject = described_class.receive(uncanny: 'x-men')
|
14
|
+
subject.args.should == { uncanny: 'x-men' }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
context '#define' do
|
19
|
+
let(:test_klass){ Object.const_get('WhiteQueen') }
|
20
|
+
|
21
|
+
around(:each) do |example|
|
22
|
+
Object.const_set('WhiteQueen', Class.new(subject.namespace))
|
23
|
+
example.run
|
24
|
+
Object.send(:remove_const, 'WhiteQueen')
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'returns a Hanuman::Stage class definition' do
|
28
|
+
subject.label = :white_queen
|
29
|
+
subject.define.superclass.should be(subject.namespace)
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'registers the defined class' do
|
33
|
+
subject.for_class = test_klass
|
34
|
+
test_klass.should_receive(:register)
|
35
|
+
subject.define
|
36
|
+
end
|
37
|
+
|
38
|
+
context 'without :for_class attribute set' do
|
39
|
+
it 'does not create a class definition' do
|
40
|
+
subject.for_class = test_klass
|
41
|
+
subject.should_not_receive(:define_class)
|
42
|
+
subject.define
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'with :for_class attribute set' do
|
47
|
+
it 'creates a class definition' do
|
48
|
+
subject.label = :white_queen
|
49
|
+
subject.should_receive(:define_class).with(:white_queen).and_return(test_klass)
|
50
|
+
subject.define
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context '#define_class' do
|
56
|
+
around(:each) do |example|
|
57
|
+
subject.namespace.const_set('ProfessorX', Class.new(subject.namespace))
|
58
|
+
example.run
|
59
|
+
subject.namespace.send(:remove_const, 'ProfessorX')
|
60
|
+
end
|
61
|
+
|
62
|
+
context 'already defined within the namespace' do
|
63
|
+
it 'does not define the class again' do
|
64
|
+
subject.namespace.should_not_receive(:const_set)
|
65
|
+
subject.define_class(:professor_x)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
context 'not defined within the namespace' do
|
70
|
+
let(:defined_class){ double :magneto, :set_builder => true }
|
71
|
+
|
72
|
+
it 'defines the class' do
|
73
|
+
subject.namespace.should_receive(:const_set).with('Magneto', an_instance_of(Class)).and_return(defined_class)
|
74
|
+
subject.define_class(:magneto)
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'builder attribute' do
|
79
|
+
let(:test_klass) { subject.namespace.const_get('ProfessorX') }
|
80
|
+
|
81
|
+
it 'sets the defined class builder attribute' do
|
82
|
+
test_klass.should_receive(:set_builder).with(subject)
|
83
|
+
subject.define_class(:professor_x)
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
context '#serialize' do
|
89
|
+
it 'serializes into a hash' do
|
90
|
+
subject.serialize.should include(:label)
|
91
|
+
subject.serialize.should_not include(:args, :for_class)
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
shared_examples_for Hanuman::Shortcuts do
|
2
|
+
|
3
|
+
before(:each) do
|
4
|
+
@orig_reg = subject.registry.show
|
5
|
+
subject.registry.clear!
|
6
|
+
end
|
7
|
+
|
8
|
+
after(:each) do
|
9
|
+
subject.registry.clear!
|
10
|
+
subject.registry.merge!(@orig_reg)
|
11
|
+
end
|
12
|
+
|
13
|
+
context '.registry' do
|
14
|
+
it 'returns the registry' do
|
15
|
+
subject.registry.should == Hanuman::GlobalRegistry
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context '.add_shortcut_method_for' do
|
20
|
+
let(:shortcut){ :banshee }
|
21
|
+
it 'add shortcut methods for creating builders' do
|
22
|
+
expect{ subject.add_shortcut_method_for(shortcut, Hanuman::StageBuilder) }.to change{ subject.respond_to? shortcut }.from(false).to(true)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
context '.builder_shortcut' do
|
27
|
+
context 'with an existing definition' do
|
28
|
+
let(:existing_definition){ Hanuman::StageBuilder.receive(label: :sunfire) }
|
29
|
+
|
30
|
+
it 'returns the existing definition from the registry' do
|
31
|
+
subject.registry.create(:sunfire, existing_definition)
|
32
|
+
subject.registry.should_receive(:retrieve).with(:sunfire).and_return(existing_definition)
|
33
|
+
subject.builder_shortcut(Hanuman::StageBuilder, :sunfire)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'with a nonexisting definition' do
|
38
|
+
let(:mock_builder_type){ double :builder_type }
|
39
|
+
let(:mock_builder) { double :builder }
|
40
|
+
let(:block_arg) { ->(){ def absorb() 'radiation' ; end } }
|
41
|
+
|
42
|
+
it 'creates a new definition using the supplied builder_type' do
|
43
|
+
mock_builder_type.should_receive(:receive).with(label: :sunfire).and_return mock_builder
|
44
|
+
mock_builder.should_receive(:define).with(&block_arg)
|
45
|
+
subject.builder_shortcut(mock_builder_type, :sunfire, &block_arg)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'graph builder decoration' do
|
50
|
+
it 'decorates the builder with registry methods if the builder is a GraphBuilder' do
|
51
|
+
Hanuman::GlobalRegistry.should_receive(:decorate_with_registry).with an_instance_of(Hanuman::GraphBuilder)
|
52
|
+
subject.builder_shortcut(Hanuman::GraphBuilder, :sunfire)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,152 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'gorillib/model'
|
3
|
+
require 'wu/model/reconcilable'
|
4
|
+
require 'support/model_test_helpers'
|
5
|
+
|
6
|
+
describe Gorillib::Model::Reconcilable, :model_spec do
|
7
|
+
|
8
|
+
before do
|
9
|
+
smurfhouse_class.class_eval do
|
10
|
+
include Gorillib::Model::Reconcilable
|
11
|
+
end
|
12
|
+
smurf_class.class_eval do
|
13
|
+
include Gorillib::Model::Reconcilable
|
14
|
+
field :cromulence, Integer
|
15
|
+
field :smurfhouse, Gorillib::Test::Smurfhouse
|
16
|
+
end
|
17
|
+
end
|
18
|
+
let(:empty_smurf){ smurf_class.new(name: nil) }
|
19
|
+
let(:angry_smurf){ smurf_class.new(name: 'Angry Smurf', smurfiness: 20, weapon: :smurfchucks) }
|
20
|
+
let(:handy_smurf){ smurf_class.new(name: 'Handy Smurf', smurfiness: 20, weapon: :monkeysmurf) }
|
21
|
+
subject{ smurf_class.new(name: 'Handy Smurf', smurfiness: 20, weapon: :monkeysmurf) }
|
22
|
+
|
23
|
+
context '#reconcilable_attributes' do
|
24
|
+
it 'returns only unset, non-nil values' do
|
25
|
+
subject.weapon = nil
|
26
|
+
subject.reconcilable_attributes.should == { name: 'Handy Smurf', smurfiness: 20 }
|
27
|
+
subject.compact_attributes.should == { name: 'Handy Smurf', smurfiness: 20, weapon: nil }
|
28
|
+
empty_smurf.reconcilable_attributes.should == {}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
context '#conflicting_attribute!' do
|
33
|
+
it 'warns by default' do
|
34
|
+
stdout, stderr = capture_output{ subject.conflicting_attribute!(:weapon, :monkeysmurf, :smurfwrench) }
|
35
|
+
stderr.string.should =~ /conflicting.* weapon: had :monkeysmurf got :smurfwrench\b/
|
36
|
+
end
|
37
|
+
it 'returns false always by default' do
|
38
|
+
subject.stub(:warn)
|
39
|
+
subject.conflicting_attribute!(:weapon, :monkeysmurf, :smurfwrench).should == false
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context '#adopt' do
|
44
|
+
it 'returns true on compatible, false on incompatible' do
|
45
|
+
subject.stub(:warn)
|
46
|
+
subject.adopt(empty_smurf).should be_true
|
47
|
+
subject.adopt(angry_smurf).should be_false
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'calls adopt_foo instead of adopt_attribute(:foo, ...) if present' do
|
51
|
+
subject.should_receive(:adopt_weapon).with(:smurfchucks, angry_smurf).and_return true
|
52
|
+
subject.should_receive(:adopt_name ).with('Angry Smurf', angry_smurf).and_return true
|
53
|
+
subject.adopt(angry_smurf).should be_true
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'on compatible objects' do
|
57
|
+
before{ subject.should_not_receive(:conflicting_attribute!) }
|
58
|
+
it 'makes no changes from unset or nil values' do
|
59
|
+
subject.adopt(empty_smurf).should be_true
|
60
|
+
subject.should == handy_smurf
|
61
|
+
end
|
62
|
+
it 'makes no changes from equal values' do
|
63
|
+
subject.adopt(handy_smurf).should be_true
|
64
|
+
subject.should == handy_smurf
|
65
|
+
end
|
66
|
+
it 'sets unset attributes to the other value' do
|
67
|
+
handy_smurf.cromulence = 99
|
68
|
+
subject.attribute_set?(:cromulence).should be_false
|
69
|
+
subject.adopt(handy_smurf).should be_true
|
70
|
+
subject.should == handy_smurf
|
71
|
+
subject.cromulence.should == 99
|
72
|
+
end
|
73
|
+
it 'sets nil attributes to the other value' do
|
74
|
+
handy_smurf.cromulence = 99
|
75
|
+
subject.cromulence = nil
|
76
|
+
subject.attribute_set?(:cromulence).should be_true
|
77
|
+
subject.adopt(handy_smurf).should be_true
|
78
|
+
subject.should == handy_smurf
|
79
|
+
subject.cromulence.should == 99
|
80
|
+
end
|
81
|
+
it 'asks adoptable attribute to adopt other value' do
|
82
|
+
handy_smurf.smurfhouse = smurfhouse_class.new(color: :brown)
|
83
|
+
sh = subject.smurfhouse = smurfhouse_class.new(shape: :mushroom)
|
84
|
+
subject.adopt(handy_smurf).should be_true
|
85
|
+
subject.smurfhouse.attributes.should == { shape: :mushroom, color: :brown }
|
86
|
+
subject.smurfhouse.should equal(sh)
|
87
|
+
end
|
88
|
+
it 'does not call block' do
|
89
|
+
subject.adopt(empty_smurf){ raise 'should not call block' }
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context 'on incompatible objects' do
|
94
|
+
it 'returns the value of conflicting_attribute!' do
|
95
|
+
subject.weapon = :smurfwrench
|
96
|
+
subject.should_receive(:conflicting_attribute!).with(:weapon, :smurfwrench, :monkeysmurf).and_return(false)
|
97
|
+
subject.adopt(handy_smurf).should be_false
|
98
|
+
end
|
99
|
+
it 'returns the value of conflicting_attribute!' do
|
100
|
+
subject.weapon = :smurfwrench
|
101
|
+
subject.should_receive(:conflicting_attribute!).with(:weapon, :smurfwrench, :monkeysmurf).and_return(true)
|
102
|
+
subject.adopt(handy_smurf).should be_true
|
103
|
+
end
|
104
|
+
it 'keeps its own value' do
|
105
|
+
subject.stub(:conflicting_attribute!)
|
106
|
+
subject.weapon = :smurfwrench
|
107
|
+
subject.adopt(handy_smurf)
|
108
|
+
subject.weapon.should == :smurfwrench
|
109
|
+
end
|
110
|
+
it 'adoptible attributes reconcile' do
|
111
|
+
handy_smurf.smurfhouse = smurfhouse_class.new(color: :brown)
|
112
|
+
sh = subject.smurfhouse = smurfhouse_class.new(shape: :mushroom, color: :red)
|
113
|
+
sh.should_receive(:conflicting_attribute!).with(:color, :red, :brown)
|
114
|
+
#
|
115
|
+
subject.adopt(handy_smurf).should be_false
|
116
|
+
subject.smurfhouse.attributes.should == { shape: :mushroom, color: :red }
|
117
|
+
subject.smurfhouse.should equal(sh)
|
118
|
+
end
|
119
|
+
it 'adoptible attributes reconcile and warn' do
|
120
|
+
subject.should_not_receive(:conflicting_attribute!)
|
121
|
+
handy_smurf.smurfhouse = smurfhouse_class.new(color: :brown)
|
122
|
+
sh = subject.smurfhouse = smurfhouse_class.new(shape: :mushroom, color: :red)
|
123
|
+
sh.should_receive(:conflicting_attribute!).with(:color, :red, :brown)
|
124
|
+
#
|
125
|
+
subject.adopt(handy_smurf)
|
126
|
+
end
|
127
|
+
it 'does not take a block' do
|
128
|
+
subject.stub(:warn)
|
129
|
+
subject.adopt(angry_smurf){ raise 'should not call block' }
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
context '#adopt_attribute' do
|
135
|
+
context 'takse a block (useful in overrides):' do
|
136
|
+
it 'on compatible values, block is not called' do
|
137
|
+
subject.should_not_receive(:conflicting_attribute!)
|
138
|
+
subject.send(:adopt_attribute, :weapon, :monkeysmurf) do
|
139
|
+
raise 'should not call block'
|
140
|
+
end
|
141
|
+
end
|
142
|
+
it 'on incompatible values, block is called instead of conflicting_attribute!' do
|
143
|
+
subject.should_not_receive(:conflicting_attribute!)
|
144
|
+
subject.send(:adopt_attribute, :weapon, :smurfwrench) do
|
145
|
+
mock_val
|
146
|
+
end.should == mock_val
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
|
152
|
+
end
|
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Wukong::Dataflow do
|
4
|
+
|
5
|
+
# context '#handle_dsl_methods_for' do
|
6
|
+
# let(:block_arg){ ->(rec){ transform_into('kitty pryde') } }
|
7
|
+
# it 'accepts a block and assigns it to an :action key' do
|
8
|
+
# graph_builder.send(:mystique, &block_arg)
|
9
|
+
# graph_builder.stages[:mystique].serialize.should include(action: block_arg)
|
10
|
+
# end
|
11
|
+
# end
|
12
|
+
|
13
|
+
end
|
14
|
+
|
15
|
+
# describe Wukong::Chain, :helpers => true do
|
16
|
+
# subject{ described_class.new }
|
17
|
+
# let(:test_re){ /^f/ }
|
18
|
+
|
19
|
+
# context 'examples' do
|
20
|
+
|
21
|
+
# subject{
|
22
|
+
# test_sink = test_sink()
|
23
|
+
# Wukong.chain(:integers) do
|
24
|
+
# set_source Wukong::Source::Integers.new(:qty => 100)
|
25
|
+
# set_sink test_sink
|
26
|
+
|
27
|
+
# input(:default) >
|
28
|
+
# map{|i| i.to_s } >
|
29
|
+
# re(/..+/) >
|
30
|
+
# map(&:reverse) >
|
31
|
+
# limit(20) >
|
32
|
+
# output(:default)
|
33
|
+
# end
|
34
|
+
# Wukong::LocalRunner.receive(:flow => Wukong.chain(:integers))
|
35
|
+
# }
|
36
|
+
|
37
|
+
# it 'runs' do
|
38
|
+
# subject.run(:default)
|
39
|
+
# subject.flow.output(:default).records.should == ["01", "11", "21", "31", "41", "51", "61", "71", "81", "91", "02", "12", "22", "32", "42", "52", "62", "72", "82", "92"]
|
40
|
+
# end
|
41
|
+
|
42
|
+
# end
|
43
|
+
|
44
|
+
# context '#select' do
|
45
|
+
# it 'evaluates block arg on each record, selecting if true' do
|
46
|
+
# result = subject.select{|rec| rec.odd? }
|
47
|
+
# result.should be_a(Wukong::Widget::Select)
|
48
|
+
# result.should be_select(3)
|
49
|
+
# result.should_not be_select(2)
|
50
|
+
# end
|
51
|
+
|
52
|
+
# it 'given proc as plain arg, evaluates it on each record, selecting if true' do
|
53
|
+
# result = subject.select( ->(rec){ rec.odd? } )
|
54
|
+
# result.should be_a(Wukong::Widget::Select)
|
55
|
+
# result.should be_select(3)
|
56
|
+
# result.should_not be_select(2)
|
57
|
+
# end
|
58
|
+
|
59
|
+
# it 'adds a stage to the dataflow' do
|
60
|
+
# p subject.stages
|
61
|
+
# subject.stages.should_receive(:receive_item).with(:select_1, kind_of(Wukong::Widget::Select))
|
62
|
+
# subject.select{|rec| rec =~ /^h/ }.should be_a(Wukong::Widget::Select)
|
63
|
+
# p subject.stages
|
64
|
+
# end
|
65
|
+
# end
|
66
|
+
|
67
|
+
# context '#reject' do
|
68
|
+
# it 'evaluates block arg on each record, rejecting if true' do
|
69
|
+
# result = subject.reject{|rec| rec.odd? }
|
70
|
+
# result.should be_a(Wukong::Widget::Reject)
|
71
|
+
# result.should_not be_select(3)
|
72
|
+
# result.should be_select(2)
|
73
|
+
# end
|
74
|
+
|
75
|
+
# it 'given proc as plain arg, evaluates it on each record, rejecting if true' do
|
76
|
+
# result = subject.reject( ->(rec){ rec.odd? } )
|
77
|
+
# result.should be_a(Wukong::Widget::Reject)
|
78
|
+
# result.should_not be_select(3)
|
79
|
+
# result.should be_select(2)
|
80
|
+
# end
|
81
|
+
|
82
|
+
# it 'adds a stage to the dataflow' do
|
83
|
+
# subject.should_receive(:receive_item).with(:reject_0, kind_of(Wukong::Widget::Reject))
|
84
|
+
# subject.reject{|rec| rec =~ /^h/ }.should be_a(Wukong::Widget::Reject)
|
85
|
+
# end
|
86
|
+
# end
|
87
|
+
# end
|
@@ -0,0 +1,154 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Wukong::DriverMethods do
|
4
|
+
|
5
|
+
describe "#construct_dataflow" do
|
6
|
+
|
7
|
+
context "given a label registered to a processor" do
|
8
|
+
let(:driver) { Wukong::SpecHelpers::UnitTestDriver.new(:regexp, match: /hi/) }
|
9
|
+
|
10
|
+
context "constructs an anonymous dataflow" do
|
11
|
+
let(:dataflow) { driver.dataflow }
|
12
|
+
subject { dataflow }
|
13
|
+
|
14
|
+
it { should_not be_nil }
|
15
|
+
its(:label) { should be_nil }
|
16
|
+
its(:links) { should be_empty }
|
17
|
+
|
18
|
+
context "with a single stage" do
|
19
|
+
let(:stage) { dataflow.stages.values.first }
|
20
|
+
subject { stage }
|
21
|
+
|
22
|
+
it { should_not be_nil }
|
23
|
+
its(:label) { should == :regexp }
|
24
|
+
its(:match) { should == /hi/ }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
context "given a serialization argument" do
|
30
|
+
context "that does not match a registered serializer" do
|
31
|
+
it "raises an error" do
|
32
|
+
expect { Wukong::SpecHelpers::UnitTestDriver.new(:regexp, match: /hi/, to: 'fake') }.to raise_error(Wukong::Error)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
context "that matches a registered serializer" do
|
36
|
+
let(:driver) { Wukong::SpecHelpers::UnitTestDriver.new(:regexp, match: /hi/, to: 'json') }
|
37
|
+
let(:dataflow) { driver.dataflow }
|
38
|
+
it "appends the serializer to each of the leaves" do
|
39
|
+
dataflow.leaves.size.should == 1
|
40
|
+
dataflow.leaves.map(&:label).should_not include(:regexp)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
context "given a deserialization argument" do
|
46
|
+
let(:driver) { Wukong::SpecHelpers::UnitTestDriver.new(:regexp, match: /hi/, from: 'json') }
|
47
|
+
let(:dataflow) { driver.dataflow }
|
48
|
+
|
49
|
+
context "adds a deserializer" do
|
50
|
+
subject { dataflow.stages[:from_json] }
|
51
|
+
it { should_not be_nil }
|
52
|
+
it "which is the root of the dataflow" do
|
53
|
+
dataflow.root.should == subject
|
54
|
+
end
|
55
|
+
it "which is linked to the original root" do
|
56
|
+
dataflow.ancestors(dataflow.stages[:regexp]).should include(subject)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
context "given a recordization argument" do
|
62
|
+
let(:driver) { Wukong::SpecHelpers::UnitTestDriver.new(:regexp, match: /hi/, as: Time) }
|
63
|
+
let(:dataflow) { driver.dataflow }
|
64
|
+
|
65
|
+
context "adds a recordizer" do
|
66
|
+
subject { dataflow.stages[:recordize] }
|
67
|
+
it { should_not be_nil }
|
68
|
+
it "which is the root of the dataflow" do
|
69
|
+
dataflow.root.should == subject
|
70
|
+
end
|
71
|
+
it "which is linked to the original root" do
|
72
|
+
dataflow.ancestors(dataflow.stages[:regexp]).should include(subject)
|
73
|
+
end
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context "given deserialization and recordization arguments" do
|
78
|
+
let(:driver) { Wukong::SpecHelpers::UnitTestDriver.new(:regexp, match: /hi/, from: 'json', as: Time) }
|
79
|
+
let(:dataflow) { driver.dataflow }
|
80
|
+
let(:recordizer) { dataflow.stages[:recordize] }
|
81
|
+
let(:deserializer) { dataflow.stages[:from_json] }
|
82
|
+
|
83
|
+
context "adds a deserializer" do
|
84
|
+
subject { deserializer }
|
85
|
+
it { should_not be_nil }
|
86
|
+
it "which is the root of the dataflow" do
|
87
|
+
dataflow.root.should == subject
|
88
|
+
end
|
89
|
+
it "which is linked to the recordizer" do
|
90
|
+
dataflow.ancestors(dataflow.stages[:recordizer]).should include(subject)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
context "adds a recordizer" do
|
95
|
+
subject { recordizer }
|
96
|
+
it { should_not be_nil }
|
97
|
+
it "which is linked to the original root" do
|
98
|
+
dataflow.ancestors(dataflow.stages[:regexp]).should include(subject)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe "#setup_dataflow" do
|
106
|
+
let(:driver) { Wukong::SpecHelpers::UnitTestDriver.new(:regexp, match: /hi/) }
|
107
|
+
|
108
|
+
it "calls the driver's #setup method" do
|
109
|
+
driver.should_receive(:setup)
|
110
|
+
driver.setup_dataflow
|
111
|
+
end
|
112
|
+
|
113
|
+
it "calls setup on each stage of the dataflow" do
|
114
|
+
driver.dataflow.each_stage do |stage|
|
115
|
+
stage.should_receive(:setup)
|
116
|
+
end
|
117
|
+
driver.setup_dataflow
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
describe "#finalize_dataflow" do
|
122
|
+
let(:driver) { Wukong::SpecHelpers::UnitTestDriver.new(:regexp, match: /hi/) }
|
123
|
+
it "calls the driver's #finalize method" do
|
124
|
+
driver.should_receive(:finalize)
|
125
|
+
driver.finalize_dataflow
|
126
|
+
end
|
127
|
+
|
128
|
+
it "calls finalize on each stage of the dataflow" do
|
129
|
+
driver.dataflow.each_stage do |stage|
|
130
|
+
stage.should_receive(:finalize)
|
131
|
+
end
|
132
|
+
driver.finalize_dataflow
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
describe "#finalize_and_stop_dataflow" do
|
137
|
+
let(:driver) { Wukong::SpecHelpers::UnitTestDriver.new(:regexp, match: /hi/) }
|
138
|
+
it "calls the driver's #finalize and #stop methods" do
|
139
|
+
driver.should_receive(:finalize)
|
140
|
+
driver.should_receive(:stop)
|
141
|
+
driver.finalize_and_stop_dataflow
|
142
|
+
end
|
143
|
+
|
144
|
+
it "calls finalize and stop on each stage of the dataflow" do
|
145
|
+
driver.dataflow.each_stage do |stage|
|
146
|
+
stage.should_receive(:finalize)
|
147
|
+
stage.should_receive(:stop)
|
148
|
+
end
|
149
|
+
driver.finalize_and_stop_dataflow
|
150
|
+
end
|
151
|
+
|
152
|
+
end
|
153
|
+
|
154
|
+
end
|