funl 0.7 → 0.8

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: f7052cdcfcfbc11611386090111ff18932e150dc
4
- data.tar.gz: 8d406bc8f898c87a82240a689fec27dc2fe6bf3d
3
+ metadata.gz: 2b9cbf42dd9f7a6813d6a0fcd2882d677c1d72fa
4
+ data.tar.gz: 1ad336d8811f9effcb413610177a374383431164
5
5
  SHA512:
6
- metadata.gz: a69cb87e3c8960f9c354d3ab5bfbe561d54e07088bbcf3f22e479789e17a8bca00b29fde36ecc9a8872a6dec8e9c65bac1bc6b13c8c3a3f115cc96e4c188d4a6
7
- data.tar.gz: 2b1fd03f61eb10df1f4f0b71e72991b7b75469f286c08991605a8c7aaccb962ef4045c7b5869f2e667be768ebb445eca6ad3fe0164b8c26f25fe04bb4c58119c
6
+ metadata.gz: e037b7343642c8d08fc0d45c10c06e032ddd7054ba47fc06d60fecf107ee7aac3c74d641063875c522b4fa7de98ebcd1ab71a5a5b9508781cab678a219f97b5a
7
+ data.tar.gz: 23fdd84f5d8146083979031de31d6a4a309b17a30c573afc07787df98d46c15d386ad43e18f94b6203d8d6687469fd4f92c55bbcccaaeeedb65b8d3edd88c42c
@@ -6,23 +6,55 @@ module Funl
6
6
  YAML_TYPE = ObjectStream::YAML_TYPE
7
7
  JSON_TYPE = ObjectStream::JSON_TYPE
8
8
  MSGPACK_TYPE = ObjectStream::MSGPACK_TYPE
9
+
10
+ module JSON_SYM
11
+ def self.load arg
12
+ JSON.parse arg, symbolize_keys: true
13
+ end
14
+
15
+ def self.dump arg
16
+ JSON.dump arg
17
+ end
18
+ end
19
+
20
+ module MessagePack_SYM
21
+ def self.load arg
22
+ MessagePack.load arg, symbolize_keys: true
23
+ end
24
+
25
+ def self.dump arg
26
+ MessagePack.dump arg
27
+ end
28
+ end
9
29
 
10
30
  # Returns something which responds to #dump(obj) and #load(str).
11
- def self.for type
31
+ def self.for type, symbolize_keys: false
12
32
  case type
13
33
  when MARSHAL_TYPE
14
34
  Marshal
35
+
15
36
  when YAML_TYPE
16
37
  require 'yaml'
17
38
  YAML
39
+
18
40
  when JSON_TYPE
19
41
  require 'yajl'
20
42
  require 'yajl/json_gem'
21
43
  ## would 'json' conflict with yajl required from other libs?
22
- JSON
44
+ if symbolize_keys
45
+ JSON_SYM
46
+ else
47
+ JSON
48
+ end
49
+
23
50
  when MSGPACK_TYPE
24
51
  require 'msgpack'
25
- MessagePack
52
+ if symbolize_keys
53
+ MessagePack_SYM
54
+ else
55
+ MessagePack
56
+ end
57
+
26
58
  else
27
59
  raise ArgumentError, "unknown type: #{type.inspect}"
28
60
  end
@@ -21,15 +21,18 @@ module Funl
21
21
  attr_reader :start_tick
22
22
  attr_reader :blob_type
23
23
  attr_reader :blobber
24
+ attr_reader :symbolize_keys
24
25
 
25
26
  def initialize(seq: seq!, cseq: cseq!, arc: nil,
26
27
  log: Logger.new($stderr),
27
28
  stream_type: ObjectStream::MSGPACK_TYPE,
28
- message_class: Message)
29
+ message_class: Message,
30
+ symbolize_keys: false)
29
31
 
30
32
  @log = log
31
33
  @stream_type = stream_type ## discover this thru connections
32
34
  @message_class = message_class
35
+ @symbolize_keys = symbolize_keys
33
36
 
34
37
  @seq = client_stream_for(seq)
35
38
  @cseq = client_stream_for(cseq)
@@ -109,7 +112,7 @@ module Funl
109
112
  log.info "start_tick = #{start_tick}"
110
113
  @blob_type = greeting["blob"]
111
114
  log.info "blob_type = #{blob_type}"
112
- @blobber = Blobber.for(blob_type)
115
+ @blobber = Blobber.for(blob_type, symbolize_keys: symbolize_keys)
113
116
  seq.expect message_class
114
117
 
115
118
  @arc = @arcio && client_stream_for(@arcio, type: blob_type)
@@ -8,15 +8,15 @@ module Funl
8
8
 
9
9
  # Mixin depends on stream_type, log, client_id, message_class.
10
10
  module Stream
11
- def client_stream_for io, type: stream_type
12
- ObjectStreamWrapper.new(io, type: type).tap do |stream|
11
+ def client_stream_for io, type: stream_type, **opts
12
+ ObjectStreamWrapper.new(io, type: type, **opts).tap do |stream|
13
13
  stream.write_to_outbox {{"client_id" => client_id}}
14
14
  # client_id will be nil in the case of cseq, but that's ok.
15
15
  end
16
16
  end
17
17
 
18
- def server_stream_for io, type: stream_type
19
- ObjectStreamWrapper.new(io, type: type).tap do |stream|
18
+ def server_stream_for io, type: stream_type, **opts
19
+ ObjectStreamWrapper.new(io, type: type, **opts).tap do |stream|
20
20
  stream.consume do |h|
21
21
  raise StreamError, "bad handshake: #{h.class}" unless h.kind_of? Hash
22
22
  client_id = h["client_id"]
@@ -26,8 +26,8 @@ module Funl
26
26
  end
27
27
  end
28
28
 
29
- def message_server_stream_for io, type: stream_type
30
- ObjectStreamWrapper.new(io, type: type).tap do |stream|
29
+ def message_server_stream_for io, type: stream_type, **opts
30
+ ObjectStreamWrapper.new(io, type: type, **opts).tap do |stream|
31
31
  stream.consume do |h|
32
32
  raise StreamError, "bad handshake: #{h.class}" unless h.kind_of? Hash
33
33
  client_id = h["client_id"]
@@ -1,3 +1,3 @@
1
1
  module Funl
2
- VERSION = "0.7"
2
+ VERSION = "0.8"
3
3
  end
@@ -0,0 +1,58 @@
1
+ require 'funl/blobber'
2
+
3
+ require 'minitest/autorun'
4
+
5
+ class TestBlobber < Minitest::Test
6
+ OBJECTS = [
7
+ [ {a: 1, b: 2}, {"a" => 1, "b" => 2} ]
8
+ ]
9
+
10
+ def test_marshal
11
+ blobber = Funl::Blobber.for ObjectStream::MARSHAL_TYPE
12
+ OBJECTS.each do |sym_obj, str_obj|
13
+ assert_equal sym_obj, blobber.load(blobber.dump(sym_obj))
14
+ assert_equal str_obj, blobber.load(blobber.dump(str_obj))
15
+ end
16
+ end
17
+
18
+ def test_yaml
19
+ blobber = Funl::Blobber.for ObjectStream::YAML_TYPE
20
+ OBJECTS.each do |sym_obj, str_obj|
21
+ assert_equal sym_obj, blobber.load(blobber.dump(sym_obj))
22
+ assert_equal str_obj, blobber.load(blobber.dump(str_obj))
23
+ end
24
+ end
25
+
26
+ def test_json_string_keys
27
+ blobber = Funl::Blobber.for ObjectStream::JSON_TYPE
28
+ OBJECTS.each do |sym_obj, str_obj|
29
+ assert_equal str_obj, blobber.load(blobber.dump(sym_obj))
30
+ assert_equal str_obj, blobber.load(blobber.dump(str_obj))
31
+ end
32
+ end
33
+
34
+ def test_json_symbol_keys
35
+ blobber = Funl::Blobber.for ObjectStream::JSON_TYPE, symbolize_keys: true
36
+ OBJECTS.each do |sym_obj, str_obj|
37
+ assert_equal sym_obj, blobber.load(blobber.dump(sym_obj))
38
+ assert_equal sym_obj, blobber.load(blobber.dump(str_obj))
39
+ end
40
+ end
41
+
42
+ def test_msgpack_string_keys
43
+ blobber = Funl::Blobber.for ObjectStream::MSGPACK_TYPE
44
+ OBJECTS.each do |sym_obj, str_obj|
45
+ assert_equal str_obj, blobber.load(blobber.dump(sym_obj))
46
+ assert_equal str_obj, blobber.load(blobber.dump(str_obj))
47
+ end
48
+ end
49
+
50
+ def test_msgpack_symbol_keys
51
+ blobber = Funl::Blobber.for ObjectStream::MSGPACK_TYPE, symbolize_keys: true
52
+ OBJECTS.each do |sym_obj, str_obj|
53
+ assert_equal sym_obj, blobber.load(blobber.dump(sym_obj))
54
+ assert_equal sym_obj, blobber.load(blobber.dump(str_obj))
55
+ end
56
+ end
57
+ end
58
+
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: funl
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.7'
4
+ version: '0.8'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joel VanderWerf
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-01-30 00:00:00.000000000 Z
11
+ date: 2014-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: object-stream
@@ -63,6 +63,7 @@ files:
63
63
  - lib/funl/stream.rb
64
64
  - lib/funl/subscription-tracker.rb
65
65
  - lib/funl/version.rb
66
+ - test/test-blobber.rb
66
67
  - test/test-client-sequencer.rb
67
68
  - test/test-client.rb
68
69
  - test/test-message-sequencer.rb
@@ -97,16 +98,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
97
98
  version: '0'
98
99
  requirements: []
99
100
  rubyforge_project:
100
- rubygems_version: 2.2.1
101
+ rubygems_version: 2.2.2
101
102
  signing_key:
102
103
  specification_version: 4
103
104
  summary: Sequences messages
104
105
  test_files:
105
- - test/test-stream.rb
106
- - test/test-message.rb
107
- - test/test-client.rb
106
+ - test/test-message-sequencer.rb
108
107
  - test/test-client-sequencer.rb
109
- - test/test-subscribe.rb
110
108
  - test/test-reflect.rb
111
- - test/test-message-sequencer.rb
109
+ - test/test-message.rb
110
+ - test/test-stream.rb
111
+ - test/test-subscribe.rb
112
+ - test/test-client.rb
113
+ - test/test-blobber.rb
112
114
  has_rdoc: