vigilem-core 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (61) hide show
  1. checksums.yaml +7 -0
  2. data/lib/vigilem/core.rb +9 -0
  3. data/lib/vigilem/core/abstract_device.rb +97 -0
  4. data/lib/vigilem/core/adapters.rb +2 -0
  5. data/lib/vigilem/core/adapters/adapter.rb +57 -0
  6. data/lib/vigilem/core/adapters/basic_adapter.rb +43 -0
  7. data/lib/vigilem/core/adapters/buffered_adapter.rb +28 -0
  8. data/lib/vigilem/core/buffer.rb +151 -0
  9. data/lib/vigilem/core/buffer_handler.rb +95 -0
  10. data/lib/vigilem/core/default_buffer.rb +45 -0
  11. data/lib/vigilem/core/demultiplexer.rb +225 -0
  12. data/lib/vigilem/core/device.rb +43 -0
  13. data/lib/vigilem/core/event_handler.rb +156 -0
  14. data/lib/vigilem/core/eventable.rb +80 -0
  15. data/lib/vigilem/core/hooks.rb +36 -0
  16. data/lib/vigilem/core/hooks/callback.rb +66 -0
  17. data/lib/vigilem/core/hooks/callback_proc.rb +25 -0
  18. data/lib/vigilem/core/hooks/conditional_hook.rb +62 -0
  19. data/lib/vigilem/core/hooks/hook.rb +193 -0
  20. data/lib/vigilem/core/hooks/inheritable.rb +24 -0
  21. data/lib/vigilem/core/hooks/meta_callback.rb +53 -0
  22. data/lib/vigilem/core/hooks/utils.rb +23 -0
  23. data/lib/vigilem/core/hub.rb +50 -0
  24. data/lib/vigilem/core/input_system_handler.rb +55 -0
  25. data/lib/vigilem/core/lockable_pipeline_component.rb +30 -0
  26. data/lib/vigilem/core/multiplexer.rb +168 -0
  27. data/lib/vigilem/core/pipeline.rb +68 -0
  28. data/lib/vigilem/core/stat.rb +121 -0
  29. data/lib/vigilem/core/system.rb +9 -0
  30. data/lib/vigilem/core/system/check.rb +33 -0
  31. data/lib/vigilem/core/transfer_agent.rb +67 -0
  32. data/lib/vigilem/core/version.rb +5 -0
  33. data/spec/bug_notes.txt +12 -0
  34. data/spec/given_helper.rb +12 -0
  35. data/spec/spec_helper.rb +7 -0
  36. data/spec/vigilem/core/abstract_device_spec.rb +103 -0
  37. data/spec/vigilem/core/adapters/adapter_spec.rb +28 -0
  38. data/spec/vigilem/core/adapters/basic_adapter_spec.rb +53 -0
  39. data/spec/vigilem/core/adapters/buffered_adapter_spec.rb +16 -0
  40. data/spec/vigilem/core/buffer_handler_spec.rb +51 -0
  41. data/spec/vigilem/core/buffer_spec.rb +236 -0
  42. data/spec/vigilem/core/default_buffer_spec.rb +17 -0
  43. data/spec/vigilem/core/demultiplexer_spec.rb +166 -0
  44. data/spec/vigilem/core/device_spec.rb +62 -0
  45. data/spec/vigilem/core/event_handler_spec.rb +134 -0
  46. data/spec/vigilem/core/hooks/callback_proc_spec.rb +66 -0
  47. data/spec/vigilem/core/hooks/hook_spec.rb +230 -0
  48. data/spec/vigilem/core/hooks/inheritable_spec.rb +19 -0
  49. data/spec/vigilem/core/hooks/meta_callback_spec.rb +69 -0
  50. data/spec/vigilem/core/hooks/utils_spec.rb +25 -0
  51. data/spec/vigilem/core/hooks_spec.rb +50 -0
  52. data/spec/vigilem/core/hub_spec.rb +51 -0
  53. data/spec/vigilem/core/input_system_handler_spec.rb +33 -0
  54. data/spec/vigilem/core/lockable_pipeline_component_spec.rb +19 -0
  55. data/spec/vigilem/core/multiplexer_spec.rb +113 -0
  56. data/spec/vigilem/core/pipeline_spec.rb +5 -0
  57. data/spec/vigilem/core/stat_spec.rb +63 -0
  58. data/spec/vigilem/core/system/check_spec.rb +24 -0
  59. data/spec/vigilem/core/system_spec.rb +29 -0
  60. data/spec/vigilem/core/transfer_agent_spec.rb +80 -0
  61. metadata +273 -0
@@ -0,0 +1,19 @@
1
+ require 'spec_helper'
2
+
3
+ require 'vigilem/core/hooks'
4
+
5
+ require 'vigilem/support/lazy_simple_delegator'
6
+
7
+ require 'vigilem/support/system'
8
+
9
+ require 'vigilem/core'
10
+
11
+ describe Vigilem::Core::Hooks::Inheritable do
12
+ subject { Vigilem::Core::Device }
13
+
14
+ context 'will inherit hooks' do
15
+ it 'will have at least one callback from AbstractDevice' do
16
+ expect(subject.hooks.find {|hook| hook.name == :after_init }.owner).to eql(Vigilem::Core::AbstractDevice)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,69 @@
1
+ require 'spec_helper'
2
+
3
+ require 'vigilem/core/hooks'
4
+
5
+ require 'vigilem/core/hooks/meta_callback'
6
+ describe Vigilem::Core::Hooks::MetaCallback do
7
+ subject do
8
+ described_class.new do
9
+ self
10
+ end
11
+ end
12
+
13
+ describe '#ran?' do
14
+ it 'will start false because nothing has ran' do
15
+ expect(subject.ran?).to be_falsey
16
+ end
17
+ end
18
+
19
+ context 'private' do
20
+ describe '#ran=' do
21
+ it 'sets ran' do
22
+ subject.send(:ran=, true)
23
+ expect(subject.ran?).to be_truthy
24
+ end
25
+ end
26
+ end
27
+
28
+ shared_examples 'evaluatable' do
29
+ before(:all) { Context = Class.new unless defined? :Context}
30
+
31
+ let(:instance) { Context.new }
32
+
33
+ let!(:result) { subject.send(method_name, instance) }
34
+
35
+ it 'flags ran? to true' do
36
+ expect(subject.ran?).to be_truthy
37
+ end
38
+
39
+ it 'runs callbackproc #evaluate' do
40
+ expect(result).to eql(instance)
41
+ end
42
+ end
43
+
44
+ describe '#evaluate' do
45
+
46
+ it_behaves_like 'evaluatable' do
47
+ let(:method_name) { :evaluate }
48
+ end
49
+ end
50
+
51
+ describe '#[]' do
52
+ it_behaves_like 'evaluatable' do
53
+ let(:method_name) { :[] }
54
+ end
55
+ end
56
+
57
+ describe '#call' do
58
+ When(:result) { subject.call }
59
+
60
+ it 'flags ran to true' do
61
+ expect(subject.ran?).to be_truthy
62
+ end
63
+
64
+ it 'will run like Proc' do
65
+ expect(result).to eql(self)
66
+ end
67
+ end
68
+
69
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ require 'vigilem/core/hooks/utils'
4
+
5
+ describe Vigilem::Core::Hooks::Utils do
6
+
7
+ before(:all) { TmpClass = Class.new }
8
+
9
+ # @todo test instances
10
+ describe '#callback_is_in_subclass?' do
11
+
12
+ before :all do
13
+ TempSubclass = Class.new(TmpClass) do
14
+ def self.callback
15
+ lambda { puts self }
16
+ end
17
+ end
18
+ end
19
+
20
+ it 'will determine whether the callback binding is a subclass of context' do
21
+ expect(described_class.callback_is_in_subclass?(TmpClass, TempSubclass.callback)).to be_truthy
22
+ end
23
+
24
+ end
25
+ end
@@ -0,0 +1,50 @@
1
+ require 'spec_helper'
2
+
3
+ require 'vigilem/core/hooks'
4
+
5
+ describe Vigilem::Core::Hooks do
6
+
7
+ it 'will have hooks as instance method' do
8
+ expect(described_class.method_defined?(:hooks)).to be_truthy
9
+ end
10
+
11
+ let!(:base) do
12
+ dc = described_class
13
+ Class.new do
14
+ extend dc
15
+ end
16
+ end
17
+
18
+ let(:callback) do
19
+ Class.new do
20
+ def name
21
+ :testr
22
+ end
23
+ def run
24
+ self
25
+ end
26
+ end
27
+ end
28
+
29
+ it 'will have class level run_hook method' do
30
+ expect(base).to respond_to(:run_hook)
31
+ end
32
+
33
+ it 'will have an instance level run_hooks' do
34
+ expect(base.method_defined?(:run_hook)).to be_truthy
35
+ end
36
+
37
+ it 'will have class level hooks' do
38
+ expect(base).to respond_to(:hooks)
39
+ end
40
+
41
+ let(:base_instance) { base.new }
42
+
43
+ let!(:hooks) { base.hooks << callback.new }
44
+
45
+ it 'will call run on every hook' do
46
+ expect(base.hooks.first).to receive(:run)
47
+ base_instance.run_hook :testr
48
+ end
49
+
50
+ end
@@ -0,0 +1,51 @@
1
+ require 'vigilem/core/hub'
2
+
3
+ describe Vigilem::Core::Hub do
4
+
5
+ subject { described_class.new([]) }
6
+
7
+ describe '#initialize' do
8
+ it 'will initialize the buffers' do
9
+ expect(subject.buffers).to_not be_nil
10
+ end
11
+ end
12
+
13
+ describe '#add_buffer' do
14
+ let(:buffer) { Object.new }
15
+
16
+ it 'will add to the buffers' do
17
+ subject.add_buffer(buffer)
18
+ expect(subject.buffers).to include(buffer)
19
+ end
20
+ end
21
+
22
+ describe '#<<' do
23
+ let(:buffer) { Object.new }
24
+
25
+ it 'will add to the buffers' do
26
+ subject << buffer
27
+ expect(subject.buffers).to include(buffer)
28
+ end
29
+ end
30
+
31
+ describe '#demux' do
32
+
33
+ let(:buffer) { [1,2,3] }
34
+
35
+ let(:buffer2) { %w(a b c) }
36
+
37
+ let!(:reg) do
38
+ subject.add_buffer(buffer)
39
+ subject.add_buffer(buffer2)
40
+ end
41
+
42
+ it 'returns buffers that get the new messages' do
43
+ expect(subject.demux(buffer2, 5)).to eql([buffer])
44
+ end
45
+
46
+ it 'updates the buffers except the link' do
47
+ subject.demux([], 5)
48
+ expect(buffer).to eql([1,2,3,5])
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,33 @@
1
+ require 'spec_helper'
2
+
3
+ require 'vigilem/core/input_system_handler'
4
+
5
+ describe Vigilem::Core::InputSystemHandler do
6
+
7
+ after(:each) do
8
+ (described_class.instance_variables).each do |ivar|
9
+ described_class.send(:remove_instance_variable, ivar)
10
+ end
11
+ end
12
+
13
+ class FakeHandler
14
+ include Vigilem::Core::InputSystemHandler
15
+ def initialize
16
+ initialize_input_system_handler
17
+ end
18
+ end
19
+
20
+ let(:handler) { FakeHandler.new }
21
+
22
+ describe '#initialize' do
23
+
24
+ it 'will initialize inbox/buffer' do
25
+ expect(handler.inbox).to_not be_nil
26
+ end
27
+
28
+ it 'will register the base class when initialized' do
29
+ expect(FakeHandler.all).to include handler
30
+ end
31
+ end
32
+
33
+ end
@@ -0,0 +1,19 @@
1
+ require 'vigilem/core/lockable_pipeline_component'
2
+
3
+ describe Vigilem::Core::LockablePipelineComponent do
4
+
5
+ class LPCHost
6
+ include Vigilem::Core::LockablePipelineComponent
7
+ end
8
+
9
+ subject { LPCHost.new }
10
+
11
+ describe '#semaphore' do
12
+ it 'pulls from #source if available' do
13
+ allow(subject).to receive(:source)
14
+ expect(subject).to receive(:source)
15
+ subject.semaphore
16
+ end
17
+ end
18
+
19
+ end
@@ -0,0 +1,113 @@
1
+ require 'spec_helper'
2
+
3
+ require 'tempfile'
4
+
5
+ require 'vigilem/support/core_ext'
6
+
7
+ require 'vigilem/core/multiplexer'
8
+
9
+ describe Vigilem::Core::Multiplexer do
10
+
11
+ before(:each) do
12
+ @out = Tempfile.new('out')
13
+ @ios = [Tempfile.new('foo'), Tempfile.new('bar'),
14
+ Tempfile.new('fizz'), Tempfile.new('buzz')]
15
+ end
16
+
17
+ class MultiplexerHost
18
+ include Vigilem::Core::Multiplexer
19
+ def initialize(inpts, out=nil)
20
+ initialize_multiplexer(inpts, out)
21
+ end
22
+
23
+ end
24
+
25
+ after(:each) do
26
+ @out.respond(:close)
27
+ @ios.each {|io| io.respond.close }
28
+ end
29
+
30
+ let(:out) { @out }
31
+
32
+ let(:io_objs) { @ios[0..1] }
33
+
34
+ describe '::initialize' do
35
+
36
+ it 'updates inputs array' do
37
+ expect(MultiplexerHost.new(io_objs.sample(2), out).inputs).to match [duck_type(:fileno)] * 2
38
+ end
39
+
40
+ end
41
+
42
+ context 'post init' do
43
+
44
+ let(:plex) { MultiplexerHost.new(@ios, out) }
45
+
46
+ describe '#ready?' do
47
+
48
+ context 'all ready' do
49
+
50
+ it 'returns the ready files' do
51
+ expect(plex.ready?).to match(@ios)
52
+ end
53
+ end
54
+ context 'some not ready' do
55
+ let(:rw) { IO.pipe }
56
+
57
+ let(:pipes) do
58
+ rw.last << 'ready'
59
+ [IO.pipe, *rw].flatten
60
+ end
61
+
62
+ let(:mplex) { MultiplexerHost.new(pipes) }
63
+
64
+ it 'returns the ready files' do
65
+ #expect(mplex.ready?).to eql([rw]) #hangs
66
+ expect(mplex.ready?.first).to eql(rw.first)
67
+ end
68
+ end
69
+
70
+ end
71
+
72
+ context 'private' do
73
+ describe '#recursive_check' do
74
+ it %q<checks to make sure an input on the multiplexer isn't the same as the output> do
75
+ a = []
76
+ plex.inputs << a
77
+ plex.output = a
78
+ expect do
79
+ plex.send(:recursive_check)
80
+ end.to raise_error(ArgumentError)
81
+ end
82
+ end
83
+ end
84
+
85
+ describe '::add_inputs' do
86
+ it %q<raises error if an input and matches the output> do
87
+ expect do
88
+ plex.add_inputs(plex.output)
89
+ end.to raise_error(ArgumentError)
90
+ end
91
+
92
+ it %q<runs a uniq! to prevent duplicate items in the inputs> do
93
+ ipt = plex.inputs.first
94
+ expect(plex.add_inputs(ipt).count(ipt)).to eql(1)
95
+ end
96
+ end
97
+
98
+ describe '#mux' do
99
+
100
+ before(:each) do
101
+ allow(plex).to receive(:sweep).with(3) { [1,2,3] }
102
+ end
103
+
104
+ it 'takes the return from sweep and adds it to #out' do
105
+ plex.mux(3)
106
+ expect((f = File.open(plex.out)).each_char.to_a).to eql(%w(1 2 3))
107
+ f.close
108
+ end
109
+
110
+ end
111
+
112
+ end
113
+ end
@@ -0,0 +1,5 @@
1
+ require 'vigilem/core/pipeline'
2
+
3
+ describe Vigilem::Core::Pipeline do
4
+
5
+ end
@@ -0,0 +1,63 @@
1
+ require 'vigilem/core/stat'
2
+
3
+ # @TODO cleanup commented out parts
4
+ describe Vigilem::Core::Stat do
5
+
6
+ context 'class level' do
7
+ describe 'initialize' do
8
+ it 'setup class level platform masks' do
9
+ arg = described_class.new('FakeInputSystem', 'fake_input_system_gem', :platforms => /.+/ )
10
+ expect(arg.platform_masks).to eql([/.+/])
11
+ end
12
+
13
+ it 'will have more granular proc check than just platforms' do
14
+ check = lambda { 'test' }
15
+ arg = described_class.new('FakeInputSystem', 'fake_input_system_gem', :platforms => /.+/, &check)
16
+ expect(arg.send :api_check).to eql(check)
17
+ end
18
+
19
+ describe '::api_check?' do
20
+ it 'will run the api check and "convert" the result to [TrueClass || FalseClass]' do
21
+ arg = described_class.new('FakeInputSystem', 'fake_input_system_gem', :platforms => /.+/) { 'test' }
22
+ expect(arg.api_check?).to be_truthy
23
+ end
24
+ end
25
+
26
+ describe '::available_on?' do
27
+ it 'will test the platforms set in new against a given String' do
28
+ arg = described_class.new('FakeInputSystem', 'fake_input_system_gem', :platforms => /darwin/)
29
+ expect(arg.available_on?('darwin')).to be_truthy
30
+ end
31
+ end
32
+ #alias_method :is_available_on?, :available_on?
33
+
34
+ describe '::available?' do
35
+ let(:check) { lambda { true } }
36
+
37
+ context 'platforms match' do
38
+
39
+ it 'will call check' do
40
+ arg = described_class.new('FakeInputSystem', 'fake_input_system_gem', :platforms => /.+/, &check)
41
+ expect(check).to receive(:call).and_return(true)
42
+ arg.available?
43
+ end
44
+
45
+ it 'available? will be true' do
46
+ arg = described_class.new('FakeInputSystem', 'fake_input_system_gem', :platforms => /.+/, &check)
47
+ expect(arg.available?).to be_truthy
48
+ end
49
+ end
50
+ context %q<platforms don't match> do
51
+
52
+ it '#available? will be false' do
53
+ arg = described_class.new('FakeInputSystem', 'fake_input_system_gem', :platforms => /1234/, &check)
54
+ expect(arg.available?).to be_falsey
55
+ end
56
+ end
57
+
58
+ end
59
+
60
+ end
61
+ end
62
+
63
+ end