Skip to content
Browse files

Merging

  • Loading branch information...
2 parents 9f594e2 + 00fd524 commit d41ffb8edf9f8dc1b1f1565699d4d0a6be6aaa92 @bergie bergie committed
Showing with 114 additions and 4 deletions.
  1. +6 −3 component.json
  2. +53 −0 components/GenerateGroup.coffee
  3. +2 −1 package.json
  4. +53 −0 test/GenerateGroup.coffee
View
9 component.json
@@ -12,7 +12,8 @@
"dependencies": {
"component/underscore": "*",
"noflo/noflo": "*",
- "noflo/noflo-core": "*"
+ "noflo/noflo-core": "*",
+ "broofa/node-uuid": "*"
},
"scripts": [
"components/ReadGroups.coffee",
@@ -32,8 +33,9 @@
"components/MapGroup.coffee",
"components/MergeGroups.coffee",
"components/GroupByObjectKey.coffee",
- "index.js",
- "graphs/ObjectifyByGroup.fbp"
+ "graphs/ObjectifyByGroup.fbp",
+ "components/GenerateGroup.coffee",
+ "index.js"
],
"json": [
"component.json"
@@ -46,6 +48,7 @@
"CollectTree": "components/CollectTree.coffee",
"FilterByGroup": "components/FilterByGroup.coffee",
"FirstGroup": "components/FirstGroup.coffee",
+ "GenerateGroup": "components/GenerateGroup.coffee",
"Group": "components/Group.coffee",
"GroupByObjectKey": "components/GroupByObjectKey.coffee",
"GroupZip": "components/GroupZip.coffee",
View
53 components/GenerateGroup.coffee
@@ -0,0 +1,53 @@
+noflo = require 'noflo'
+uuid = require 'node-uuid'
+
+class GenerateGroup extends noflo.Component
+
+ description: 'Wrap IPs into a random uuid generated group'
+
+ constructor: ->
+ @inPorts =
+ in: new noflo.Port 'all'
+ @outPorts =
+ out: new noflo.Port 'all'
+
+ @groups = []
+
+ @inPorts.in.on 'begingroup', (group) =>
+ @beginGroup group
+ @inPorts.in.on 'data', (data) =>
+ @pushGeneratedGroup data
+ @inPorts.in.on 'endgroup', () =>
+ @popGeneratedGroup()
+ @endGroup()
+ @inPorts.in.on 'disconnect', () =>
+ @popGeneratedGroup()
+ @clearGroups()
+ @outPorts.out.disconnect() if @outPorts.out.isConnected()
+
+ beginGroup: (group) ->
+ @groups.push { group: group, generated: false }
+ @outPorts.out.beginGroup group if @outPorts.out.isAttached()
+
+ endGroup: () ->
+ @groups.pop()
+ @outPorts.out.endGroup() if @outPorts.out.isAttached()
+
+ pushGeneratedGroup: (data) ->
+ if @groups.length < 1 or
+ (@groups.length > 0 and not @groups[@groups.length - 1].generated)
+ generated = { group: uuid(), generated: true }
+ @groups.push generated
+ @outPorts.out.beginGroup generated.group if @outPorts.out.isAttached()
+ @outPorts.out.send data if @outPorts.out.isAttached()
+
+ popGeneratedGroup: () ->
+ return if @groups.length < 1
+ return unless @groups[@groups.length - 1].generated
+ @groups.pop()
+ @outPorts.out.endGroup() if @outPorts.out.isAttached()
+
+ clearGroups: () ->
+ @groups = []
+
+exports.getComponent = -> new GenerateGroup
View
3 package.json
@@ -31,7 +31,7 @@
"dependencies": {
"noflo": "~0.5.0",
"underscore": "1.4.x",
- "noflo-cache": "~0.0.1"
+ "node-uuid": "1.4.x"
},
"devDependencies": {
"grunt-exec": "~0.4.2",
@@ -60,6 +60,7 @@
"CollectTree": "components/CollectTree.coffee",
"FilterByGroup": "components/FilterByGroup.coffee",
"FirstGroup": "components/FirstGroup.coffee",
+ "GenerateGroup": "components/GenerateGroup.coffee",
"Group": "components/Group.coffee",
"GroupByObjectKey": "components/GroupByObjectKey.coffee",
"GroupZip": "components/GroupZip.coffee",
View
53 test/GenerateGroup.coffee
@@ -0,0 +1,53 @@
+test = require "noflo-test"
+
+test.component("groups/GenerateGroup").
+ discuss("pass in a non grouped connection").
+ send.connect("in").
+ send.data("in", "data").
+ send.disconnect("in").
+ discuss("one groups is sent").
+ receive.connect("out").
+ receive.beginGroup("out").
+ receive.data("out", "data").
+ receive.endGroup("out").
+ receive.disconnect("out").
+
+ next().
+ discuss("pass in a grouped connection").
+ send.beginGroup("in", "group").
+ send.data("in", "data").
+ send.endGroup("in").
+ send.disconnect("in").
+ discuss("two groups are sent").
+ receive.connect("out").
+ receive.beginGroup("out", "group").
+ receive.beginGroup("out").
+ receive.data("out", "data").
+ receive.endGroup("out").
+ receive.endGroup("out").
+ receive.disconnect("out").
+
+ next().
+ discuss("pass in a multi grouped connection").
+ send.beginGroup("in", "group1").
+ send.data("in", "data1").
+ send.beginGroup("in", "group2").
+ send.data("in", "data2").
+ send.endGroup("in").
+ send.endGroup("in").
+ send.disconnect("in").
+ discuss("four groups are sent").
+ receive.connect("out").
+ receive.beginGroup("out", "group").
+ receive.beginGroup("out").
+ receive.data("out", "data1").
+ receive.beginGroup("out", "group2").
+ receive.beginGroup("out").
+ receive.data("out", "data2").
+ receive.endGroup("out").
+ receive.endGroup("out").
+ receive.endGroup("out").
+ receive.endGroup("out").
+ receive.disconnect("out").
+
+export module

0 comments on commit d41ffb8

Please sign in to comment.
Something went wrong with that request. Please try again.