ernie 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ = 1.2.0 / 2009-11-23
2
+ * API Additions
3
+ * Add Ernie.expose
4
+ * Internal Changes
5
+ * Remove 15s internal timeout
6
+
1
7
  = 1.1.0 / 2009-10-28
2
8
  * Major changes
3
9
  * Remove dependency on Erlectricity
data/README.md CHANGED
@@ -51,6 +51,8 @@ Running
51
51
  Example Handler
52
52
  ---------------
53
53
 
54
+ Using the DSL:
55
+
54
56
  require 'ernie'
55
57
 
56
58
  mod(:calc) do
@@ -59,6 +61,18 @@ Example Handler
59
61
  end
60
62
  end
61
63
 
64
+ Using Ernie.expose:
65
+
66
+ require 'ernie'
67
+
68
+ module Calc
69
+ def add(a, b)
70
+ a + b
71
+ end
72
+ end
73
+
74
+ Ernie.expose(:calc, Calc)
75
+
62
76
 
63
77
  Example BERT-RPC call for above example
64
78
  ---------------------------------------
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :minor: 1
2
+ :minor: 2
3
3
  :patch: 0
4
4
  :major: 1
@@ -15,8 +15,6 @@ rpc(WrappedPort, Message) ->
15
15
  send(WrappedPort, Message),
16
16
  receive
17
17
  {WrappedPort, Result} -> {ok, Result}
18
- after 15000 ->
19
- {error, timed_out, WrappedPort}
20
18
  end.
21
19
 
22
20
  send(WrappedPort, Message) ->
data/ernie.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{ernie}
8
- s.version = "1.1.0"
8
+ s.version = "1.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Tom Preston-Werner"]
12
- s.date = %q{2009-10-28}
12
+ s.date = %q{2009-11-23}
13
13
  s.default_executable = %q{ernie}
14
14
  s.email = %q{tom@mojombo.com}
15
15
  s.executables = ["ernie"]
@@ -37,7 +37,8 @@ Gem::Specification.new do |s|
37
37
  "elib/logger_sup.erl",
38
38
  "elib/port_wrapper.erl",
39
39
  "ernie.gemspec",
40
- "examples/calc.rb",
40
+ "examples/dsl.rb",
41
+ "examples/expose.rb",
41
42
  "ext/Makefile",
42
43
  "ext/extconf.rb",
43
44
  "lib/ernie.rb",
@@ -58,7 +59,8 @@ Gem::Specification.new do |s|
58
59
  "test/handler.rb",
59
60
  "test/helper.rb",
60
61
  "test/load.rb",
61
- "examples/calc.rb"
62
+ "examples/dsl.rb",
63
+ "examples/expose.rb"
62
64
  ]
63
65
 
64
66
  if s.respond_to? :specification_version then
data/examples/dsl.rb ADDED
@@ -0,0 +1,25 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require 'ernie'
3
+
4
+ mod(:test) do
5
+ # Add two numbers together
6
+ fun(:add) do |a, b|
7
+ a + b
8
+ end
9
+
10
+ # Return the given number of bytes
11
+ fun(:bytes) do |bytes|
12
+ 'x' * bytes
13
+ end
14
+
15
+ # Sleep for +sec+ and then return :ok
16
+ fun(:slow) do |sec|
17
+ sleep(sec)
18
+ :ok
19
+ end
20
+
21
+ # Throw an error
22
+ fun(:error) do |a, b|
23
+ raise "abandon hope!"
24
+ end
25
+ end
@@ -0,0 +1,27 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require 'ernie'
3
+
4
+ module Test
5
+ # Add two numbers together
6
+ def add(a, b)
7
+ a + b
8
+ end
9
+
10
+ # Return the given number of bytes
11
+ def bytes(n)
12
+ 'x' * n
13
+ end
14
+
15
+ # Sleep for +sec+ and then return :ok
16
+ def slow(sec)
17
+ sleep(sec)
18
+ :ok
19
+ end
20
+
21
+ # Throw an error
22
+ def error
23
+ raise "abandon hope!"
24
+ end
25
+ end
26
+
27
+ Ernie.expose(:test, Test)
data/lib/ernie.rb CHANGED
@@ -32,6 +32,22 @@ class Ernie
32
32
  self.current_mod.fun(name, block)
33
33
  end
34
34
 
35
+ # Expose all public methods in a Ruby module:
36
+ # +name+ is the ernie module Symbol
37
+ # +mixin+ is the ruby module whose public methods are exposed
38
+ #
39
+ # Returns nothing
40
+ def self.expose(name, mixin)
41
+ context = Object.new
42
+ context.extend mixin
43
+ mod(name, lambda {
44
+ mixin.public_instance_methods.each do |meth|
45
+ fun(meth.to_sym, context.method(meth))
46
+ end
47
+ })
48
+ context
49
+ end
50
+
35
51
  # Set the logfile to given path.
36
52
  # +file+ is the String path to the logfile
37
53
  #
@@ -182,4 +198,4 @@ end
182
198
 
183
199
  at_exit do
184
200
  Ernie.start unless $test
185
- end
201
+ end
data/test/ernie_test.rb CHANGED
@@ -15,4 +15,44 @@ class ErnieTest < Test::Unit::TestCase
15
15
  assert Ernie.mods[:foo].funs[:bar]
16
16
  end
17
17
  end
18
+
19
+ module TestExposingModule
20
+ def foo
21
+ end
22
+
23
+ def bar(a, b, c=nil)
24
+ [a, b, c]
25
+ end
26
+
27
+ protected
28
+ def baz
29
+ end
30
+
31
+ private
32
+ def bling
33
+ end
34
+ end
35
+
36
+ context "expose" do
37
+ setup { Ernie.expose :expo, TestExposingModule }
38
+ teardown { Ernie.mods.clear }
39
+
40
+ should "add all public methods from the module" do
41
+ assert_not_nil Ernie.mods[:expo].funs[:foo]
42
+ assert_not_nil Ernie.mods[:expo].funs[:bar]
43
+ end
44
+
45
+ should "not expose protected methods" do
46
+ assert_nil Ernie.mods[:expo].funs[:baz]
47
+ end
48
+
49
+ should "not expose private methods" do
50
+ assert_nil Ernie.mods[:expo].funs[:bling]
51
+ end
52
+
53
+ should "dispatch to module methods properly" do
54
+ res = Ernie.dispatch(:expo, :bar, ['a', :b, { :fiz => 42 }])
55
+ assert_equal ['a', :b, { :fiz => 42 }], res
56
+ end
57
+ end
18
58
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ernie
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tom Preston-Werner
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-28 00:00:00 -07:00
12
+ date: 2009-11-23 00:00:00 -08:00
13
13
  default_executable: ernie
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -60,7 +60,8 @@ files:
60
60
  - elib/logger_sup.erl
61
61
  - elib/port_wrapper.erl
62
62
  - ernie.gemspec
63
- - examples/calc.rb
63
+ - examples/dsl.rb
64
+ - examples/expose.rb
64
65
  - ext/Makefile
65
66
  - ext/extconf.rb
66
67
  - lib/ernie.rb
@@ -103,4 +104,5 @@ test_files:
103
104
  - test/handler.rb
104
105
  - test/helper.rb
105
106
  - test/load.rb
106
- - examples/calc.rb
107
+ - examples/dsl.rb
108
+ - examples/expose.rb
data/examples/calc.rb DELETED
@@ -1,28 +0,0 @@
1
- $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
- require 'ernie'
3
-
4
- # Just about the easiest example I could thing of.
5
- mod(:calc) do
6
- fun(:add) do |a, b|
7
- a + b
8
- end
9
- end
10
-
11
- # Useful for tests that need to simulate longer running functions.
12
- mod(:slowcalc) do
13
- fun(:add) do |a, b|
14
- sleep(rand * 2)
15
- a + b
16
- end
17
-
18
- fun(:superslow) do
19
- sleep 10
20
- end
21
- end
22
-
23
- # Throw an error
24
- mod(:errorcalc) do
25
- fun(:add) do |a, b|
26
- raise "abandon hope!"
27
- end
28
- end