beambridge 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/.gitignore +23 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/History.txt +35 -0
- data/LICENSE +20 -0
- data/README.md +130 -0
- data/Rakefile +44 -0
- data/VERSION.yml +4 -0
- data/beambridge.gemspec +29 -0
- data/benchmarks/bench.rb +21 -0
- data/examples/echo/README.md +12 -0
- data/examples/echo/echo.erl +13 -0
- data/examples/echo/echo.rb +10 -0
- data/examples/gruff/gruff.erl +61 -0
- data/examples/gruff/gruff_provider.rb +30 -0
- data/examples/gruff/gruff_run.sh +19 -0
- data/examples/gruff/stat_run.sh +20 -0
- data/examples/gruff/stat_writer.erl +40 -0
- data/examples/simple/README.md +5 -0
- data/examples/simple/rerl.rb +110 -0
- data/examples/simple/rerl.sh +37 -0
- data/examples/tinderl/README.md +14 -0
- data/examples/tinderl/tinderl.erl +43 -0
- data/examples/tinderl/tinderl.rb +27 -0
- data/ext/decoder.c +398 -0
- data/ext/extconf.rb +11 -0
- data/lib/beambridge.rb +34 -0
- data/lib/beambridge/condition.rb +66 -0
- data/lib/beambridge/conditions/boolean.rb +11 -0
- data/lib/beambridge/conditions/hash.rb +13 -0
- data/lib/beambridge/conditions/static.rb +34 -0
- data/lib/beambridge/conditions/type.rb +17 -0
- data/lib/beambridge/constants.rb +36 -0
- data/lib/beambridge/decoder.rb +212 -0
- data/lib/beambridge/encoder.rb +164 -0
- data/lib/beambridge/errors/beambridge_error.rb +3 -0
- data/lib/beambridge/errors/decode_error.rb +3 -0
- data/lib/beambridge/errors/encode_error.rb +3 -0
- data/lib/beambridge/matcher.rb +21 -0
- data/lib/beambridge/port.rb +48 -0
- data/lib/beambridge/receiver.rb +69 -0
- data/lib/beambridge/types/function.rb +3 -0
- data/lib/beambridge/types/list.rb +3 -0
- data/lib/beambridge/types/new_function.rb +3 -0
- data/lib/beambridge/types/new_reference.rb +3 -0
- data/lib/beambridge/types/pid.rb +3 -0
- data/lib/beambridge/types/reference.rb +3 -0
- data/lib/beambridge/version.rb +3 -0
- data/spec/condition_spec.rb +72 -0
- data/spec/decode_spec.rb +143 -0
- data/spec/encode_spec.rb +152 -0
- data/spec/matcher_spec.rb +81 -0
- data/spec/port_spec.rb +34 -0
- data/spec/receiver_spec.rb +103 -0
- data/spec/spec_helper.rb +47 -0
- metadata +153 -0
@@ -0,0 +1,81 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
def false_match(matcher, arg)
|
4
|
+
matcher.matches?(arg).should == false
|
5
|
+
end
|
6
|
+
|
7
|
+
describe "A matcher whose condition is a String (the class object" do
|
8
|
+
before(:each) do
|
9
|
+
@matcher = Beambridge::Matcher.new(nil, Beambridge::TypeCondition.new(String), nil)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should match any string" do
|
13
|
+
@matcher.matches?("foo").should == true
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should not match symbols" do
|
17
|
+
@matcher.matches?(:foo).should == false
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "A matcher whose condition is Symbol (the class object)" do
|
22
|
+
before(:each) do
|
23
|
+
@matcher = Beambridge::Matcher.new(nil, Beambridge::TypeCondition.new(Symbol), nil)
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should match any symbol" do
|
27
|
+
@matcher.matches?(:foo).should == true
|
28
|
+
@matcher.matches?(:bar).should == true
|
29
|
+
@matcher.matches?(:baz).should == true
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should not match strings" do
|
33
|
+
@matcher.matches?("foo").should == false
|
34
|
+
@matcher.matches?("bar").should == false
|
35
|
+
@matcher.matches?("baz").should == false
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should not match a arrays" do
|
39
|
+
@matcher.matches?([:foo]).should == false
|
40
|
+
@matcher.matches?([:foo, :bar]).should == false
|
41
|
+
@matcher.matches?([:foo, :bar, :baz]).should == false
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "a matcher whose condition is a symbol" do
|
46
|
+
before(:each) do
|
47
|
+
@matcher = Beambridge::Matcher.new(nil, Beambridge::StaticCondition.new(:foo), nil)
|
48
|
+
end
|
49
|
+
|
50
|
+
it "should match that symbol" do
|
51
|
+
@matcher.matches?(:foo).should == true
|
52
|
+
end
|
53
|
+
|
54
|
+
it "should not match any other symbol" do
|
55
|
+
@matcher.matches?(:bar).should == false
|
56
|
+
@matcher.matches?(:baz).should == false
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe "a matcher whose matcher is an array" do
|
61
|
+
|
62
|
+
it "should match if all of its children match" do
|
63
|
+
Beambridge::Matcher.new(nil, [Beambridge::StaticCondition.new(:speak), Beambridge::TypeCondition.new(Object)], nil).matches?([:paste, "haha"]).should == false
|
64
|
+
|
65
|
+
matcher = Beambridge::Matcher.new(nil, [Beambridge::StaticCondition.new(:foo), Beambridge::StaticCondition.new(:bar)], nil)
|
66
|
+
matcher.matches?([:foo, :bar]).should == true
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should not match any of its children dont match" do
|
70
|
+
matcher = Beambridge::Matcher.new(nil, [Beambridge::StaticCondition.new(:foo), Beambridge::StaticCondition.new(:bar)], nil)
|
71
|
+
matcher.matches?([:foo]).should == false
|
72
|
+
matcher.matches?([:foo, :bar, :baz]).should == false
|
73
|
+
matcher.matches?([:fooo, :barr]).should == false
|
74
|
+
matcher.matches?([3, :bar]).should == false
|
75
|
+
end
|
76
|
+
|
77
|
+
it "should not match if arg isn't an array" do
|
78
|
+
matcher = Beambridge::Matcher.new(nil, [Beambridge::StaticCondition.new(:foo), Beambridge::StaticCondition.new(:bar)], nil)
|
79
|
+
matcher.matches?(:foo).should == false
|
80
|
+
end
|
81
|
+
end
|
data/spec/port_spec.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe "A port" do
|
4
|
+
it "should return terms from the queue if it is not empty" do
|
5
|
+
port = FakePort.new()
|
6
|
+
port.queue.clear
|
7
|
+
port.queue << :foo << :bar
|
8
|
+
port.receive.should == :foo
|
9
|
+
port.receive.should == :bar
|
10
|
+
port.receive.should == nil
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should read_from_input if the queue gets empty" do
|
14
|
+
port = FakePort.new(:bar)
|
15
|
+
port.queue.clear
|
16
|
+
port.queue << :foo
|
17
|
+
port.receive.should == :foo
|
18
|
+
port.receive.should == :bar
|
19
|
+
port.receive.should == nil
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should put the terms in skipped at the front of queue when restore_skipped is called" do
|
23
|
+
port = FakePort.new(:baz)
|
24
|
+
port.queue.clear
|
25
|
+
port.queue << :bar
|
26
|
+
port.skipped << :foo
|
27
|
+
port.restore_skipped
|
28
|
+
|
29
|
+
port.receive.should == :foo
|
30
|
+
port.receive.should == :bar
|
31
|
+
port.receive.should == :baz
|
32
|
+
port.receive.should == nil
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,103 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
def simple_receiver_and_port(*terms, &block)
|
4
|
+
port = FakePort.new(*terms)
|
5
|
+
receiver = if block
|
6
|
+
Beambridge::Receiver.new(port, &block)
|
7
|
+
else
|
8
|
+
Beambridge::Receiver.new(port) do |f|
|
9
|
+
f.when Erl.any do
|
10
|
+
:matched
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "When a receiver is passed a message that matches two match blocks it" do
|
17
|
+
before(:each) do
|
18
|
+
@port = FakePort.new([:foo, :foo])
|
19
|
+
@receiver = Beambridge::Receiver.new(@port) do |f|
|
20
|
+
f.when([:foo, :foo]) do
|
21
|
+
:first
|
22
|
+
end
|
23
|
+
|
24
|
+
f.when([:foo, Erl.any]) do
|
25
|
+
:second
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should run the first matching receiver's block" do
|
31
|
+
@receiver.run.should == :first
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "A receiver" do
|
36
|
+
it "should return the result of the match block when finished" do
|
37
|
+
simple_receiver_and_port(:foo).run.should == :matched
|
38
|
+
simple_receiver_and_port(:bar).run.should == :matched
|
39
|
+
simple_receiver_and_port(:bar, :baz).run.should == :matched
|
40
|
+
end
|
41
|
+
|
42
|
+
it "should process another message if the matched block returns the results of receive_loop" do
|
43
|
+
recv = simple_receiver_and_port(:foo, :bar, :baz) do |f|
|
44
|
+
f.when(:bar) { }
|
45
|
+
f.when(Erl.any) { f.receive_loop }
|
46
|
+
end
|
47
|
+
|
48
|
+
recv.run
|
49
|
+
recv.port.terms.should == [:baz]
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should properly nest" do
|
53
|
+
@port = FakePort.new(:foo, :bar, :baz)
|
54
|
+
@receiver = Beambridge::Receiver.new(@port) do |f|
|
55
|
+
f.when(:foo) do
|
56
|
+
f.receive do |g|
|
57
|
+
g.when(:bar){ :ok }
|
58
|
+
end
|
59
|
+
f.receive_loop
|
60
|
+
end
|
61
|
+
|
62
|
+
f.when(:baz) do
|
63
|
+
:done
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
@receiver.run.should == :done
|
68
|
+
@port.terms.should == []
|
69
|
+
end
|
70
|
+
|
71
|
+
it "should queue up skipped results and restore them when a match happens" do
|
72
|
+
@port = FakePort.new(:foo, :baz, :bar)
|
73
|
+
@receiver = Beambridge::Receiver.new(@port) do |f|
|
74
|
+
f.when(:foo) do
|
75
|
+
f.receive do |g|
|
76
|
+
g.when(:bar){ :ok }
|
77
|
+
end
|
78
|
+
f.receive_loop
|
79
|
+
end
|
80
|
+
|
81
|
+
f.when(:baz) do
|
82
|
+
:done
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
@receiver.run.should == :done
|
87
|
+
@port.terms.should == []
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should expose bindings to the matched block" do
|
91
|
+
@port = FakePort.new(:foo, :bar, :baz)
|
92
|
+
results = []
|
93
|
+
@receiver = Beambridge::Receiver.new(@port) do |f|
|
94
|
+
f.when(Erl.atom) do |bindinated|
|
95
|
+
results << bindinated
|
96
|
+
f.receive_loop
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
@receiver.run.should == nil
|
101
|
+
results.should == [:foo, :bar, :baz]
|
102
|
+
end
|
103
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
require "bundler/setup"
|
2
|
+
|
3
|
+
require "stringio"
|
4
|
+
require "pry"
|
5
|
+
require "beambridge"
|
6
|
+
|
7
|
+
$stdout.sync = true
|
8
|
+
|
9
|
+
module BeambridgeTestHelpers
|
10
|
+
def run_erl(code)
|
11
|
+
%x{erl -noshell -eval "A = #{code.split.join(' ')}, io:put_chars(binary_to_list(A))." -s erlang halt}
|
12
|
+
end
|
13
|
+
|
14
|
+
def encode_packet(code)
|
15
|
+
bin = run_erl("term_to_binary(#{code})")
|
16
|
+
[bin.length, bin].pack("Na#{bin.length}")
|
17
|
+
end
|
18
|
+
|
19
|
+
def word_length
|
20
|
+
(1.size * 8) - 2
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
class FakePort < Beambridge::Port
|
25
|
+
attr_reader :sent
|
26
|
+
attr_reader :terms
|
27
|
+
|
28
|
+
def initialize(*terms)
|
29
|
+
@terms = terms
|
30
|
+
@sent = []
|
31
|
+
super(StringIO.new(""), StringIO.new(""))
|
32
|
+
end
|
33
|
+
|
34
|
+
def send(term)
|
35
|
+
sent << term
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def read_from_input
|
41
|
+
@terms.shift
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
RSpec.configure do |config|
|
46
|
+
config.include BeambridgeTestHelpers
|
47
|
+
end
|
metadata
ADDED
@@ -0,0 +1,153 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: beambridge
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Scott Fleckenstein
|
8
|
+
- Tom Preston-Werner
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2014-01-25 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ! '>='
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :development
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ! '>='
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: rspec
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :development
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ! '>='
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: pry-nav
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :development
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
description: Asset pipeline CLI to be executed from a different language.
|
57
|
+
email:
|
58
|
+
- mathieul@gmail.com
|
59
|
+
executables: []
|
60
|
+
extensions:
|
61
|
+
- ext/extconf.rb
|
62
|
+
extra_rdoc_files:
|
63
|
+
- LICENSE
|
64
|
+
- README.md
|
65
|
+
files:
|
66
|
+
- .gitignore
|
67
|
+
- .rspec
|
68
|
+
- Gemfile
|
69
|
+
- History.txt
|
70
|
+
- LICENSE
|
71
|
+
- README.md
|
72
|
+
- Rakefile
|
73
|
+
- VERSION.yml
|
74
|
+
- beambridge.gemspec
|
75
|
+
- benchmarks/bench.rb
|
76
|
+
- examples/echo/README.md
|
77
|
+
- examples/echo/echo.erl
|
78
|
+
- examples/echo/echo.rb
|
79
|
+
- examples/gruff/gruff.erl
|
80
|
+
- examples/gruff/gruff_provider.rb
|
81
|
+
- examples/gruff/gruff_run.sh
|
82
|
+
- examples/gruff/stat_run.sh
|
83
|
+
- examples/gruff/stat_writer.erl
|
84
|
+
- examples/simple/README.md
|
85
|
+
- examples/simple/rerl.rb
|
86
|
+
- examples/simple/rerl.sh
|
87
|
+
- examples/tinderl/README.md
|
88
|
+
- examples/tinderl/tinderl.erl
|
89
|
+
- examples/tinderl/tinderl.rb
|
90
|
+
- ext/decoder.c
|
91
|
+
- ext/extconf.rb
|
92
|
+
- lib/beambridge.rb
|
93
|
+
- lib/beambridge/condition.rb
|
94
|
+
- lib/beambridge/conditions/boolean.rb
|
95
|
+
- lib/beambridge/conditions/hash.rb
|
96
|
+
- lib/beambridge/conditions/static.rb
|
97
|
+
- lib/beambridge/conditions/type.rb
|
98
|
+
- lib/beambridge/constants.rb
|
99
|
+
- lib/beambridge/decoder.rb
|
100
|
+
- lib/beambridge/encoder.rb
|
101
|
+
- lib/beambridge/errors/beambridge_error.rb
|
102
|
+
- lib/beambridge/errors/decode_error.rb
|
103
|
+
- lib/beambridge/errors/encode_error.rb
|
104
|
+
- lib/beambridge/matcher.rb
|
105
|
+
- lib/beambridge/port.rb
|
106
|
+
- lib/beambridge/receiver.rb
|
107
|
+
- lib/beambridge/types/function.rb
|
108
|
+
- lib/beambridge/types/list.rb
|
109
|
+
- lib/beambridge/types/new_function.rb
|
110
|
+
- lib/beambridge/types/new_reference.rb
|
111
|
+
- lib/beambridge/types/pid.rb
|
112
|
+
- lib/beambridge/types/reference.rb
|
113
|
+
- lib/beambridge/version.rb
|
114
|
+
- spec/condition_spec.rb
|
115
|
+
- spec/decode_spec.rb
|
116
|
+
- spec/encode_spec.rb
|
117
|
+
- spec/matcher_spec.rb
|
118
|
+
- spec/port_spec.rb
|
119
|
+
- spec/receiver_spec.rb
|
120
|
+
- spec/spec_helper.rb
|
121
|
+
homepage: https://github.com/mathieul/beambridge
|
122
|
+
licenses:
|
123
|
+
- Scott Fleckenstein and Tom Preston-Werner
|
124
|
+
metadata: {}
|
125
|
+
post_install_message:
|
126
|
+
rdoc_options: []
|
127
|
+
require_paths:
|
128
|
+
- lib
|
129
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
130
|
+
requirements:
|
131
|
+
- - ! '>='
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
version: '0'
|
134
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ! '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
requirements: []
|
140
|
+
rubyforge_project:
|
141
|
+
rubygems_version: 2.2.0
|
142
|
+
signing_key:
|
143
|
+
specification_version: 4
|
144
|
+
summary: A command to pre-process web assets using Ruby tools, intended to be called
|
145
|
+
from a different language.
|
146
|
+
test_files:
|
147
|
+
- spec/condition_spec.rb
|
148
|
+
- spec/decode_spec.rb
|
149
|
+
- spec/encode_spec.rb
|
150
|
+
- spec/matcher_spec.rb
|
151
|
+
- spec/port_spec.rb
|
152
|
+
- spec/receiver_spec.rb
|
153
|
+
- spec/spec_helper.rb
|