zactor 0.0.5 → 0.0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/.rake_tasks~ +19 -0
- data/.yardopts +1 -0
- data/Gemfile +6 -2
- data/Gemfile.lock +66 -16
- data/Guardfile +12 -0
- data/README.md +147 -73
- data/Rakefile +0 -2
- data/VERSION +1 -0
- data/examples/chat/client.rb +88 -0
- data/examples/chat/server.rb +59 -0
- data/examples/ping/inproc.rb +50 -0
- data/lib/zactor.rb +263 -0
- data/lib/zactor/actor_pub.rb +19 -0
- data/lib/zactor/actor_sub.rb +46 -0
- data/lib/zactor/broker.rb +71 -0
- data/lib/zactor/log_subscriber.rb +25 -0
- data/lib/zactor/message.rb +23 -0
- data/lib/zactor/version.rb +3 -0
- data/spec/lib/actor_spec.rb +136 -0
- data/spec/lib/exchange_spec.rb +81 -0
- data/spec/lib/link_spec.rb +67 -0
- data/spec/lib/zactor_spec.rb +40 -0
- data/spec/spec_helper.rb +1 -1
- data/{ruby-interface.gemspec → zactor.gemspec} +13 -7
- metadata +100 -15
- data/lib/ruby-interface/version.rb +0 -3
- data/lib/ruby-interface/yard.rb +0 -8
- data/lib/ruby_interface.rb +0 -71
- data/spec/ruby_interface_spec.rb +0 -127
data/lib/ruby-interface/yard.rb
DELETED
data/lib/ruby_interface.rb
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
require 'active_support/core_ext/class/attribute'
|
3
|
-
require 'active_support/core_ext/string/inflections'
|
4
|
-
|
5
|
-
module RubyInterface
|
6
|
-
def interface(method_name, &interface_body)
|
7
|
-
mod_inst = self.const_set("#{method_name.to_s.camelize}InstanceMethods", Module.new)
|
8
|
-
mod_inst.module_eval <<-EOT, __FILE__, __LINE__ + 1
|
9
|
-
def #{method_name}
|
10
|
-
@#{method_name}_interface ||= self.class.#{method_name}_interface.new(self)
|
11
|
-
end
|
12
|
-
EOT
|
13
|
-
|
14
|
-
|
15
|
-
mod_class = self.const_set("#{method_name.to_s.camelize}ClassMethods", Module.new)
|
16
|
-
mod_class.module_eval <<-EOT, __FILE__, __LINE__ + 1
|
17
|
-
def #{method_name}(&blk)
|
18
|
-
self.#{method_name}_interface.class_eval(&blk) if blk
|
19
|
-
self.#{method_name}_interface
|
20
|
-
end
|
21
|
-
|
22
|
-
def inherited(subclass)
|
23
|
-
new_class = subclass.const_set("#{method_name.to_s.camelize}InterfaceClass", Class.new(self.#{method_name}_interface))
|
24
|
-
new_class.interface_base = subclass
|
25
|
-
subclass.#{method_name}_interface = new_class
|
26
|
-
super
|
27
|
-
end
|
28
|
-
EOT
|
29
|
-
|
30
|
-
interface_module = self
|
31
|
-
|
32
|
-
add_interface do |base|
|
33
|
-
base.send(:class_attribute, "#{method_name}_interface")
|
34
|
-
interface_class = base.const_set("#{method_name.to_s.camelize}InterfaceClass", Class.new(RubyInterface::InterfaceClass))
|
35
|
-
interface_class.interface_base = base
|
36
|
-
interface_class.class_eval(&interface_body) if interface_body
|
37
|
-
base.send("#{method_name}_interface=", interface_class)
|
38
|
-
base.extend mod_class
|
39
|
-
base.send :include, mod_inst
|
40
|
-
base.class_eval(&interface_class.interfaced) if interface_class.interfaced
|
41
|
-
end
|
42
|
-
|
43
|
-
interface_module.define_singleton_method(:included) do |base|
|
44
|
-
@_deps.each {|d| d.call(base)}
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
private
|
49
|
-
def add_interface &block
|
50
|
-
@_deps ||= []
|
51
|
-
@_deps << block
|
52
|
-
end
|
53
|
-
|
54
|
-
class InterfaceClass
|
55
|
-
class_attribute :interface_base
|
56
|
-
attr_accessor :owner
|
57
|
-
def initialize(owner)
|
58
|
-
@owner = owner
|
59
|
-
end
|
60
|
-
|
61
|
-
class << self
|
62
|
-
def interfaced(&block)
|
63
|
-
if block_given?
|
64
|
-
@_interfaced_block = block
|
65
|
-
else
|
66
|
-
@_interfaced_block
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
data/spec/ruby_interface_spec.rb
DELETED
@@ -1,127 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
require 'spec_helper'
|
3
|
-
|
4
|
-
describe RubyInterface do
|
5
|
-
def make_interface
|
6
|
-
mod = Module.new
|
7
|
-
mod.extend(RubyInterface)
|
8
|
-
mod
|
9
|
-
end
|
10
|
-
|
11
|
-
describe "Создание интерфейса" do
|
12
|
-
let(:mod) { make_interface.tap { |v| v.interface(:test) } }
|
13
|
-
|
14
|
-
it "должен вызываться interfaced, если определен" do
|
15
|
-
@proc = proc {}
|
16
|
-
klass = Class.new
|
17
|
-
mod.interface :int do
|
18
|
-
interfaced(&@proc)
|
19
|
-
end
|
20
|
-
mock(klass).class_eval(&@proc)
|
21
|
-
mock(klass).class_eval(&@proc)
|
22
|
-
klass.send :include, mod
|
23
|
-
end
|
24
|
-
|
25
|
-
describe "Класс с интерфейсом" do
|
26
|
-
subject { klass }
|
27
|
-
let(:klass) { Class.new.tap { |v| v.send :include, mod } }
|
28
|
-
let(:interface_klass) { klass.test_interface }
|
29
|
-
its(:test) { should eq(interface_klass) }
|
30
|
-
|
31
|
-
it "может дополнять класс интерфейса" do
|
32
|
-
interface_klass.respond_to?(:test).should be_false
|
33
|
-
klass.test do
|
34
|
-
mattr_accessor :test
|
35
|
-
end
|
36
|
-
interface_klass.respond_to?(:test).should be_true
|
37
|
-
end
|
38
|
-
|
39
|
-
it "должен содержать класс интерфейса" do
|
40
|
-
klass::TestInterfaceClass.ancestors.should include(RubyInterface::InterfaceClass)
|
41
|
-
klass.test_interface.should eq(klass::TestInterfaceClass)
|
42
|
-
end
|
43
|
-
|
44
|
-
describe "Класс интерфейса" do
|
45
|
-
subject { interface_klass }
|
46
|
-
its(:interface_base) { should eq(klass) }
|
47
|
-
|
48
|
-
describe "Объект с интерфейсом" do
|
49
|
-
subject { obj }
|
50
|
-
let(:obj) { klass.new }
|
51
|
-
its(:test) { should be_kind_of(interface_klass)}
|
52
|
-
describe "Объект интерфейса" do
|
53
|
-
subject { interface_obj }
|
54
|
-
let(:interface_obj) { obj.test }
|
55
|
-
its(:owner) { should eq(obj) }
|
56
|
-
let(:mod) do
|
57
|
-
make_interface.tap do |v|
|
58
|
-
v.interface(:test) do
|
59
|
-
def foo
|
60
|
-
"bar"
|
61
|
-
end
|
62
|
-
end
|
63
|
-
end
|
64
|
-
end
|
65
|
-
|
66
|
-
it "должен поддерживать методы определенные в интерфейсе" do
|
67
|
-
interface_obj.foo.should eq('bar')
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
describe "при наследовании" do
|
73
|
-
let(:klass2) { Class.new(klass) }
|
74
|
-
it "должен создавать новый интерфейс-класс, наследуя старый" do
|
75
|
-
klass2.test.ancestors.should include(interface_klass)
|
76
|
-
end
|
77
|
-
it "новый интерфейс-класс должен ссылаться на новый класс" do
|
78
|
-
klass2.test.interface_base.should eq(klass2)
|
79
|
-
end
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
describe "Модуль с двумя интерфейсами" do
|
88
|
-
before(:each) do
|
89
|
-
@mod = Module.new
|
90
|
-
@mod.send :extend, RubyInterface
|
91
|
-
@mod.interface :first do
|
92
|
-
interfaced do
|
93
|
-
def baz
|
94
|
-
first.foo
|
95
|
-
end
|
96
|
-
end
|
97
|
-
|
98
|
-
def foo
|
99
|
-
"bar"
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
@mod.interface :second do
|
104
|
-
interfaced do
|
105
|
-
self.second_interface.foo
|
106
|
-
end
|
107
|
-
|
108
|
-
def self.foo
|
109
|
-
"baz"
|
110
|
-
end
|
111
|
-
end
|
112
|
-
end
|
113
|
-
|
114
|
-
it "не должно происходить ошибок при подключении модуля с двумя интерфейсами" do
|
115
|
-
b = Class.new
|
116
|
-
lambda { b.send :include, @mod }.should_not raise_error
|
117
|
-
end
|
118
|
-
|
119
|
-
it "должны появиться интерфейсы с методами" do
|
120
|
-
b = Class.new
|
121
|
-
b.send :include, @mod
|
122
|
-
bb = b.new
|
123
|
-
bb.baz.should eq("bar")
|
124
|
-
bb.second_interface.foo.should eq("baz")
|
125
|
-
end
|
126
|
-
end
|
127
|
-
end
|