vigilem-core 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- 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,16 @@
|
|
1
|
+
require 'vigilem/core/adapters/buffered_adapter'
|
2
|
+
|
3
|
+
describe Vigilem::Core::Adapters::BufferedAdapter do
|
4
|
+
|
5
|
+
it 'is a BufferHandler' do
|
6
|
+
expect(described_class).to be < Vigilem::Core::BufferHandler
|
7
|
+
end
|
8
|
+
|
9
|
+
describe '#initialize_buffered' do
|
10
|
+
it %q<init's a buffer_handler and adapter> do
|
11
|
+
pending('@todo test')
|
12
|
+
raise 'NotImplementedError'
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
require 'vigilem/core/buffer_handler'
|
2
|
+
|
3
|
+
# @TODO finish
|
4
|
+
describe Vigilem::Core::BufferHandler do
|
5
|
+
|
6
|
+
before :all do
|
7
|
+
FakeBHandler = Class.new do
|
8
|
+
include Vigilem::Core::BufferHandler
|
9
|
+
def initialize
|
10
|
+
initialize_buffer_handler
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
subject do
|
16
|
+
FakeBHandler.new
|
17
|
+
end
|
18
|
+
|
19
|
+
describe '#initialize_buffer_handler' do
|
20
|
+
|
21
|
+
it 'will initialize the default buffer' do
|
22
|
+
expect(subject.buffers[:default]).not_to be_nil
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '#buffer' do
|
27
|
+
it 'returns a buffer' do
|
28
|
+
expect(subject.buffer).not_to be_nil
|
29
|
+
#alias_method :inbox, :buffer
|
30
|
+
end
|
31
|
+
it 'assigns a new Buffer of type passed in' do
|
32
|
+
subject.buffers[:default] = nil
|
33
|
+
subject.buffer(:default, '')
|
34
|
+
expect(subject.buffer).to be == Vigilem::Core::DefaultBuffer.new('')
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#buffered' do
|
39
|
+
#@todo
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '#buffered!' do
|
43
|
+
#@todo
|
44
|
+
end
|
45
|
+
|
46
|
+
context 'private' do
|
47
|
+
describe '#buffer=' do
|
48
|
+
#alias_method :inbox=, :buffer=
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,236 @@
|
|
1
|
+
require 'vigilem/core/buffer'
|
2
|
+
|
3
|
+
require 'delegate'
|
4
|
+
|
5
|
+
describe Vigilem::Core::Buffer do
|
6
|
+
|
7
|
+
|
8
|
+
context 'private' do
|
9
|
+
|
10
|
+
before :all do
|
11
|
+
SuperCheck = Class.new(String) { include ::Vigilem::Core::Buffer }
|
12
|
+
end
|
13
|
+
|
14
|
+
before :all do
|
15
|
+
SuperDelegateCheck = Class.new(SimpleDelegator) { include ::Vigilem::Core::Buffer }
|
16
|
+
end
|
17
|
+
|
18
|
+
subject { SuperCheck.new('abcdef') }
|
19
|
+
|
20
|
+
describe '_super_check' do
|
21
|
+
it 'will call the superclass method if it exists' do
|
22
|
+
expect(subject.send(:_super_check, :slice, nil, 1,2)).to eql('bc')
|
23
|
+
end
|
24
|
+
|
25
|
+
it %Q(will call the otherwise block if the superclass doesn't have the method) do
|
26
|
+
expect(subject.send(:_super_check, :dice, nil, 1,2) { '$' }).to eql('$')
|
27
|
+
end
|
28
|
+
|
29
|
+
context 'delegate' do
|
30
|
+
subject do
|
31
|
+
SuperDelegateCheck.new(%Q(ces't cheese))
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'will call __getobj__ if the class responds to it' do
|
35
|
+
expect(subject.send(:_super_check, :slice, nil, 7,2)).to eql('he')
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
class StrBuffer
|
43
|
+
include ::Vigilem::Core::Buffer
|
44
|
+
|
45
|
+
def initialize(str=nil)
|
46
|
+
@str = str || 'I am rawrg!'
|
47
|
+
end
|
48
|
+
|
49
|
+
def _dump(level)
|
50
|
+
Marshal.dump(@ary)
|
51
|
+
end
|
52
|
+
|
53
|
+
def self._load(str)
|
54
|
+
self.new(*Marshal.load(str))
|
55
|
+
end
|
56
|
+
|
57
|
+
def slice!(*args)
|
58
|
+
self.class.new(*@str.slice!(*args))
|
59
|
+
end
|
60
|
+
|
61
|
+
def concat(other_str)
|
62
|
+
self.class.new(*@str.concat(other_str))
|
63
|
+
end
|
64
|
+
|
65
|
+
def ==(other_obj)
|
66
|
+
@str == other_obj.instance_variable_get(:@str)
|
67
|
+
end
|
68
|
+
|
69
|
+
def length
|
70
|
+
@str.length
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
class AryBuffer
|
75
|
+
include ::Vigilem::Core::Buffer
|
76
|
+
|
77
|
+
def initialize(*ary)
|
78
|
+
@ary = if ary.empty? then %w(a b c d) else ary end
|
79
|
+
end
|
80
|
+
|
81
|
+
def _dump(level)
|
82
|
+
Marshal.dump(@ary)
|
83
|
+
end
|
84
|
+
|
85
|
+
def self._load(str)
|
86
|
+
self.new(*Marshal.load(str))
|
87
|
+
end
|
88
|
+
|
89
|
+
def slice!(*args)
|
90
|
+
self.class.new(*@ary.slice!(*args))
|
91
|
+
end
|
92
|
+
|
93
|
+
def concat(other_str)
|
94
|
+
self.class.new(*@ary.concat(other_str))
|
95
|
+
end
|
96
|
+
|
97
|
+
def ==(other_obj)
|
98
|
+
@ary == other_obj.instance_variable_get(:@ary)
|
99
|
+
end
|
100
|
+
|
101
|
+
def length
|
102
|
+
@ary.length
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
class FailBuffer
|
107
|
+
include ::Vigilem::Core::Buffer
|
108
|
+
def _dump(level)
|
109
|
+
Marshal.dump(@ary)
|
110
|
+
end
|
111
|
+
|
112
|
+
def self._load(str)
|
113
|
+
self.new(*Marshal.dump(str))
|
114
|
+
end
|
115
|
+
|
116
|
+
def initialize
|
117
|
+
@str = %w(a b c d)
|
118
|
+
end
|
119
|
+
|
120
|
+
def concat(other_str)
|
121
|
+
@str.concat(other_str)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
describe '#offset!' do
|
126
|
+
context 'will slice! from the @input_buffer and return the remainder' do
|
127
|
+
|
128
|
+
context StrBuffer do
|
129
|
+
it 'buffer > len' do
|
130
|
+
expect(subject.offset!(4)).to be == [described_class.new('I am'), 0]
|
131
|
+
end
|
132
|
+
it 'buffer < len' do
|
133
|
+
expect(subject.offset!(13)).to be == [described_class.new('I am rawrg!'), 2]
|
134
|
+
end
|
135
|
+
end
|
136
|
+
context AryBuffer do
|
137
|
+
it 'buffer > len' do
|
138
|
+
expect(subject.offset!(3)).to be == [described_class.new('a', 'b', 'c'), 0]
|
139
|
+
end
|
140
|
+
|
141
|
+
it 'buffer < len' do
|
142
|
+
expect(subject.offset!(9)).to be == [described_class.new('a', 'b', 'c', 'd'), 5]
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
shared_examples 'modifier!' do
|
150
|
+
before(:all) { @buffer = described_class.new }
|
151
|
+
|
152
|
+
let(:result) { @buffer.send(method_name, *args) }
|
153
|
+
|
154
|
+
it 'return a subset of the original' do
|
155
|
+
expect(result).to be == described_class.new(*result_match)
|
156
|
+
end
|
157
|
+
|
158
|
+
it 'will modify the original buffer' do
|
159
|
+
expect(@buffer).to be == described_class.new(*buffer_state)
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
shared_examples 'modifier' do
|
164
|
+
before(:all) { @buffer = described_class.new }
|
165
|
+
|
166
|
+
let(:result) { @buffer.send(method_name, *args) }
|
167
|
+
|
168
|
+
it 'return a subset of the original' do
|
169
|
+
expect(result).to be == described_class.new(*result_match)
|
170
|
+
end
|
171
|
+
|
172
|
+
it 'will not effect the original buffer' do
|
173
|
+
expect(@buffer).to be == described_class.new(*buffer_state)
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
describe '#slice' do
|
178
|
+
context AryBuffer do
|
179
|
+
it_behaves_like 'modifier' do
|
180
|
+
let(:method_name) { :slice }
|
181
|
+
let(:args) { [1, 2] }
|
182
|
+
let(:result_match) { %w(b c) }
|
183
|
+
let(:buffer_state) { %w(a b c d) }
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
context StrBuffer do
|
188
|
+
it_behaves_like 'modifier' do
|
189
|
+
let(:method_name) { :slice }
|
190
|
+
let(:args) { [1, 2] }
|
191
|
+
let(:result_match) { ' a' }
|
192
|
+
let(:buffer_state) { 'I am rawrg!' }
|
193
|
+
end
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
describe '#slice!' do
|
198
|
+
context AryBuffer do
|
199
|
+
it_behaves_like 'modifier!' do
|
200
|
+
let(:method_name) { :slice! }
|
201
|
+
let(:args) { [1, 2] }
|
202
|
+
let(:result_match) { %w(b c) }
|
203
|
+
let(:buffer_state) { %w(a d) }
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
context StrBuffer do
|
208
|
+
it_behaves_like 'modifier!' do
|
209
|
+
let(:method_name) { :slice! }
|
210
|
+
let(:args) { [1, 2] }
|
211
|
+
let(:result_match) { ' a' }
|
212
|
+
let(:buffer_state) { 'Im rawrg!' }
|
213
|
+
end
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
describe 'concat' do
|
218
|
+
context AryBuffer do
|
219
|
+
it_behaves_like 'modifier!' do
|
220
|
+
let(:method_name) { :concat }
|
221
|
+
let(:args) { [[1]] }
|
222
|
+
let(:result_match) { %w(a b c d) + [1] }
|
223
|
+
let(:buffer_state) { %w(a b c d) + [1] }
|
224
|
+
end
|
225
|
+
end
|
226
|
+
|
227
|
+
context StrBuffer do
|
228
|
+
it_behaves_like 'modifier!' do
|
229
|
+
let(:method_name) { :concat }
|
230
|
+
let(:args) { 'E>' }
|
231
|
+
let(:result_match) { 'I am rawrg!E>' }
|
232
|
+
let(:buffer_state) { 'I am rawrg!E>' }
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
236
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'vigilem/core/default_buffer'
|
2
|
+
|
3
|
+
describe Vigilem::Core::DefaultBuffer do
|
4
|
+
context 'declared type' do
|
5
|
+
describe '::wrap' do
|
6
|
+
it 'becomes the type passed in' do
|
7
|
+
expect(described_class.wrap('').__getobj__).to be_a(String)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'default type ([])' do
|
13
|
+
it 'defaults the type to an array' do
|
14
|
+
expect(described_class.new.__getobj__).to be_an(Array)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,166 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
require 'tempfile'
|
4
|
+
|
5
|
+
require 'vigilem/core/demultiplexer'
|
6
|
+
|
7
|
+
describe Vigilem::Core::Demultiplexer do
|
8
|
+
|
9
|
+
after(:each) do
|
10
|
+
(described_class.instance_variables).each do |ivar|
|
11
|
+
described_class.send(:remove_instance_variable, ivar)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class OutEvent < Struct.new(:metadata, :type); end
|
16
|
+
|
17
|
+
let(:outputs) { [[[], {:func => :concat}], [[], {:func => :concat}], [[], {:func => :concat}]] }
|
18
|
+
|
19
|
+
let(:input) { [] }
|
20
|
+
|
21
|
+
let(:device_one) do
|
22
|
+
t = Tempfile.new('dev')
|
23
|
+
def t.name
|
24
|
+
'at keyboard'
|
25
|
+
end
|
26
|
+
t
|
27
|
+
end
|
28
|
+
|
29
|
+
let(:device_two) do
|
30
|
+
t = Tempfile.new('dev2')
|
31
|
+
def t.name
|
32
|
+
'wheel mouse'
|
33
|
+
end
|
34
|
+
t
|
35
|
+
end
|
36
|
+
|
37
|
+
let(:devices) { [device_one, device_two] }
|
38
|
+
|
39
|
+
let(:events) do
|
40
|
+
[
|
41
|
+
OutEvent.new({:source => devices.first}),
|
42
|
+
OutEvent.new({:source => devices.last}),
|
43
|
+
OutEvent.new({}, 1),
|
44
|
+
OutEvent.new({}, 2)
|
45
|
+
]
|
46
|
+
end
|
47
|
+
|
48
|
+
context 'class-level' do
|
49
|
+
|
50
|
+
describe '#option_names' do
|
51
|
+
it 'returns a list of options for this observer' do
|
52
|
+
expect(described_class.option_names).to all(be_a(Symbol))
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe '#event_option_names' do
|
57
|
+
it 'returns the event option Symbols' do
|
58
|
+
good_opt = described_class.event_option_names
|
59
|
+
expect(described_class.event_option_names).to all(be_a(Symbol)) and not include(:func)
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '::all' do
|
64
|
+
it 'defaults to []' do
|
65
|
+
expect(described_class.all).to be_empty
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
describe '::filter_events' do
|
70
|
+
|
71
|
+
it 'filters events if the device is the same as an event source' do
|
72
|
+
expect(described_class.filter_events(events, {:device => device_one })).to eql(events.take(1))
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'filters events if a device is the same as an event source' do
|
76
|
+
expect(described_class.filter_events(events, {:devices => devices })).to eql(events.take(2))
|
77
|
+
end
|
78
|
+
|
79
|
+
it 'filters events if the Regexp matches an event source name' do
|
80
|
+
expect(described_class.filter_events(events, {:device_name => /keyboard/ })).to eql(events.take(1))
|
81
|
+
end
|
82
|
+
|
83
|
+
it 'filters events if a Regexp matches an event source name' do
|
84
|
+
expect(described_class.filter_events(events, {:device_names => [/keyboard/, /mouse/] })).to eql(events.take(2))
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'filters events if the type is the same as an event type' do
|
88
|
+
expect(described_class.filter_events(events, {:type => 1 })).to eql([events[2]])
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'filters events if a type is the same as an event type' do
|
92
|
+
expect(described_class.filter_events(events, {:types => [1, 2] })).to eql(events[2,2])
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
describe '#filter_events' do
|
99
|
+
it 'calls the clas level filter events' do
|
100
|
+
allow(described_class).to receive(:filter_events)
|
101
|
+
expect(described_class).to receive(:filter_events)
|
102
|
+
subject.filter_events([], {})
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
describe '#outputs' do
|
107
|
+
it 'starts empty' do
|
108
|
+
expect(subject.outputs).to be_empty
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe '#input' do
|
113
|
+
it 'starts empty' do
|
114
|
+
expect(subject.input).to be_nil
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
118
|
+
describe '#add_observer' do
|
119
|
+
|
120
|
+
it 'returns the opts args passed in (like Observerable)' do
|
121
|
+
expect(subject.add_observer(*outputs.first)).to eql(outputs.first.last)
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'adds to #ouputs' do
|
125
|
+
subject.add_observer(*outputs.first)
|
126
|
+
expect(subject.outputs).to be == outputs.first.take(1)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe '#initialize' do
|
131
|
+
|
132
|
+
subject { described_class.new(input, outputs) }
|
133
|
+
|
134
|
+
it 'sets #outputs' do
|
135
|
+
expect(subject.outputs).to eql(outputs.map(&:first))
|
136
|
+
end
|
137
|
+
|
138
|
+
it 'sets #input' do
|
139
|
+
expect(subject.input).to eql(input)
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'adds it to #all' do
|
143
|
+
expect(described_class.all).to eql([subject])
|
144
|
+
end
|
145
|
+
|
146
|
+
end
|
147
|
+
|
148
|
+
describe '#notify_observers' do
|
149
|
+
it 'pushes passed in events to observers' do
|
150
|
+
arg = described_class.new(input, outputs)
|
151
|
+
arg.changed
|
152
|
+
arg.notify_observers(*events)
|
153
|
+
expect(outputs.flat_map(&:first)).not_to be_empty
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
describe '#demux' do
|
158
|
+
it 'pulls from the input and pushes to the correct observers' do
|
159
|
+
arg = described_class.new(input, outputs)
|
160
|
+
(arg.input ||= []) << events.first
|
161
|
+
arg.demux
|
162
|
+
expect(outputs.flat_map(&:first)).to all(be_a(OutEvent))
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|