vigilem-core 0.0.9
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.
- checksums.yaml +7 -0
- data/lib/vigilem/core.rb +9 -0
- data/lib/vigilem/core/abstract_device.rb +97 -0
- data/lib/vigilem/core/adapters.rb +2 -0
- data/lib/vigilem/core/adapters/adapter.rb +57 -0
- data/lib/vigilem/core/adapters/basic_adapter.rb +43 -0
- data/lib/vigilem/core/adapters/buffered_adapter.rb +28 -0
- data/lib/vigilem/core/buffer.rb +151 -0
- data/lib/vigilem/core/buffer_handler.rb +95 -0
- data/lib/vigilem/core/default_buffer.rb +45 -0
- data/lib/vigilem/core/demultiplexer.rb +225 -0
- data/lib/vigilem/core/device.rb +43 -0
- data/lib/vigilem/core/event_handler.rb +156 -0
- data/lib/vigilem/core/eventable.rb +80 -0
- data/lib/vigilem/core/hooks.rb +36 -0
- data/lib/vigilem/core/hooks/callback.rb +66 -0
- data/lib/vigilem/core/hooks/callback_proc.rb +25 -0
- data/lib/vigilem/core/hooks/conditional_hook.rb +62 -0
- data/lib/vigilem/core/hooks/hook.rb +193 -0
- data/lib/vigilem/core/hooks/inheritable.rb +24 -0
- data/lib/vigilem/core/hooks/meta_callback.rb +53 -0
- data/lib/vigilem/core/hooks/utils.rb +23 -0
- data/lib/vigilem/core/hub.rb +50 -0
- data/lib/vigilem/core/input_system_handler.rb +55 -0
- data/lib/vigilem/core/lockable_pipeline_component.rb +30 -0
- data/lib/vigilem/core/multiplexer.rb +168 -0
- data/lib/vigilem/core/pipeline.rb +68 -0
- data/lib/vigilem/core/stat.rb +121 -0
- data/lib/vigilem/core/system.rb +9 -0
- data/lib/vigilem/core/system/check.rb +33 -0
- data/lib/vigilem/core/transfer_agent.rb +67 -0
- data/lib/vigilem/core/version.rb +5 -0
- data/spec/bug_notes.txt +12 -0
- data/spec/given_helper.rb +12 -0
- data/spec/spec_helper.rb +7 -0
- data/spec/vigilem/core/abstract_device_spec.rb +103 -0
- data/spec/vigilem/core/adapters/adapter_spec.rb +28 -0
- data/spec/vigilem/core/adapters/basic_adapter_spec.rb +53 -0
- data/spec/vigilem/core/adapters/buffered_adapter_spec.rb +16 -0
- data/spec/vigilem/core/buffer_handler_spec.rb +51 -0
- data/spec/vigilem/core/buffer_spec.rb +236 -0
- data/spec/vigilem/core/default_buffer_spec.rb +17 -0
- data/spec/vigilem/core/demultiplexer_spec.rb +166 -0
- data/spec/vigilem/core/device_spec.rb +62 -0
- data/spec/vigilem/core/event_handler_spec.rb +134 -0
- data/spec/vigilem/core/hooks/callback_proc_spec.rb +66 -0
- data/spec/vigilem/core/hooks/hook_spec.rb +230 -0
- data/spec/vigilem/core/hooks/inheritable_spec.rb +19 -0
- data/spec/vigilem/core/hooks/meta_callback_spec.rb +69 -0
- data/spec/vigilem/core/hooks/utils_spec.rb +25 -0
- data/spec/vigilem/core/hooks_spec.rb +50 -0
- data/spec/vigilem/core/hub_spec.rb +51 -0
- data/spec/vigilem/core/input_system_handler_spec.rb +33 -0
- data/spec/vigilem/core/lockable_pipeline_component_spec.rb +19 -0
- data/spec/vigilem/core/multiplexer_spec.rb +113 -0
- data/spec/vigilem/core/pipeline_spec.rb +5 -0
- data/spec/vigilem/core/stat_spec.rb +63 -0
- data/spec/vigilem/core/system/check_spec.rb +24 -0
- data/spec/vigilem/core/system_spec.rb +29 -0
- data/spec/vigilem/core/transfer_agent_spec.rb +80 -0
- metadata +273 -0
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'vigilem/core/device'
|
4
|
+
|
5
|
+
describe Vigilem::Core::Device do
|
6
|
+
describe '#new' do
|
7
|
+
|
8
|
+
Stat = Vigilem::Core::Stat
|
9
|
+
|
10
|
+
before(:each) do
|
11
|
+
Stat.all << double('fake_stat', :available? => true, :input_system_name => 'guy on the couch')
|
12
|
+
end
|
13
|
+
|
14
|
+
after(:each) do
|
15
|
+
Stat.all.replace([])
|
16
|
+
end
|
17
|
+
|
18
|
+
subject do
|
19
|
+
described_class.new do
|
20
|
+
on_os(/.+/) do
|
21
|
+
@adaptability_level = 'Tardigrade'
|
22
|
+
end
|
23
|
+
|
24
|
+
on_input_system(/.+/) do
|
25
|
+
@mode = 'stun'
|
26
|
+
end
|
27
|
+
after_init { @testr = 'test' }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
context 'class creation' do
|
32
|
+
it 'creates a Class if block given' do
|
33
|
+
expect(subject).to be_instance_of(Class)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'instantiation' do
|
38
|
+
|
39
|
+
it 'throws error when settings are empty' do
|
40
|
+
expect { described_class.new }.to raise_error(RuntimeError)
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'will pass system_checks' do
|
44
|
+
expect { subject.new }.to_not raise_error
|
45
|
+
end
|
46
|
+
|
47
|
+
context 'hooks' do
|
48
|
+
it 'runs #on_os hook' do
|
49
|
+
expect(subject.new.instance_variable_get(:@adaptability_level)).to eql 'Tardigrade'
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'runs #on_input_system hook' do
|
53
|
+
expect(subject.new.instance_variable_get(:@mode)).to eql 'stun'
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
@@ -0,0 +1,134 @@
|
|
1
|
+
|
2
|
+
require 'vigilem/core/event_handler'
|
3
|
+
|
4
|
+
describe Vigilem::Core::EventHandler do
|
5
|
+
|
6
|
+
class EventHandlerHost
|
7
|
+
include Vigilem::Core::EventHandler
|
8
|
+
end
|
9
|
+
|
10
|
+
subject { EventHandlerHost.new }
|
11
|
+
|
12
|
+
describe '#type_handles' do
|
13
|
+
|
14
|
+
it 'returns a Hash' do
|
15
|
+
expect(subject.type_handles).to be_a(Hash)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context 'register, execution' do
|
20
|
+
|
21
|
+
let(:handler) do
|
22
|
+
lambda do |event|
|
23
|
+
["I'm handling it", event]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
let!(:register) { subject.on(:my_event, &handler) }
|
28
|
+
|
29
|
+
describe '#on' do
|
30
|
+
it 'adds a block to the hash with the key == type arg' do
|
31
|
+
expect(subject.type_handles[:my_event].call(:my_event)).to eql(handler.call(:my_event))
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
|
36
|
+
describe '#handle' do
|
37
|
+
|
38
|
+
class Event
|
39
|
+
end
|
40
|
+
|
41
|
+
class UnknownEvent
|
42
|
+
end
|
43
|
+
|
44
|
+
let(:event) do
|
45
|
+
Event.new
|
46
|
+
end
|
47
|
+
|
48
|
+
let(:handler) do
|
49
|
+
lambda do |event|
|
50
|
+
["I'm handling it", event]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'executes the registered block with the event as arg' do
|
55
|
+
subject.on(Event, &handler)
|
56
|
+
expect(subject.handle(event)).to eql(["I'm handling it", event])
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'returns nil when event is not registered/handle-able' do
|
60
|
+
subject.on(Event, &handler)
|
61
|
+
expect(subject.handle(UnknownEvent.new)).to be_nil
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
let(:test_name) { 'on_test_event' }
|
66
|
+
|
67
|
+
describe '#type_from_on_format' do
|
68
|
+
it 'strips out the event type from the on_#{event_type} format' do
|
69
|
+
expect(described_class.type_from_on_format(test_name)).to eql(:test_event)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
describe '::type_from_on_format' do
|
74
|
+
it 'returns whether or not the string is in on_#{event_type} format' do
|
75
|
+
expect(described_class.type_from_on_format(test_name)).to be_truthy
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
describe '#respond_to?' do
|
80
|
+
it 'responds to items in the on_#{type} format' do
|
81
|
+
expect(described_class.respond_to?(test_name)).to be_truthy
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context 'private' do
|
86
|
+
|
87
|
+
describe '_define_register' do
|
88
|
+
|
89
|
+
it 'will not respond to direct access' do
|
90
|
+
expect { subject.class._define_register }.to raise_error(NoMethodError, /private method `_define_register'/)
|
91
|
+
end
|
92
|
+
|
93
|
+
class SomeEvent; end
|
94
|
+
|
95
|
+
let!(:run_method) { subject.class.send(:_define_register, SomeEvent, 'some_event') }
|
96
|
+
|
97
|
+
it 'defines the class_method on_#{type} method' do
|
98
|
+
expect(subject.class).to respond_to(:on_some_event)
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'defines the instance_method on_#{type} method' do
|
102
|
+
expect(subject.class.method_defined?(:on_some_event)).to be_truthy
|
103
|
+
end
|
104
|
+
|
105
|
+
it 'returns the method defined' do
|
106
|
+
expect(run_method).to be_a(Method)
|
107
|
+
end
|
108
|
+
|
109
|
+
end
|
110
|
+
|
111
|
+
describe '_define_handler' do
|
112
|
+
|
113
|
+
it 'will not respond to direct access' do
|
114
|
+
expect { subject.class._define_handler }.to raise_error(NoMethodError, /private method `_define_handler'/)
|
115
|
+
end
|
116
|
+
|
117
|
+
class SomeEvent; end
|
118
|
+
|
119
|
+
let!(:run_method) { subject.class.send(:_define_handler, 'some_event') {|event| "this is some_event #{event}" } }
|
120
|
+
|
121
|
+
it 'defines the instance_method on_#{type} method' do
|
122
|
+
expect(subject.class.method_defined?(:handle_some_event)).to be_truthy
|
123
|
+
end
|
124
|
+
|
125
|
+
it 'returns the method defined' do
|
126
|
+
expect(run_method).to be_a(Proc)
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
end #context 'private'
|
131
|
+
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'vigilem/core/hooks'
|
4
|
+
|
5
|
+
describe Vigilem::Core::Hooks::CallbackProc do
|
6
|
+
subject do
|
7
|
+
described_class.new do
|
8
|
+
self
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#evaluate' do
|
13
|
+
|
14
|
+
before(:all) { Context = Class.new }
|
15
|
+
|
16
|
+
context 'class' do
|
17
|
+
|
18
|
+
let!(:result) { subject.evaluate(Context) }
|
19
|
+
|
20
|
+
it 'will run in the class context specified' do
|
21
|
+
expect(result).to eql(Context)
|
22
|
+
end
|
23
|
+
|
24
|
+
it '[] will be the same' do
|
25
|
+
expect(result).to eql(Context)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'will remember the last result' do
|
29
|
+
expect(subject.result).to eql(Context)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
context 'instance' do
|
34
|
+
|
35
|
+
let(:instance) { Context.new }
|
36
|
+
|
37
|
+
let!(:result) { subject.evaluate(instance) }
|
38
|
+
|
39
|
+
it 'will run in the object context specified' do
|
40
|
+
expect(result).to eql(instance)
|
41
|
+
end
|
42
|
+
|
43
|
+
it '[] will be the same' do
|
44
|
+
expect(result).to eql(instance)
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'will remember the last result' do
|
48
|
+
expect(subject.result).to eql(instance)
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '#call' do
|
55
|
+
|
56
|
+
let!(:result) { subject.call }
|
57
|
+
|
58
|
+
it 'will run like Proc' do
|
59
|
+
expect(result).to eql(self)
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'will remember the result' do
|
63
|
+
expect(subject.result).to eql(result)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,230 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'vigilem/core/hooks'
|
4
|
+
|
5
|
+
describe Vigilem::Core::Hooks::Hook do
|
6
|
+
|
7
|
+
subject { described_class.new(:testr) }
|
8
|
+
|
9
|
+
describe '#new' do
|
10
|
+
|
11
|
+
it 'to yield itself' do
|
12
|
+
expect {|b| described_class.new(:testr, &b).to yield_control }
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
|
17
|
+
context 'after initialized' do
|
18
|
+
|
19
|
+
let!(:init_size) { subject.callbacks.size }
|
20
|
+
|
21
|
+
describe '#<<' do
|
22
|
+
|
23
|
+
let!(:callbacks) { subject << lambda { self } }
|
24
|
+
|
25
|
+
it 'should increase callbacks by one' do
|
26
|
+
expect(subject.callbacks.size).to eql(init_size + 1)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'will return a full the list of callbacks' do
|
30
|
+
expect(callbacks).to equal(subject.callbacks)
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'will convert procs to Callbacks' do
|
34
|
+
expect(callbacks.all? {|cb| cb.is_a? Vigilem::Core::Hooks::Callback }).to be_truthy
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#add' do
|
39
|
+
let!(:callbacks) { subject.add { self } }
|
40
|
+
|
41
|
+
it 'should increase callbacks by one' do
|
42
|
+
expect(subject.callbacks.size).to eql(init_size + 1)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'will return a full the list of callbacks' do
|
46
|
+
expect(callbacks).to equal(subject.callbacks)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'will convert procs to Callbacks' do
|
50
|
+
expect(callbacks.all? {|cb| cb.is_a? Vigilem::Core::Hooks::Callback }).to be_truthy
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
describe '#callbacks' do
|
55
|
+
|
56
|
+
let(:sub_callback) do
|
57
|
+
class TmpSubClass < self.class
|
58
|
+
lambda { self }
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
let!(:all_callbacks) { subject << sub_callback }
|
63
|
+
|
64
|
+
it 'filters out subclass callbacks when given context/scope' do
|
65
|
+
expect(subject.callbacks(self).none? {|cb| cb.source_location == sub_callback.source_location }).to be_truthy
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
|
70
|
+
context 'execution' do
|
71
|
+
|
72
|
+
let!(:callback1) { subject.add { self }.last }
|
73
|
+
|
74
|
+
let!(:callback2) { subject.add { self.class }.last }
|
75
|
+
|
76
|
+
describe '#call' do
|
77
|
+
|
78
|
+
it 'will execute callbacks in the context which they where created' do
|
79
|
+
expect(subject.call()).to eql([self, self.class])
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
describe '#run' do
|
84
|
+
|
85
|
+
let!(:context) { (FakeContext = Class.new).new }
|
86
|
+
|
87
|
+
it 'will execute callbacks in the context which is passed in' do
|
88
|
+
expect(subject.run(context)).to eql([context, FakeContext])
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
describe '#default_body' do
|
94
|
+
|
95
|
+
it 'will return a Proc' do
|
96
|
+
expect(subject.default_body).to be_a(Proc)
|
97
|
+
end
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
describe '#bind' do
|
102
|
+
|
103
|
+
let!(:context) do
|
104
|
+
local = subject
|
105
|
+
Class.new do
|
106
|
+
extend Vigilem::Core::Hooks
|
107
|
+
local.bind(self)
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'will add hook as singleton_method' do
|
112
|
+
expect(context.respond_to?(:testr)).to be_truthy
|
113
|
+
end
|
114
|
+
|
115
|
+
describe '#owner' do
|
116
|
+
it 'wil be the value of context' do
|
117
|
+
expect(subject.owner).to eql(context)
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
describe '#generate' do
|
124
|
+
|
125
|
+
let!(:context) do
|
126
|
+
local = subject
|
127
|
+
Class.new do
|
128
|
+
extend Vigilem::Core::Hooks
|
129
|
+
local.generate(self)
|
130
|
+
end.new
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'will add hook as instance_method' do
|
134
|
+
expect(context.respond_to?(:testr)).to be_truthy
|
135
|
+
end
|
136
|
+
|
137
|
+
describe '#owner' do
|
138
|
+
it 'wil be the value of context' do
|
139
|
+
expect(subject.owner).to eql(context.class)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|
144
|
+
|
145
|
+
describe '#body' do
|
146
|
+
|
147
|
+
it 'will return default_proc when not set' do
|
148
|
+
expect(subject.send(:body)).to equal(subject.default_body)
|
149
|
+
end
|
150
|
+
|
151
|
+
let(:nw_body) { lambda { puts 'test' } }
|
152
|
+
|
153
|
+
it 'will return a block when given one' do
|
154
|
+
expect(subject.send(:body, &nw_body)).to eql(nw_body)
|
155
|
+
end
|
156
|
+
|
157
|
+
context 'generating' do
|
158
|
+
|
159
|
+
subject do
|
160
|
+
described_class.new(:bdy) do
|
161
|
+
body { 'test' }
|
162
|
+
end
|
163
|
+
end
|
164
|
+
|
165
|
+
let!(:context) do
|
166
|
+
local = subject
|
167
|
+
Class.new do
|
168
|
+
extend Vigilem::Core::Hooks
|
169
|
+
local.generate(self)
|
170
|
+
end.new
|
171
|
+
end
|
172
|
+
|
173
|
+
it 'will set the prco to be generated on the class' do
|
174
|
+
expect(context.bdy).to eql('test')
|
175
|
+
end
|
176
|
+
|
177
|
+
context 'binding' do
|
178
|
+
subject do
|
179
|
+
described_class.new(:bdy) do
|
180
|
+
body { 'test' }
|
181
|
+
end
|
182
|
+
end
|
183
|
+
|
184
|
+
let!(:context) do
|
185
|
+
local = subject
|
186
|
+
Class.new do
|
187
|
+
extend Vigilem::Core::Hooks
|
188
|
+
local.bind(self)
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'will set the proc to be binded on the class' do
|
193
|
+
expect(context.bdy).to eql('test')
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
describe '::enumerate' do
|
201
|
+
|
202
|
+
let(:call_backs) do
|
203
|
+
[ Vigilem::Core::Hooks::CallbackProc.new {|arg| self },
|
204
|
+
Vigilem::Core::Hooks::CallbackProc.new {|arg| self.class } ]
|
205
|
+
end
|
206
|
+
|
207
|
+
it 'will accept args with a list of callbacks and enumerate through them passing a long the args' do
|
208
|
+
expect(call_backs.first).to receive(:call).with('test').and_return('test')
|
209
|
+
expect(call_backs.last).to receive(:call).with('test').and_return(String)
|
210
|
+
described_class.send(:enumerate, call_backs, :args => 'test')
|
211
|
+
end
|
212
|
+
|
213
|
+
it 'will return the results' do
|
214
|
+
expect(described_class.send(:enumerate, call_backs, :args => 'test')).to eql([self, self.class])
|
215
|
+
end
|
216
|
+
|
217
|
+
it 'will accept a block and yield a meta_callback' do
|
218
|
+
expect {|b| described_class.send(:enumerate, call_backs, &b).to yield_with_args(MetaCallback) }
|
219
|
+
end
|
220
|
+
|
221
|
+
it 'will accept an arg of :context and evaluate the callbacks in that context' do
|
222
|
+
expect(call_backs.first).to receive(:evaluate).with(self, 'test').and_return(self)
|
223
|
+
expect(call_backs.last).to receive(:evaluate).with(self, 'test').and_return(String)
|
224
|
+
described_class.send(:enumerate, call_backs, :context => self, :args => 'test')
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
|
229
|
+
end
|
230
|
+
end
|