mojombo-erlectricity 0.2.1 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (49) hide show
  1. data/History.txt +14 -1
  2. data/LICENSE +20 -0
  3. data/README.md +130 -0
  4. data/Rakefile +63 -60
  5. data/VERSION.yml +4 -0
  6. data/examples/echo/README.md +12 -0
  7. data/examples/echo/echo.erl +13 -0
  8. data/examples/echo/echo.rb +11 -0
  9. data/examples/gruff/gruff.erl +17 -18
  10. data/examples/gruff/gruff_provider.rb +12 -19
  11. data/examples/gruff/{gruff_run.erl → gruff_run.sh} +5 -3
  12. data/examples/gruff/{stat_run.erl → stat_run.sh} +5 -3
  13. data/examples/gruff/stat_writer.erl +6 -6
  14. data/examples/simple/README.md +5 -0
  15. data/examples/simple/rerl.rb +111 -0
  16. data/examples/simple/rerl.sh +37 -0
  17. data/examples/tinderl/README.md +14 -0
  18. data/examples/tinderl/tinderl.erl +19 -21
  19. data/examples/tinderl/tinderl.rb +11 -10
  20. data/ext/decoder.c +67 -60
  21. data/lib/erlectricity/condition.rb +35 -20
  22. data/lib/erlectricity/conditions/boolean.rb +11 -0
  23. data/lib/erlectricity/conditions/hash.rb +9 -10
  24. data/lib/erlectricity/conditions/static.rb +31 -10
  25. data/lib/erlectricity/conditions/type.rb +14 -14
  26. data/lib/erlectricity/constants.rb +3 -4
  27. data/lib/erlectricity/decoder.rb +205 -199
  28. data/lib/erlectricity/encoder.rb +49 -35
  29. data/lib/erlectricity/errors/decode_error.rb +1 -1
  30. data/lib/erlectricity/errors/encode_error.rb +1 -1
  31. data/lib/erlectricity/errors/erlectricity_error.rb +1 -1
  32. data/lib/erlectricity/matcher.rb +15 -32
  33. data/lib/erlectricity/port.rb +11 -11
  34. data/lib/erlectricity/receiver.rb +54 -64
  35. data/lib/erlectricity/types/list.rb +3 -1
  36. data/lib/erlectricity.rb +4 -7
  37. data/test/condition_spec.rb +8 -9
  38. data/test/decode_spec.rb +27 -28
  39. data/test/encode_spec.rb +31 -24
  40. data/test/matcher_spec.rb +24 -12
  41. data/test/port_spec.rb +3 -4
  42. data/test/receiver_spec.rb +18 -20
  43. data/test/test_helper.rb +9 -5
  44. metadata +36 -29
  45. data/CONTRIBUTORS +0 -2
  46. data/Manifest.txt +0 -45
  47. data/README.txt +0 -43
  48. data/setup.rb +0 -1585
  49. data/test/test_erlectricity.rb +0 -2
data/test/matcher_spec.rb CHANGED
@@ -4,23 +4,37 @@ def false_match(matcher, arg)
4
4
  matcher.matches?(arg).should == false
5
5
  end
6
6
 
7
+ context "A matcher whose condition is a String (the class object" do
8
+ setup do
9
+ @matcher = Erlectricity::Matcher.new(nil, Erlectricity::TypeCondition.new(String), nil)
10
+ end
11
+
12
+ specify "should match any string" do
13
+ @matcher.matches?("foo").should == true
14
+ end
15
+
16
+ specify "should not match symbols" do
17
+ @matcher.matches?(:foo).should == false
18
+ end
19
+ end
20
+
7
21
  context "A matcher whose condition is Symbol (the class object)" do
8
22
  setup do
9
23
  @matcher = Erlectricity::Matcher.new(nil, Erlectricity::TypeCondition.new(Symbol), nil)
10
24
  end
11
-
25
+
12
26
  specify "should match any symbol" do
13
27
  @matcher.matches?(:foo).should == true
14
28
  @matcher.matches?(:bar).should == true
15
29
  @matcher.matches?(:baz).should == true
16
30
  end
17
-
31
+
18
32
  specify "should not match strings" do
19
33
  @matcher.matches?("foo").should == false
20
34
  @matcher.matches?("bar").should == false
21
35
  @matcher.matches?("baz").should == false
22
36
  end
23
-
37
+
24
38
  specify "should not match a arrays" do
25
39
  @matcher.matches?([:foo]).should == false
26
40
  @matcher.matches?([:foo, :bar]).should == false
@@ -32,11 +46,11 @@ context "a matcher whose condition is a symbol" do
32
46
  setup do
33
47
  @matcher = Erlectricity::Matcher.new(nil, Erlectricity::StaticCondition.new(:foo), nil)
34
48
  end
35
-
49
+
36
50
  specify "should match that symbol" do
37
51
  @matcher.matches?(:foo).should == true
38
52
  end
39
-
53
+
40
54
  specify "should not match any other symbol" do
41
55
  @matcher.matches?(:bar).should == false
42
56
  @matcher.matches?(:baz).should == false
@@ -44,16 +58,14 @@ context "a matcher whose condition is a symbol" do
44
58
  end
45
59
 
46
60
  context "a matcher whose matcher is an array" do
47
- setup do
48
- end
49
-
61
+
50
62
  specify "should match if all of its children match" do
51
63
  Erlectricity::Matcher.new(nil, [Erlectricity::StaticCondition.new(:speak), Erlectricity::TypeCondition.new(Object)], nil).matches?([:paste, "haha"]).should == false
52
-
64
+
53
65
  matcher = Erlectricity::Matcher.new(nil, [Erlectricity::StaticCondition.new(:foo), Erlectricity::StaticCondition.new(:bar)], nil)
54
66
  matcher.matches?([:foo, :bar]).should == true
55
67
  end
56
-
68
+
57
69
  specify "should not match any of its children dont match" do
58
70
  matcher = Erlectricity::Matcher.new(nil, [Erlectricity::StaticCondition.new(:foo), Erlectricity::StaticCondition.new(:bar)], nil)
59
71
  matcher.matches?([:foo]).should == false
@@ -61,9 +73,9 @@ context "a matcher whose matcher is an array" do
61
73
  matcher.matches?([:fooo, :barr]).should == false
62
74
  matcher.matches?([3, :bar]).should == false
63
75
  end
64
-
76
+
65
77
  specify "should not match if arg isn't an array" do
66
78
  matcher = Erlectricity::Matcher.new(nil, [Erlectricity::StaticCondition.new(:foo), Erlectricity::StaticCondition.new(:bar)], nil)
67
79
  matcher.matches?(:foo).should == false
68
80
  end
69
- end
81
+ end
data/test/port_spec.rb CHANGED
@@ -9,7 +9,7 @@ context "A port" do
9
9
  port.receive.should == :bar
10
10
  port.receive.should == nil
11
11
  end
12
-
12
+
13
13
  specify "should read_from_input if the queue gets empty" do
14
14
  port = FakePort.new(:bar)
15
15
  port.queue.clear
@@ -18,18 +18,17 @@ context "A port" do
18
18
  port.receive.should == :bar
19
19
  port.receive.should == nil
20
20
  end
21
-
21
+
22
22
  specify "should put the terms in skipped at the front of queue when restore_skipped is called" do
23
23
  port = FakePort.new(:baz)
24
24
  port.queue.clear
25
25
  port.queue << :bar
26
26
  port.skipped << :foo
27
27
  port.restore_skipped
28
-
28
+
29
29
  port.receive.should == :foo
30
30
  port.receive.should == :bar
31
31
  port.receive.should == :baz
32
32
  port.receive.should == nil
33
-
34
33
  end
35
34
  end
@@ -13,21 +13,20 @@ def simple_receiver_and_port(*terms, &block)
13
13
  end
14
14
  end
15
15
 
16
-
17
16
  context "When a receiver is passed a message that matches two match blocks it" do
18
17
  setup do
19
18
  @port = FakePort.new([:foo, :foo])
20
19
  @receiver = Erlectricity::Receiver.new(@port) do |f|
21
- f.when(:foo, :foo) do
20
+ f.when([:foo, :foo]) do
22
21
  :first
23
22
  end
24
-
25
- f.when(:foo, Erl.any) do
23
+
24
+ f.when([:foo, Erl.any]) do
26
25
  :second
27
26
  end
28
27
  end
29
28
  end
30
-
29
+
31
30
  specify "should run the first matching receiver's block" do
32
31
  @receiver.run.should == :first
33
32
  end
@@ -39,17 +38,17 @@ context "A receiver" do
39
38
  simple_receiver_and_port(:bar).run.should == :matched
40
39
  simple_receiver_and_port(:bar, :baz).run.should == :matched
41
40
  end
42
-
41
+
43
42
  specify "should process another message if the matched block returns the results of receive_loop" do
44
43
  recv = simple_receiver_and_port(:foo, :bar, :baz) do |f|
45
44
  f.when(:bar) { }
46
45
  f.when(Erl.any) { f.receive_loop }
47
46
  end
48
-
47
+
49
48
  recv.run
50
49
  recv.port.terms.should == [:baz]
51
50
  end
52
-
51
+
53
52
  specify "should properly nest" do
54
53
  @port = FakePort.new(:foo, :bar, :baz)
55
54
  @receiver = Erlectricity::Receiver.new(@port) do |f|
@@ -57,18 +56,18 @@ context "A receiver" do
57
56
  f.receive do |g|
58
57
  g.when(:bar){ :ok }
59
58
  end
60
- f.receive_loop
59
+ f.receive_loop
61
60
  end
62
-
61
+
63
62
  f.when(:baz) do
64
63
  :done
65
64
  end
66
65
  end
67
-
66
+
68
67
  @receiver.run.should == :done
69
68
  @port.terms.should == []
70
69
  end
71
-
70
+
72
71
  specify "should queue up skipped results and restore them when a match happens" do
73
72
  @port = FakePort.new(:foo, :baz, :bar)
74
73
  @receiver = Erlectricity::Receiver.new(@port) do |f|
@@ -76,30 +75,29 @@ context "A receiver" do
76
75
  f.receive do |g|
77
76
  g.when(:bar){ :ok }
78
77
  end
79
- f.receive_loop
78
+ f.receive_loop
80
79
  end
81
-
80
+
82
81
  f.when(:baz) do
83
82
  :done
84
83
  end
85
84
  end
86
-
85
+
87
86
  @receiver.run.should == :done
88
- @port.terms.should == []
87
+ @port.terms.should == []
89
88
  end
90
-
89
+
91
90
  specify "should expose bindings to the matched block" do
92
91
  @port = FakePort.new(:foo, :bar, :baz)
93
92
  results = []
94
93
  @receiver = Erlectricity::Receiver.new(@port) do |f|
95
94
  f.when(Erl.atom) do |bindinated|
96
95
  results << bindinated
97
- f.receive_loop
96
+ f.receive_loop
98
97
  end
99
98
  end
100
-
99
+
101
100
  @receiver.run.should == nil
102
101
  results.should == [:foo, :bar, :baz]
103
102
  end
104
-
105
103
  end
data/test/test_helper.rb CHANGED
@@ -1,21 +1,24 @@
1
1
  $:.unshift(File.dirname(__FILE__) + '/../lib')
2
+
2
3
  require 'erlectricity'
3
4
  require 'rubygems'
4
5
  require 'test/unit'
5
6
  require 'test/spec'
7
+ require 'stringio'
8
+
9
+ $stdout.sync = true
6
10
 
7
11
  class Test::Unit::TestCase
8
-
9
12
  def run_erl(code)
10
13
  cmd = %Q{erl -noshell -eval "A = #{code.split.join(' ')}, io:put_chars(A)." -s erlang halt}
11
14
  `#{cmd}`
12
15
  end
13
-
16
+
14
17
  def encode_packet(code)
15
18
  bin = run_erl("term_to_binary(#{code})")
16
19
  [bin.length, bin].pack("Na#{bin.length}")
17
20
  end
18
-
21
+
19
22
  def word_length
20
23
  (1.size * 8) - 2
21
24
  end
@@ -24,7 +27,7 @@ end
24
27
  class FakePort < Erlectricity::Port
25
28
  attr_reader :sent
26
29
  attr_reader :terms
27
-
30
+
28
31
  def initialize(*terms)
29
32
  @terms = terms
30
33
  @sent = []
@@ -34,8 +37,9 @@ class FakePort < Erlectricity::Port
34
37
  def send(term)
35
38
  sent << term
36
39
  end
37
-
40
+
38
41
  private
42
+
39
43
  def read_from_input
40
44
  @terms.shift
41
45
  end
metadata CHANGED
@@ -1,53 +1,53 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mojombo-erlectricity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Fleckenstein
8
+ - Tom Preston-Werner
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
12
 
12
- date: 2008-06-04 00:00:00 -07:00
13
+ date: 2009-04-29 00:00:00 -07:00
13
14
  default_executable:
14
- dependencies:
15
- - !ruby/object:Gem::Dependency
16
- name: concurrent
17
- version_requirement:
18
- version_requirements: !ruby/object:Gem::Requirement
19
- requirements:
20
- - - "="
21
- - !ruby/object:Gem::Version
22
- version: 0.2.2
23
- version:
24
- description: A library to interface erlang and ruby through the erlang port system
25
- email: nullstyle@gmail.com
15
+ dependencies: []
16
+
17
+ description:
18
+ email: tom@mojombo.com
26
19
  executables: []
27
20
 
28
21
  extensions:
29
22
  - ext/extconf.rb
30
23
  extra_rdoc_files:
31
- - History.txt
32
- - Manifest.txt
33
- - README.txt
24
+ - LICENSE
25
+ - README.md
34
26
  files:
35
- - CONTRIBUTORS
36
27
  - History.txt
37
- - Manifest.txt
38
- - README.txt
28
+ - LICENSE
29
+ - README.md
39
30
  - Rakefile
31
+ - VERSION.yml
32
+ - examples/echo/README.md
33
+ - examples/echo/echo.erl
34
+ - examples/echo/echo.rb
40
35
  - examples/gruff/gruff.erl
41
36
  - examples/gruff/gruff_provider.rb
42
- - examples/gruff/gruff_run.erl
43
- - examples/gruff/stat_run.erl
37
+ - examples/gruff/gruff_run.sh
38
+ - examples/gruff/stat_run.sh
44
39
  - examples/gruff/stat_writer.erl
40
+ - examples/simple/README.md
41
+ - examples/simple/rerl.rb
42
+ - examples/simple/rerl.sh
43
+ - examples/tinderl/README.md
45
44
  - examples/tinderl/tinderl.erl
46
45
  - examples/tinderl/tinderl.rb
47
46
  - ext/decoder.c
48
47
  - ext/extconf.rb
49
48
  - lib/erlectricity.rb
50
49
  - lib/erlectricity/condition.rb
50
+ - lib/erlectricity/conditions/boolean.rb
51
51
  - lib/erlectricity/conditions/hash.rb
52
52
  - lib/erlectricity/conditions/static.rb
53
53
  - lib/erlectricity/conditions/type.rb
@@ -67,7 +67,6 @@ files:
67
67
  - lib/erlectricity/types/pid.rb
68
68
  - lib/erlectricity/types/reference.rb
69
69
  - lib/erlectricity/version.rb
70
- - setup.rb
71
70
  - test/condition_spec.rb
72
71
  - test/decode_spec.rb
73
72
  - test/encode_spec.rb
@@ -75,14 +74,12 @@ files:
75
74
  - test/port_spec.rb
76
75
  - test/receiver_spec.rb
77
76
  - test/spec_suite.rb
78
- - test/test_erlectricity.rb
79
77
  - test/test_helper.rb
80
78
  has_rdoc: true
81
- homepage: http://erlectricity.rubyforge.org
79
+ homepage: http://github.com/mojombo/erlectricity
82
80
  post_install_message:
83
81
  rdoc_options:
84
- - --main
85
- - README.txt
82
+ - --charset=UTF-8
86
83
  require_paths:
87
84
  - lib
88
85
  - ext
@@ -101,10 +98,20 @@ required_rubygems_version: !ruby/object:Gem::Requirement
101
98
  requirements: []
102
99
 
103
100
  rubyforge_project: erlectricity
104
- rubygems_version: 1.0.1
101
+ rubygems_version: 1.2.0
105
102
  signing_key:
106
103
  specification_version: 2
107
104
  summary: A library to interface erlang and ruby through the erlang port system
108
105
  test_files:
109
- - test/test_erlectricity.rb
106
+ - test/condition_spec.rb
107
+ - test/decode_spec.rb
108
+ - test/encode_spec.rb
109
+ - test/matcher_spec.rb
110
+ - test/port_spec.rb
111
+ - test/receiver_spec.rb
112
+ - test/spec_suite.rb
110
113
  - test/test_helper.rb
114
+ - examples/echo/echo.rb
115
+ - examples/gruff/gruff_provider.rb
116
+ - examples/simple/rerl.rb
117
+ - examples/tinderl/tinderl.rb
data/CONTRIBUTORS DELETED
@@ -1,2 +0,0 @@
1
- Tom Preston-Werner
2
- - provided the C extension that replaces the ruby decoder
data/Manifest.txt DELETED
@@ -1,45 +0,0 @@
1
- CONTRIBUTORS
2
- History.txt
3
- Manifest.txt
4
- README.txt
5
- Rakefile
6
- examples/gruff/gruff.erl
7
- examples/gruff/gruff_provider.rb
8
- examples/gruff/gruff_run.erl
9
- examples/gruff/stat_run.erl
10
- examples/gruff/stat_writer.erl
11
- examples/tinderl/tinderl.erl
12
- examples/tinderl/tinderl.rb
13
- ext/decoder.c
14
- ext/extconf.rb
15
- lib/erlectricity.rb
16
- lib/erlectricity/condition.rb
17
- lib/erlectricity/conditions/hash.rb
18
- lib/erlectricity/conditions/static.rb
19
- lib/erlectricity/conditions/type.rb
20
- lib/erlectricity/constants.rb
21
- lib/erlectricity/decoder.rb
22
- lib/erlectricity/encoder.rb
23
- lib/erlectricity/errors/decode_error.rb
24
- lib/erlectricity/errors/encode_error.rb
25
- lib/erlectricity/errors/erlectricity_error.rb
26
- lib/erlectricity/matcher.rb
27
- lib/erlectricity/port.rb
28
- lib/erlectricity/receiver.rb
29
- lib/erlectricity/types/function.rb
30
- lib/erlectricity/types/list.rb
31
- lib/erlectricity/types/new_function.rb
32
- lib/erlectricity/types/new_reference.rb
33
- lib/erlectricity/types/pid.rb
34
- lib/erlectricity/types/reference.rb
35
- lib/erlectricity/version.rb
36
- setup.rb
37
- test/condition_spec.rb
38
- test/decode_spec.rb
39
- test/encode_spec.rb
40
- test/matcher_spec.rb
41
- test/port_spec.rb
42
- test/receiver_spec.rb
43
- test/spec_suite.rb
44
- test/test_erlectricity.rb
45
- test/test_helper.rb
data/README.txt DELETED
@@ -1,43 +0,0 @@
1
- erlectricity
2
- by Scott Fleckenstein
3
- Tom Preston-Werner
4
-
5
- http://github.com/mojombo/erlectricity
6
-
7
- == DESCRIPTION:
8
-
9
- Erlectricity allows a Ruby program to receive and respond to Erlang messages
10
- sent over the Erlang binary protocol.
11
-
12
- == INSTALL:
13
-
14
- $ gem install erlectricity
15
-
16
- == USAGE (Ruby side):
17
-
18
- require 'rubygems'
19
- require 'erlectricity'
20
- require 'stringio'
21
-
22
- receive do |f|
23
- f.when(:echo, String) do |text|
24
- f.send!(:result, "You said: #{text}")
25
- f.receive_loop
26
- end
27
- end
28
-
29
- == USAGE (Erlang side):
30
-
31
- -module(echo).
32
- -export([test/0]).
33
-
34
- test() ->
35
- Cmd = "ruby echo.rb",
36
- Port = open_port({spawn, Cmd}, [{packet, 4}, use_stdio, exit_status, binary]),
37
- Payload = term_to_binary({echo, <<"hello world!">>}),
38
- port_command(Port, Payload),
39
- receive
40
- {Port, {data, Data}} ->
41
- {result, Text} = binary_to_term(Data),
42
- io:format("~p~n", [Text])
43
- end.