erlang-etf 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0df02c49c6d963c92a155665d854c29c64d4d506
4
- data.tar.gz: 1f4365a62a0b2ee16b87fa688cba57ee0b4a89f9
3
+ metadata.gz: c065a1c33b75cf6235b7911022718a22fa44204c
4
+ data.tar.gz: 57fb1fc1ce89f1826ac5bcef122f1eb085430baa
5
5
  SHA512:
6
- metadata.gz: 40c84fcbf9312de7a5d9e0e057651743764fe6172e72c8c7e66a80fd4fd693b826235b83f010410f0ff086295f81186f3f4b9630b23276a432b6ad0a26af018b
7
- data.tar.gz: f167a812a0f03ab72ea546cf3cf47947a9192e921de500439130932c11a33283fdad27f3a3d3b9e195c5b4b560d9a3b4f773d4b523598e421259d9ffdfba1b0a
6
+ metadata.gz: 3979a241f92a3f08a19e81042c266381fc8e17837e08f7f7dd7be0d34d637bacc051d0fff6a808237c57386b23fed4cc13970247efb70054c7f3ba0355668f79
7
+ data.tar.gz: 8947fad90e772020fff53c997d7c5240b73cb9cd298e4ab0f3f951d76aefc90ab193225a4241b4636f022c2031fecdb4d29f12bab2fdeb02e4003fc7795e6189
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_dependency "binary-protocol"
22
- spec.add_dependency "erlang-terms"
22
+ spec.add_dependency "erlang-terms", ">= 1.1.0"
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1.3"
25
25
  spec.add_development_dependency "rake"
@@ -14,6 +14,7 @@ end
14
14
 
15
15
  require "erlang/etf/extensions/erlang-export"
16
16
  require "erlang/etf/extensions/erlang-list"
17
+ require "erlang/etf/extensions/erlang-map"
17
18
  require "erlang/etf/extensions/erlang-nil"
18
19
  require "erlang/etf/extensions/erlang-pid"
19
20
  require "erlang/etf/extensions/erlang-string"
@@ -33,6 +34,11 @@ module Erlang
33
34
  include Erlang::ETF::Extensions::ErlangList
34
35
  end
35
36
 
37
+ # @private
38
+ class ::Erlang::Map
39
+ include Erlang::ETF::Extensions::ErlangMap
40
+ end
41
+
36
42
  # @private
37
43
  class ::Erlang::Nil
38
44
  include Erlang::ETF::Extensions::ErlangNil
@@ -0,0 +1,26 @@
1
+ require 'erlang/map'
2
+
3
+ module Erlang
4
+ module ETF
5
+ module Extensions
6
+
7
+ module ErlangMap
8
+
9
+ def __erlang_type__
10
+ :map
11
+ end
12
+
13
+ def __erlang_evolve__
14
+ if size == 0
15
+ ETF::Map.new([], [])
16
+ else
17
+ ETF::Map.new(*map do |(key, value)|
18
+ [key.__erlang_evolve__, value.__erlang_evolve__]
19
+ end.transpose)
20
+ end
21
+ end
22
+
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,51 @@
1
+ module Erlang
2
+ module ETF
3
+
4
+ #
5
+ # 1 | 4 | N | N
6
+ # --- | ---- | ---- | ------
7
+ # 116 | Size | Keys | Values
8
+ #
9
+ # The Size specifies the number of keys and values that
10
+ # follows the size descriptor.
11
+ #
12
+ # (see [`MAP_EXT`])
13
+ #
14
+ # [`MAP_EXT`]: http://erlang.org/doc/apps/erts/erl_ext_dist.html#MAP_EXT
15
+ #
16
+ class Map
17
+ include Term
18
+
19
+ uint8 :tag, always: Terms::MAP_EXT
20
+
21
+ uint32be :size, always: -> { keys.size }
22
+
23
+ term :keys, type: :array
24
+ term :values, type: :array
25
+
26
+ deserialize do |buffer|
27
+ size, = buffer.read(BYTES_32).unpack(UINT32BE_PACK)
28
+ self.keys = []
29
+ size.times do
30
+ self.keys << Terms.deserialize(buffer)
31
+ end
32
+ self.values = []
33
+ size.times do
34
+ self.values << Terms.deserialize(buffer)
35
+ end
36
+ self
37
+ end
38
+
39
+ finalize
40
+
41
+ def initialize(keys, values)
42
+ @keys = keys
43
+ @values = values
44
+ end
45
+
46
+ def __ruby_evolve__
47
+ ::Erlang::Map[keys.map(&:__ruby_evolve__).zip(values.map(&:__ruby_evolve__))]
48
+ end
49
+ end
50
+ end
51
+ end
@@ -26,6 +26,7 @@ module Erlang
26
26
  NEW_FLOAT_EXT = 70.freeze
27
27
  ATOM_UTF8_EXT = 118.freeze
28
28
  SMALL_ATOM_UTF8_EXT = 119.freeze
29
+ MAP_EXT = 116.freeze
29
30
  end
30
31
  end
31
32
  end
@@ -44,6 +45,7 @@ require "erlang/etf/integer"
44
45
  require "erlang/etf/large_big"
45
46
  require "erlang/etf/large_tuple"
46
47
  require "erlang/etf/list"
48
+ require "erlang/etf/map"
47
49
  require "erlang/etf/new_float"
48
50
  require "erlang/etf/new_fun"
49
51
  require "erlang/etf/new_reference"
@@ -87,6 +89,7 @@ module Erlang
87
89
  MAP[NEW_FLOAT_EXT] = ETF::NewFloat
88
90
  MAP[ATOM_UTF8_EXT] = ETF::AtomUTF8
89
91
  MAP[SMALL_ATOM_UTF8_EXT] = ETF::SmallAtomUTF8
92
+ MAP[MAP_EXT] = ETF::Map
90
93
 
91
94
  def self.deserialize(buffer)
92
95
  key, = buffer.read(1).unpack(::Binary::Protocol::UINT8_PACK)
@@ -1,5 +1,5 @@
1
1
  module Erlang
2
2
  module ETF
3
- VERSION = "1.0.1"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
@@ -0,0 +1,48 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Erlang::ETF::Extensions::ErlangMap do
6
+ let(:klass) { ::Erlang::Map }
7
+
8
+ describe '[instance]' do
9
+ let(:instance) { klass[keys.zip(values)] }
10
+
11
+ describe '__erlang_type__' do
12
+ subject { instance.__erlang_type__ }
13
+
14
+ context 'when empty' do
15
+ let(:keys) { [] }
16
+ let(:values) { [] }
17
+
18
+ it { should eq(:map) }
19
+ end
20
+
21
+ context 'when not empty' do
22
+ let(:keys) { [:a] }
23
+ let(:values) { [1] }
24
+
25
+ it { should eq(:map) }
26
+ end
27
+ end
28
+
29
+ describe '__erlang_evolve__' do
30
+ subject { instance.__erlang_evolve__ }
31
+
32
+ context 'when empty' do
33
+ let(:keys) { [] }
34
+ let(:values) { [] }
35
+
36
+ it { should eq(Erlang::ETF::Map.new([], [])) }
37
+ end
38
+
39
+ context 'when not empty' do
40
+ let(:keys) { [:a] }
41
+ let(:values) { [1] }
42
+
43
+ it { should eq(Erlang::ETF::Map.new([Erlang::ETF::SmallAtom.new("a")], [Erlang::ETF::SmallInteger.new(1)])) }
44
+ end
45
+ end
46
+ end
47
+
48
+ end
@@ -0,0 +1,100 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+ require 'pry'
5
+
6
+ describe Erlang::ETF::Map do
7
+ let(:term_class) { Erlang::ETF::Map }
8
+
9
+ let(:atom) { Erlang::ETF::SmallAtom.new("test").tap(&:serialize) }
10
+ let(:binary) { Erlang::ETF::Binary.new("test").tap(&:serialize) }
11
+ let(:new_float) { Erlang::ETF::NewFloat.new(1.1) }
12
+ let(:small_integer) { Erlang::ETF::SmallInteger.new(13) }
13
+ let(:small_list) { Erlang::ETF::List.new([atom, binary, new_float, small_integer]) }
14
+ let(:erlang_nil) { Erlang::ETF::Nil.new }
15
+ let(:small_tuple) { Erlang::ETF::SmallTuple.new([atom, binary, new_float, small_integer, small_list]) }
16
+ let(:small_map) { Erlang::ETF::Map.new([atom, binary, new_float], [small_integer, erlang_nil, small_list]) }
17
+
18
+ describe '[class]' do
19
+ describe 'deserialize' do
20
+ let(:buffer) { StringIO.new(bytes.pack('C*')) }
21
+ subject { term_class.deserialize(buffer) }
22
+
23
+ context 'single item map' do
24
+ let(:bytes) { [0, 0, 0, 1, 100, 0, 1, 97, 106] }
25
+ let(:atom_a) { Erlang::ETF::Atom.new("a").tap(&:serialize) }
26
+
27
+ its(:size) { should eq(1) }
28
+ its(:keys) { should eq([atom_a]) }
29
+ its(:values) { should eq([erlang_nil]) }
30
+ end
31
+
32
+ context 'multiple item map' do
33
+ let(:bytes) { [0, 0, 0, 3, 115, 4, 116, 101, 115, 116, 109, 0, 0, 0, 4, 116, 101, 115, 116, 70, 63, 241, 153, 153, 153, 153, 153, 154, 97, 13, 106, 108, 0, 0, 0, 4, 115, 4, 116, 101, 115, 116, 109, 0, 0, 0, 4, 116, 101, 115, 116, 70, 63, 241, 153, 153, 153, 153, 153, 154, 97, 13, 106] }
34
+
35
+ its(:size) { should eq(3) }
36
+ its(:keys) { should eq([atom, binary, new_float]) }
37
+ its(:values) { should eq([small_integer, erlang_nil, small_list]) }
38
+ end
39
+ end
40
+ end
41
+
42
+ describe '[instance]' do
43
+ let(:term) { term_class.new(keys, values) }
44
+
45
+ let(:atom_a) { Erlang::ETF::Atom.new("a").tap(&:serialize) }
46
+
47
+ describe 'serialize' do
48
+ subject { term.serialize }
49
+
50
+ context 'single item map' do
51
+ let(:bytes) { [116, 0, 0, 0, 1, 100, 0, 1, 97, 106].pack('C*') }
52
+
53
+ let(:keys) { [atom_a] }
54
+ let(:values) { [erlang_nil] }
55
+
56
+ it { should eq(bytes) }
57
+ end
58
+
59
+ context 'multiple item map' do
60
+ let(:bytes) { [116, 0, 0, 0, 3, 115, 4, 116, 101, 115, 116, 109, 0, 0, 0, 4, 116, 101, 115, 116, 70, 63, 241, 153, 153, 153, 153, 153, 154, 97, 13, 116, 0, 0, 0, 3, 115, 4, 116, 101, 115, 116, 109, 0, 0, 0, 4, 116, 101, 115, 116, 70, 63, 241, 153, 153, 153, 153, 153, 154, 97, 13, 106, 108, 0, 0, 0, 4, 115, 4, 116, 101, 115, 116, 109, 0, 0, 0, 4, 116, 101, 115, 116, 70, 63, 241, 153, 153, 153, 153, 153, 154, 97, 13, 106, 108, 0, 0, 0, 4, 115, 4, 116, 101, 115, 116, 109, 0, 0, 0, 4, 116, 101, 115, 116, 70, 63, 241, 153, 153, 153, 153, 153, 154, 97, 13, 106].pack('C*') }
61
+
62
+ let(:keys) { [atom, binary, new_float] }
63
+ let(:values) { [small_integer, small_map, small_list] }
64
+
65
+ it { should eq(bytes) }
66
+ end
67
+ end
68
+
69
+ describe '__erlang_type__' do
70
+ subject { term.__erlang_type__ }
71
+
72
+ let(:keys) { [atom_a] }
73
+ let(:values) { [erlang_nil] }
74
+ it { should eq(:map) }
75
+ end
76
+
77
+ describe '__ruby_evolve__' do
78
+ context 'single item map' do
79
+ let(:ruby_obj) { ::Erlang::Map[:a, :a] }
80
+ subject { term.__ruby_evolve__ }
81
+
82
+ let(:keys) { [atom_a] }
83
+ let(:values) { [atom_a] }
84
+
85
+ it { should eq(ruby_obj) }
86
+ end
87
+
88
+ context 'multiple item map' do
89
+ let(:ruby_obj) { ::Erlang::Map[:test, "test", 1.1, 13, ::Erlang::Tuple[:test, "test", 1.1, 13, ::Erlang::List[:test, "test", 1.1, 13]], ::Erlang::List[:test, "test", 1.1, 13]] }
90
+ subject { term.__ruby_evolve__ }
91
+
92
+ let(:keys) { [atom, new_float, small_tuple] }
93
+ let(:values) { [binary, small_integer, small_list] }
94
+
95
+ it { should eq(ruby_obj) }
96
+ end
97
+ end
98
+ end
99
+
100
+ end
@@ -67,7 +67,10 @@ describe Erlang do
67
67
 
68
68
  Erlang::Export.new(:erlang, :now, 0),
69
69
  Erlang::Pid.new(:'node@host', 100, 10, 1),
70
- Erlang::String.new("test")
70
+ Erlang::String.new("test"),
71
+ Erlang::Map[],
72
+ Erlang::Map[:atom, 1],
73
+ Erlang::Map[Erlang::Map[:atom, 1], 2]
71
74
  ]
72
75
 
73
76
  roundtrip_variables.each do |roundtrip_variable|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: erlang-etf
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Bennett
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-20 00:00:00.000000000 Z
11
+ date: 2014-03-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: binary-protocol
@@ -30,14 +30,14 @@ dependencies:
30
30
  requirements:
31
31
  - - '>='
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 1.1.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '>='
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 1.1.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +108,7 @@ files:
108
108
  - lib/erlang/etf/extensions/big_decimal.rb
109
109
  - lib/erlang/etf/extensions/erlang-export.rb
110
110
  - lib/erlang/etf/extensions/erlang-list.rb
111
+ - lib/erlang/etf/extensions/erlang-map.rb
111
112
  - lib/erlang/etf/extensions/erlang-nil.rb
112
113
  - lib/erlang/etf/extensions/erlang-pid.rb
113
114
  - lib/erlang/etf/extensions/erlang-string.rb
@@ -129,6 +130,7 @@ files:
129
130
  - lib/erlang/etf/large_big.rb
130
131
  - lib/erlang/etf/large_tuple.rb
131
132
  - lib/erlang/etf/list.rb
133
+ - lib/erlang/etf/map.rb
132
134
  - lib/erlang/etf/new_float.rb
133
135
  - lib/erlang/etf/new_fun.rb
134
136
  - lib/erlang/etf/new_reference.rb
@@ -154,6 +156,7 @@ files:
154
156
  - spec/erlang/etf/extensions/big_decimal_spec.rb
155
157
  - spec/erlang/etf/extensions/erlang-export_spec.rb
156
158
  - spec/erlang/etf/extensions/erlang-list_spec.rb
159
+ - spec/erlang/etf/extensions/erlang-map_spec.rb
157
160
  - spec/erlang/etf/extensions/erlang-nil_spec.rb
158
161
  - spec/erlang/etf/extensions/erlang-pid_spec.rb
159
162
  - spec/erlang/etf/extensions/erlang-string_spec.rb
@@ -175,6 +178,7 @@ files:
175
178
  - spec/erlang/etf/large_big_spec.rb
176
179
  - spec/erlang/etf/large_tuple_spec.rb
177
180
  - spec/erlang/etf/list_spec.rb
181
+ - spec/erlang/etf/map_spec.rb
178
182
  - spec/erlang/etf/new_float_spec.rb
179
183
  - spec/erlang/etf/new_fun_spec.rb
180
184
  - spec/erlang/etf/new_reference_spec.rb
@@ -213,7 +217,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
213
217
  version: '0'
214
218
  requirements: []
215
219
  rubyforge_project:
216
- rubygems_version: 2.0.2
220
+ rubygems_version: 2.2.1
217
221
  signing_key:
218
222
  specification_version: 4
219
223
  summary: Erlang External Term Format (ETF) for Ruby
@@ -227,6 +231,7 @@ test_files:
227
231
  - spec/erlang/etf/extensions/big_decimal_spec.rb
228
232
  - spec/erlang/etf/extensions/erlang-export_spec.rb
229
233
  - spec/erlang/etf/extensions/erlang-list_spec.rb
234
+ - spec/erlang/etf/extensions/erlang-map_spec.rb
230
235
  - spec/erlang/etf/extensions/erlang-nil_spec.rb
231
236
  - spec/erlang/etf/extensions/erlang-pid_spec.rb
232
237
  - spec/erlang/etf/extensions/erlang-string_spec.rb
@@ -248,6 +253,7 @@ test_files:
248
253
  - spec/erlang/etf/large_big_spec.rb
249
254
  - spec/erlang/etf/large_tuple_spec.rb
250
255
  - spec/erlang/etf/list_spec.rb
256
+ - spec/erlang/etf/map_spec.rb
251
257
  - spec/erlang/etf/new_float_spec.rb
252
258
  - spec/erlang/etf/new_fun_spec.rb
253
259
  - spec/erlang/etf/new_reference_spec.rb