erlectricity 0.2.0 → 0.2.1
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.
- data/README.txt +42 -2
- data/Rakefile +4 -1
- data/ext/decoder.c +2 -0
- data/lib/erlectricity.rb +5 -1
- data/lib/erlectricity/decoder.rb +3 -1
- data/lib/erlectricity/version.rb +1 -1
- data/test/decode_spec.rb +7 -1
- data/test/encode_spec.rb +1 -1
- data/test/test_helper.rb +2 -1
- metadata +53 -38
data/README.txt
CHANGED
@@ -1,3 +1,43 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
erlectricity
|
2
|
+
by Scott Fleckenstein
|
3
|
+
Tom Preston-Werner
|
4
|
+
|
5
|
+
http://github.com/mojombo/erlectricity
|
6
|
+
|
7
|
+
== DESCRIPTION:
|
3
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.
|
data/Rakefile
CHANGED
@@ -49,8 +49,11 @@ hoe = Hoe.new(GEM_NAME, VERS) do |p|
|
|
49
49
|
|
50
50
|
# == Optional
|
51
51
|
p.changes = p.paragraphs_of("History.txt", 0..1).join("\n\n")
|
52
|
-
p.extra_deps = [
|
52
|
+
p.extra_deps = [
|
53
|
+
['concurrent', '0.2.2'],
|
54
|
+
] # An array of rubygem dependencies [name, version], e.g. [ ['active_support', '>= 1.3.1'] ]
|
53
55
|
#p.spec_extras = {} # A hash of extra values to set in the gemspec.
|
56
|
+
p.spec_extras = {:extensions => ['ext/extconf.rb']}
|
54
57
|
end
|
55
58
|
|
56
59
|
desc 'Release the website and new gem version'
|
data/ext/decoder.c
CHANGED
data/lib/erlectricity.rb
CHANGED
@@ -1,3 +1,6 @@
|
|
1
|
+
$:.unshift File.join(File.dirname(__FILE__), *%w[.. ext])
|
2
|
+
|
3
|
+
|
1
4
|
require 'erlectricity/constants'
|
2
5
|
|
3
6
|
require 'erlectricity/types/new_reference'
|
@@ -5,12 +8,13 @@ require 'erlectricity/types/pid'
|
|
5
8
|
require 'erlectricity/types/function'
|
6
9
|
require 'erlectricity/types/list'
|
7
10
|
|
11
|
+
|
8
12
|
begin
|
9
13
|
#try to load the decoder C extension
|
10
14
|
require 'decoder'
|
11
15
|
rescue LoadError
|
12
16
|
#load the pure ruby instead
|
13
|
-
require 'erlectricity/decoder'
|
17
|
+
require 'erlectricity/decoder'
|
14
18
|
end
|
15
19
|
|
16
20
|
require 'erlectricity/encoder'
|
data/lib/erlectricity/decoder.rb
CHANGED
@@ -185,7 +185,9 @@ class Decoder
|
|
185
185
|
def read_list
|
186
186
|
fail("Invalid Type, not an erlang list") unless read_1 == LIST
|
187
187
|
length = read_4
|
188
|
-
(0...length).map{|i| read_any_raw}
|
188
|
+
list = (0...length).map{|i| read_any_raw}
|
189
|
+
read_1
|
190
|
+
list
|
189
191
|
end
|
190
192
|
|
191
193
|
def read_bin
|
data/lib/erlectricity/version.rb
CHANGED
data/test/decode_spec.rb
CHANGED
@@ -116,8 +116,14 @@ context "When unpacking from a binary stream" do
|
|
116
116
|
get("<< \"whatup\" >>").should == "whatup"
|
117
117
|
end
|
118
118
|
|
119
|
+
specify "a good thing should be awesome" do
|
120
|
+
get(%Q-[{options,{struct,[{test,<<"I'm chargin' mah lazer">>}]}},{passage,<<"Why doesn't this work?">>}]-).should ==
|
121
|
+
[[:options, [:struct, [[:test, "I'm chargin' mah lazer"]]]], [:passage, "Why doesn't this work?"]]
|
122
|
+
end
|
123
|
+
|
119
124
|
def get(str)
|
120
|
-
|
125
|
+
x = "term_to_binary(#{str.gsub(/"/, '\\\"')})"
|
126
|
+
bin = run_erl(x)
|
121
127
|
Erlectricity::Decoder.read_any_from(bin)
|
122
128
|
end
|
123
129
|
end
|
data/test/encode_spec.rb
CHANGED
data/test/test_helper.rb
CHANGED
@@ -7,7 +7,8 @@ require 'test/spec'
|
|
7
7
|
class Test::Unit::TestCase
|
8
8
|
|
9
9
|
def run_erl(code)
|
10
|
-
|
10
|
+
cmd = %Q{erl -noshell -eval "A = #{code.split.join(' ')}, io:put_chars(A)." -s erlang halt}
|
11
|
+
`#{cmd}`
|
11
12
|
end
|
12
13
|
|
13
14
|
def encode_packet(code)
|
metadata
CHANGED
@@ -1,34 +1,36 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.4
|
3
|
-
specification_version: 1
|
4
2
|
name: erlectricity
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.2.
|
7
|
-
date: 2007-10-29 00:00:00 -07:00
|
8
|
-
summary: A library to interface erlang and ruby through the erlang port system
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
- ext
|
12
|
-
email: nullstyle@gmail.com
|
13
|
-
homepage: http://erlectricity.rubyforge.org
|
14
|
-
rubyforge_project: erlectricity
|
15
|
-
description: A library to interface erlang and ruby through the erlang port system
|
16
|
-
autorequire:
|
17
|
-
default_executable:
|
18
|
-
bindir: bin
|
19
|
-
has_rdoc: true
|
20
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
21
|
-
requirements:
|
22
|
-
- - ">"
|
23
|
-
- !ruby/object:Gem::Version
|
24
|
-
version: 0.0.0
|
25
|
-
version:
|
4
|
+
version: 0.2.1
|
26
5
|
platform: ruby
|
27
|
-
signing_key:
|
28
|
-
cert_chain:
|
29
|
-
post_install_message:
|
30
6
|
authors:
|
31
7
|
- Scott Fleckenstein
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2008-06-04 00:00:00 -07:00
|
13
|
+
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
|
26
|
+
executables: []
|
27
|
+
|
28
|
+
extensions:
|
29
|
+
- ext/extconf.rb
|
30
|
+
extra_rdoc_files:
|
31
|
+
- History.txt
|
32
|
+
- Manifest.txt
|
33
|
+
- README.txt
|
32
34
|
files:
|
33
35
|
- CONTRIBUTORS
|
34
36
|
- History.txt
|
@@ -75,21 +77,34 @@ files:
|
|
75
77
|
- test/spec_suite.rb
|
76
78
|
- test/test_erlectricity.rb
|
77
79
|
- test/test_helper.rb
|
78
|
-
|
79
|
-
|
80
|
-
|
80
|
+
has_rdoc: true
|
81
|
+
homepage: http://erlectricity.rubyforge.org
|
82
|
+
post_install_message:
|
81
83
|
rdoc_options:
|
82
84
|
- --main
|
83
85
|
- README.txt
|
84
|
-
|
85
|
-
-
|
86
|
-
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
- ext
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: "0"
|
94
|
+
version:
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
requirements:
|
97
|
+
- - ">="
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: "0"
|
100
|
+
version:
|
92
101
|
requirements: []
|
93
102
|
|
94
|
-
|
95
|
-
|
103
|
+
rubyforge_project: erlectricity
|
104
|
+
rubygems_version: 1.0.1
|
105
|
+
signing_key:
|
106
|
+
specification_version: 2
|
107
|
+
summary: A library to interface erlang and ruby through the erlang port system
|
108
|
+
test_files:
|
109
|
+
- test/test_erlectricity.rb
|
110
|
+
- test/test_helper.rb
|