arc-furnace 0.1.13 → 0.1.14

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 401438a69d2165a093c17faf0e8c3fc10b960155
4
- data.tar.gz: 870456329b0d027b6f627b97355bc91c42854c8d
3
+ metadata.gz: c014a227e52695c9f5a91ac292f21ff1850785f6
4
+ data.tar.gz: b273460b4eafdf5be12d57d3bc721c98eb4b324f
5
5
  SHA512:
6
- metadata.gz: 2a5e9147e64a189b1874d9a06f5fff23d0f9c89b06208058dc6232ab520b342fa83d104fc0e0d5f7d8fd21e8cfb44b577fa8fa54668e117ad2f3d9086c01322f
7
- data.tar.gz: 0e14d178fc361a6ea7cb7e8a96be7537064f2cb95ea2a487fe00d0044ea14d824b89b5d9cfe5871361c5f2d778b3273a6c8d1094b0432940395c89b2920e3f7c
6
+ metadata.gz: 661e36f39e6389337bd70f0b12a618a646345353c271a96087894c3ed2b616520519d10d2c4072b8a139f2174a04ffc63b4ad7d7339f6c22b8730222fda104f0
7
+ data.tar.gz: c47fdb6fa20296507f24ff79076816fbca19b06a6c94b9b3b151c3cda6d571049e138a46fe38e6b845ed992a412977c29e2692d697919849c53372f1bb69cec3
@@ -0,0 +1,22 @@
1
+ require 'arc-furnace/observer'
2
+
3
+ module ArcFurnace
4
+ class BlockObserver < Observer
5
+ private_attr_reader :block
6
+
7
+ def initialize(source:, block:)
8
+ raise 'Must specify a block' if block.nil?
9
+ @block = block
10
+ super(source: source)
11
+ end
12
+
13
+ def observe(row)
14
+ if block.arity == 2
15
+ block.call(row, params)
16
+ else
17
+ block.call(row)
18
+ end
19
+ end
20
+
21
+ end
22
+ end
@@ -1,6 +1,7 @@
1
1
  require 'arc-furnace/all_fields_csv_sink'
2
2
  require 'arc-furnace/binary_key_merging_hash'
3
3
  require 'arc-furnace/block_filter'
4
+ require 'arc-furnace/block_observer'
4
5
  require 'arc-furnace/block_transform'
5
6
  require 'arc-furnace/block_unfold'
6
7
  require 'arc-furnace/csv_sink'
@@ -14,6 +15,7 @@ require 'arc-furnace/merging_hash'
14
15
  require 'arc-furnace/multi_csv_source'
15
16
  require 'arc-furnace/node'
16
17
  require 'arc-furnace/null_sink'
18
+ require 'arc-furnace/observer'
17
19
  require 'arc-furnace/outer_join'
18
20
  require 'arc-furnace/sink'
19
21
  require 'arc-furnace/source'
@@ -0,0 +1,29 @@
1
+ require 'arc-furnace/source'
2
+
3
+ # Observe all values in an input stream. All values are passed down
4
+ # to the next node un-adultered.
5
+ module ArcFurnace
6
+ class Observer < Source
7
+ private_attr_reader :source
8
+
9
+ def initialize(source:)
10
+ @source = source
11
+ end
12
+
13
+ def value
14
+ value = source.value.deep_dup
15
+ observe(value) if value
16
+ value
17
+ end
18
+
19
+ delegate [:empty?, :advance] => :source
20
+
21
+ # Observes each row in the node's input stream. This node should not
22
+ # modify the row passed.
23
+ #
24
+ # This method's return value is ignored
25
+ def observe(row)
26
+ raise "Unimplemented"
27
+ end
28
+ end
29
+ end
@@ -89,6 +89,18 @@ module ArcFurnace
89
89
  define_intermediate(node_id, type: type, params: params)
90
90
  end
91
91
 
92
+ # Define a node that observes rows. By default you get a BlockObserver
93
+ # (and when this metaprogramming method is passed a block) that will be passed
94
+ # a hash for each row. The result of the block is ignored; all rows
95
+ # are forwarded to the next node in the line
96
+ def self.observer(node_id, type: BlockObserver, params: {}, &block)
97
+ if block_given? && type <= BlockObserver
98
+ params[:block] = block
99
+ end
100
+ raise "Observer #{type} is not an Observer!" unless type <= Observer
101
+ define_intermediate(node_id, type: type, params: params)
102
+ end
103
+
92
104
  # Create an instance to run a transformation, passing the parameters to
93
105
  # instantiate the transform instance with. The resulting class instance
94
106
  # will have a single public method--#execute, which will perform the
@@ -1,3 +1,3 @@
1
1
  module ArcFurnace
2
- VERSION = "0.1.13"
2
+ VERSION = "0.1.14"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: arc-furnace
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.13
4
+ version: 0.1.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Spangenberger
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2016-01-15 00:00:00.000000000 Z
12
+ date: 2016-01-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: msgpack
@@ -130,6 +130,7 @@ files:
130
130
  - lib/arc-furnace/all_fields_csv_sink.rb
131
131
  - lib/arc-furnace/binary_key_merging_hash.rb
132
132
  - lib/arc-furnace/block_filter.rb
133
+ - lib/arc-furnace/block_observer.rb
133
134
  - lib/arc-furnace/block_transform.rb
134
135
  - lib/arc-furnace/block_unfold.rb
135
136
  - lib/arc-furnace/csv_sink.rb
@@ -149,6 +150,7 @@ files:
149
150
  - lib/arc-furnace/node.rb
150
151
  - lib/arc-furnace/nodes.rb
151
152
  - lib/arc-furnace/null_sink.rb
153
+ - lib/arc-furnace/observer.rb
152
154
  - lib/arc-furnace/outer_join.rb
153
155
  - lib/arc-furnace/pipeline.rb
154
156
  - lib/arc-furnace/private_attr.rb