vedeu 0.6.61 → 0.6.62

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/benchmarks/array_vs_range.rb +1 -1
  3. data/docs/events/drb.md +2 -2
  4. data/docs/events/visibility.md +1 -1
  5. data/lib/vedeu/buffers/all.rb +1 -0
  6. data/lib/vedeu/buffers/empty.rb +2 -2
  7. data/lib/vedeu/{terminal/buffer.rb → buffers/terminal.rb} +12 -16
  8. data/lib/vedeu/cursors/cursor.rb +4 -8
  9. data/lib/vedeu/cursors/refresh.rb +5 -0
  10. data/lib/vedeu/editor/all.rb +1 -0
  11. data/lib/vedeu/editor/collection.rb +26 -0
  12. data/lib/vedeu/editor/document.rb +0 -8
  13. data/lib/vedeu/editor/line.rb +17 -47
  14. data/lib/vedeu/editor/lines.rb +22 -51
  15. data/lib/vedeu/geometries/geometry.rb +0 -6
  16. data/lib/vedeu/groups/group.rb +0 -6
  17. data/lib/vedeu/input/capture.rb +1 -1
  18. data/lib/vedeu/interfaces/clear.rb +1 -1
  19. data/lib/vedeu/logging/log.rb +5 -2
  20. data/lib/vedeu/models/focus.rb +4 -13
  21. data/lib/vedeu/output/compressor.rb +8 -4
  22. data/lib/vedeu/output/output.rb +3 -3
  23. data/lib/vedeu/output/renderers/all.rb +2 -2
  24. data/lib/vedeu/output/renderers/html.rb +1 -1
  25. data/lib/vedeu/output/renderers/json.rb +1 -1
  26. data/lib/vedeu/repositories/all.rb +1 -0
  27. data/lib/vedeu/repositories/assemblage.rb +57 -0
  28. data/lib/vedeu/repositories/collection.rb +1 -40
  29. data/lib/vedeu/repositories/model.rb +17 -0
  30. data/lib/vedeu/runtime/launcher.rb +5 -8
  31. data/lib/vedeu/terminal/all.rb +0 -1
  32. data/lib/vedeu/version.rb +1 -1
  33. data/test/lib/vedeu/{terminal/buffer_test.rb → buffers/terminal_test.rb} +24 -50
  34. data/test/lib/vedeu/cursors/cursor_test.rb +0 -6
  35. data/test/lib/vedeu/editor/collection_test.rb +38 -0
  36. data/test/lib/vedeu/editor/document_test.rb +0 -16
  37. data/test/lib/vedeu/editor/line_test.rb +17 -75
  38. data/test/lib/vedeu/editor/lines_test.rb +21 -88
  39. data/test/lib/vedeu/geometries/geometry_test.rb +0 -6
  40. data/test/lib/vedeu/groups/group_test.rb +0 -6
  41. data/test/lib/vedeu/input/mouse_test.rb +1 -1
  42. data/test/lib/vedeu/logging/log_test.rb +3 -3
  43. data/test/lib/vedeu/models/focus_test.rb +62 -56
  44. data/test/lib/vedeu/output/output_test.rb +2 -2
  45. data/test/lib/vedeu/output/renderers/html_test.rb +2 -2
  46. data/test/lib/vedeu/output/renderers/json_test.rb +1 -1
  47. data/test/lib/vedeu/repositories/assemblage_test.rb +96 -0
  48. data/test/lib/vedeu/repositories/collection_test.rb +0 -54
  49. data/test/lib/vedeu/repositories/model_test.rb +15 -0
  50. data/vedeu.gemspec +1 -1
  51. metadata +13 -7
@@ -2,7 +2,7 @@ module Vedeu
2
2
 
3
3
  module Renderers
4
4
 
5
- # Renders a {Vedeu::Terminal::Buffer} as a HTML snippet; a table
5
+ # Renders a {Vedeu::Buffers::Terminal} as a HTML snippet; a table
6
6
  # by default.
7
7
  #
8
8
  class HTML < Vedeu::Renderers::File
@@ -2,7 +2,7 @@ module Vedeu
2
2
 
3
3
  module Renderers
4
4
 
5
- # Renders a {Vedeu::Terminal::Buffer} as JSON.
5
+ # Renders a {Vedeu::Buffers::Terminal} as JSON.
6
6
  #
7
7
  class JSON < Vedeu::Renderers::File
8
8
 
@@ -8,6 +8,7 @@ module Vedeu
8
8
 
9
9
  end # Vedeu
10
10
 
11
+ require 'vedeu/repositories/assemblage'
11
12
  require 'vedeu/repositories/collection'
12
13
  require 'vedeu/repositories/defaults'
13
14
  require 'vedeu/repositories/repositories'
@@ -0,0 +1,57 @@
1
+ module Vedeu
2
+
3
+ module Repositories
4
+
5
+ # Provides collection related query/command methods.
6
+ #
7
+ # @api private
8
+ #
9
+ module Assemblage
10
+
11
+ include Enumerable
12
+
13
+ # Return an individual element or collection of elements (if
14
+ # the given index is a Range).
15
+ #
16
+ # @param index [Fixnum|Range]
17
+ # @return [void]
18
+ def [](index)
19
+ collection[index]
20
+ end
21
+
22
+ # Provides iteration over the collection.
23
+ #
24
+ # @param block [Proc]
25
+ # @return [Enumerator]
26
+ def each(&block)
27
+ collection.each(&block)
28
+ end
29
+
30
+ # Returns a boolean indicating whether the collection is empty.
31
+ #
32
+ # @return [Boolean]
33
+ def empty?
34
+ collection.empty?
35
+ end
36
+
37
+ # An object is equal when its values are the same.
38
+ #
39
+ # @param other [void]
40
+ # @return [Boolean]
41
+ def eql?(other)
42
+ self.class == other.class && collection == other.collection
43
+ end
44
+ alias_method :==, :eql?
45
+
46
+ # Return the size of the collection.
47
+ #
48
+ # @return [Fixnum]
49
+ def size
50
+ collection.size
51
+ end
52
+
53
+ end # Collection
54
+
55
+ end # Repositories
56
+
57
+ end # Vedeu
@@ -9,7 +9,7 @@ module Vedeu
9
9
  #
10
10
  class Collection
11
11
 
12
- include Enumerable
12
+ include Vedeu::Repositories::Assemblage
13
13
 
14
14
  # @!attribute [r] collection
15
15
  # @return [Array|Vedeu::Repositories::Collection]
@@ -50,14 +50,6 @@ module Vedeu
50
50
  @name = name
51
51
  end
52
52
 
53
- # Fetch an entry from the collection via index.
54
- #
55
- # @param value [Fixnum]
56
- # @return [void]
57
- def [](value)
58
- collection[value]
59
- end
60
-
61
53
  # Adds an entry to the collection.
62
54
  #
63
55
  # @param other [Vedeu::Repositories::Collection]
@@ -73,37 +65,6 @@ module Vedeu
73
65
  end
74
66
  alias_method :<<, :add
75
67
 
76
- # Provides iteration over the collection.
77
- #
78
- # @param block [Proc]
79
- # @return [Enumerator]
80
- def each(&block)
81
- collection.each(&block)
82
- end
83
-
84
- # Returns a boolean indicating whether the collection is empty.
85
- #
86
- # @return [Boolean]
87
- def empty?
88
- collection.empty?
89
- end
90
-
91
- # An object is equal when its values are the same.
92
- #
93
- # @param other [Vedeu::Repositories::Collection]
94
- # @return [Boolean]
95
- def eql?(other)
96
- self.class == other.class && collection == other.collection
97
- end
98
- alias_method :==, :eql?
99
-
100
- # Returns the size of the collection.
101
- #
102
- # @return [Fixnum]
103
- def size
104
- collection.size
105
- end
106
-
107
68
  # Returns the collection as a String.
108
69
  #
109
70
  # @return [String]
@@ -64,6 +64,23 @@ module Vedeu
64
64
  @repository = klass
65
65
  end
66
66
 
67
+ # Create and store a model with the given attributes.
68
+ #
69
+ # @param attributes [Hash] A collection of attributes specific
70
+ # to the model.
71
+ # @param block [Proc] A block of code to be executing whilst
72
+ # storing.
73
+ # @return [Object] An instance of the model.
74
+ def store(attributes = {}, &block)
75
+ if block_given?
76
+ new(attributes).store(&block)
77
+
78
+ else
79
+ new(attributes).store
80
+
81
+ end
82
+ end
83
+
67
84
  private
68
85
 
69
86
  # The default values for a new instance of this class.
@@ -60,14 +60,16 @@ module Vedeu
60
60
  $stdout = @stdout
61
61
  $stderr = @stderr
62
62
 
63
- optionally_profile { Vedeu::Runtime::Application.start(configuration) }
63
+ optionally_profile do
64
+ Vedeu::Runtime::Application.start(Vedeu::Configuration)
65
+ end
64
66
 
65
67
  @exit_code = 0
66
68
 
67
69
  terminate!
68
70
 
69
71
  rescue StandardError => uncaught_exception
70
- output = if configuration.debug?
72
+ output = if Vedeu::Configuration.debug?
71
73
  uncaught_exception.message + "\n" +
72
74
  uncaught_exception.backtrace.join("\n".freeze)
73
75
  else
@@ -88,7 +90,7 @@ module Vedeu
88
90
 
89
91
  # @return [void]
90
92
  def optionally_profile
91
- if configuration.profile?
93
+ if Vedeu::Configuration.profile?
92
94
  Vedeu.profile { yield }
93
95
 
94
96
  else
@@ -113,11 +115,6 @@ module Vedeu
113
115
  end
114
116
  # :nocov:
115
117
 
116
- # @return [Vedeu::Configuration]
117
- def configuration
118
- Vedeu::Configuration
119
- end
120
-
121
118
  end # Launcher
122
119
 
123
120
  end # Vedeu
@@ -11,4 +11,3 @@ end # Vedeu
11
11
 
12
12
  require 'vedeu/terminal/mode'
13
13
  require 'vedeu/terminal/terminal'
14
- require 'vedeu/terminal/buffer'
data/lib/vedeu/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Vedeu
2
2
 
3
3
  # The current version of Vedeu.
4
- VERSION = '0.6.61'.freeze
4
+ VERSION = '0.6.62'.freeze
5
5
 
6
6
  end
@@ -8,71 +8,45 @@ module Vedeu
8
8
  it { Vedeu.bound?(:_drb_store_output_).must_equal(true) }
9
9
  end
10
10
 
11
- module Terminal
11
+ module Buffers
12
12
 
13
- describe Buffer do
13
+ describe Terminal do
14
14
 
15
- let(:described) { Vedeu::Terminal::Buffer }
15
+ let(:described) { Vedeu::Buffers::Terminal }
16
16
  let(:height) { 2 }
17
17
  let(:width) { 3 }
18
18
 
19
19
  before do
20
- Vedeu.stubs(:ready?).returns(true)
21
20
  Vedeu.stubs(:height).returns(height)
22
21
  Vedeu.stubs(:width).returns(width)
23
- Vedeu::Terminal::Buffer.reset!
22
+ Vedeu::Buffers::Terminal.reset!
24
23
  end
25
24
 
26
25
  describe '#clear' do
27
- let(:ready) { false }
28
-
29
- before do
30
- Vedeu.stubs(:ready?).returns(ready)
31
- Vedeu.renderers.stubs(:clear)
32
- end
33
-
34
26
  subject { described.clear }
35
27
 
36
- context 'when Vedeu is ready' do
37
- let(:ready) { true }
38
-
39
- it {
40
- Vedeu.renderers.expects(:clear)
41
- subject
42
- }
43
- end
44
-
45
- context 'when Vedeu is not ready' do
46
- # @todo Add more tests.
47
- end
28
+ it {
29
+ Vedeu.renderers.expects(:clear)
30
+ subject
31
+ }
48
32
  end
49
33
 
50
34
  describe '#output' do
51
- # @todo Add more tests.
35
+ subject { described.output }
36
+
37
+ it {
38
+ Vedeu::Models::Page.expects(:coerce)
39
+ subject
40
+ }
52
41
  end
53
42
 
54
43
  describe '#refresh' do
55
- let(:ready) { false }
56
-
57
- before do
58
- Vedeu.stubs(:ready?).returns(ready)
59
- Vedeu.renderers.stubs(:render)
60
- end
61
-
62
44
  subject { described.refresh }
63
45
 
64
- context 'when Vedeu is not ready' do
65
- it { subject.must_equal(nil) }
66
- end
67
-
68
- context 'when Vedeu is ready' do
69
- let(:ready) { true }
70
-
71
- it {
72
- Vedeu.renderers.expects(:render)
73
- subject
74
- }
75
- end
46
+ it {
47
+ Vedeu.renderers.expects(:render)
48
+ subject
49
+ }
76
50
  end
77
51
 
78
52
  describe '#reset!' do
@@ -81,18 +55,20 @@ module Vedeu
81
55
  it { subject.must_be_instance_of(Vedeu::Buffers::View) }
82
56
  end
83
57
 
84
- describe '#write' do
58
+ describe '#update' do
85
59
  let(:_value) {}
86
60
 
87
- subject { described.write(_value) }
61
+ subject { described.update(_value) }
88
62
 
89
63
  # @todo Add more tests.
90
64
  end
91
65
 
92
- describe '#update' do
66
+ describe '#write' do
93
67
  let(:_value) {}
94
68
 
95
- subject { described.update(_value) }
69
+ before { Vedeu.renderers.stubs(:render) }
70
+
71
+ subject { described.write(_value) }
96
72
 
97
73
  # @todo Add more tests.
98
74
  end
@@ -101,6 +77,4 @@ module Vedeu
101
77
 
102
78
  end # Terminal
103
79
 
104
-
105
-
106
80
  end # Vedeu
@@ -87,12 +87,6 @@ module Vedeu
87
87
  }
88
88
  end
89
89
 
90
- describe '.store' do
91
- subject { described.store(attributes) }
92
-
93
- it { subject.must_equal(instance) }
94
- end
95
-
96
90
  describe '#eql?' do
97
91
  let(:other) { instance }
98
92
 
@@ -0,0 +1,38 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ module Editor
6
+
7
+ class CollectionTestClass
8
+
9
+ include Enumerable
10
+ include Vedeu::Editor::Collection
11
+
12
+ attr_accessor :collection
13
+
14
+ def initialize(collection)
15
+ @collection = collection
16
+ end
17
+
18
+ end # CollectionTestClass
19
+
20
+ describe Collection do
21
+
22
+ let(:described) { Vedeu::Editor::Collection }
23
+ let(:instance) { Vedeu::Editor::CollectionTestClass.new(collection) }
24
+ let(:collection) { 'Some text...'.chars }
25
+
26
+ describe '#by_index' do
27
+ let(:index) { 0 }
28
+
29
+ subject { instance.by_index(index) }
30
+
31
+ it { subject.must_be_instance_of(String) }
32
+ end
33
+
34
+ end # Collection
35
+
36
+ end # Editor
37
+
38
+ end # Vedeu
@@ -49,22 +49,6 @@ module Vedeu
49
49
  }
50
50
  end
51
51
 
52
- describe '.store' do
53
- before { Vedeu.documents.reset! }
54
-
55
- subject { described.store(attributes) }
56
-
57
- it { subject.must_be_instance_of(described) }
58
-
59
- it 'registers the instance with the repository' do
60
- Vedeu.documents.registered?(_name).must_equal(false)
61
-
62
- subject
63
-
64
- Vedeu.documents.registered?(_name).must_equal(true)
65
- end
66
- end
67
-
68
52
  describe 'accessors' do
69
53
  it {
70
54
  instance.must_respond_to(:attributes)
@@ -6,24 +6,24 @@ module Vedeu
6
6
 
7
7
  describe Line do
8
8
 
9
- let(:described) { Vedeu::Editor::Line }
10
- let(:instance) { described.new(line) }
11
- let(:line) { 'Some text...' }
9
+ let(:described) { Vedeu::Editor::Line }
10
+ let(:instance) { described.new(collection) }
11
+ let(:collection) { 'Some text...' }
12
12
 
13
13
  describe '#initialize' do
14
14
  it { instance.must_be_instance_of(described) }
15
- it { instance.instance_variable_get('@line').must_equal(line) }
15
+ it { instance.instance_variable_get('@collection').must_equal(collection) }
16
16
 
17
17
  context 'when a line is not given' do
18
- let(:line) {}
18
+ let(:collection) {}
19
19
 
20
- it { instance.instance_variable_get('@line').must_equal('') }
20
+ it { instance.instance_variable_get('@collection').must_equal('') }
21
21
  end
22
22
  end
23
23
 
24
24
  describe 'accessors' do
25
- it { instance.must_respond_to(:line) }
26
- it { instance.must_respond_to(:line=) }
25
+ it { instance.must_respond_to(:collection) }
26
+ it { instance.must_respond_to(:collection=) }
27
27
  end
28
28
 
29
29
  describe '.coerce' do
@@ -34,38 +34,22 @@ module Vedeu
34
34
  it { subject.must_be_instance_of(Vedeu::Editor::Line) }
35
35
 
36
36
  context 'when the value is already a Vedeu::Editor::Line object' do
37
- let(:_value) { Vedeu::Editor::Line.new(line) }
37
+ let(:_value) { Vedeu::Editor::Line.new(collection) }
38
38
 
39
39
  it { subject.must_equal(_value) }
40
- it { subject.line.must_equal(line) }
40
+ it { subject.collection.must_equal(collection) }
41
41
  end
42
42
 
43
43
  context 'when the value is an empty String' do
44
44
  let(:_value) { '' }
45
45
 
46
- it { subject.line.must_equal('') }
46
+ it { subject.collection.must_equal('') }
47
47
  end
48
48
 
49
49
  context 'when the value is an String' do
50
- let(:_value) { line }
51
-
52
- it { subject.line.must_equal(line) }
53
- end
54
- end
55
-
56
- describe '#[]' do
57
- subject { instance.[](index) }
58
-
59
- context 'when index is a Fixnum' do
60
- let(:index) { 2 }
61
-
62
- it { subject.must_equal('m') }
63
- end
64
-
65
- context 'when index is a Range' do
66
- let(:index) { (3..6) }
50
+ let(:_value) { collection }
67
51
 
68
- it { subject.must_equal('e te') }
52
+ it { subject.collection.must_equal(collection) }
69
53
  end
70
54
  end
71
55
 
@@ -77,7 +61,7 @@ module Vedeu
77
61
  it { subject.must_be_instance_of(String) }
78
62
 
79
63
  context 'when the line is empty' do
80
- let(:line) { '' }
64
+ let(:collection) { '' }
81
65
 
82
66
  context 'and an index is not given' do
83
67
  let(:index) {}
@@ -125,7 +109,7 @@ module Vedeu
125
109
  it { subject.must_be_instance_of(Vedeu::Editor::Line) }
126
110
 
127
111
  context 'when the line is empty' do
128
- let(:line) { '' }
112
+ let(:collection) { '' }
129
113
 
130
114
  it { subject.line.must_equal('') }
131
115
 
@@ -167,34 +151,6 @@ module Vedeu
167
151
  end
168
152
  end
169
153
 
170
- describe '#empty?' do
171
- subject { instance.empty? }
172
-
173
- context 'when the line is empty' do
174
- let(:line) {}
175
-
176
- it { subject.must_equal(true) }
177
- end
178
-
179
- context 'when the line is not empty' do
180
- it { subject.must_equal(false) }
181
- end
182
- end
183
-
184
- describe '#eql?' do
185
- let(:other) { instance }
186
-
187
- subject { instance.eql?(other) }
188
-
189
- it { subject.must_equal(true) }
190
-
191
- context 'when different to other' do
192
- let(:other) { described.new('Other text...') }
193
-
194
- it { subject.must_equal(false) }
195
- end
196
- end
197
-
198
154
  describe '#insert_character' do
199
155
  let(:character) { 'a' }
200
156
  let(:index) { 5 }
@@ -204,7 +160,7 @@ module Vedeu
204
160
  it { subject.must_be_instance_of(Vedeu::Editor::Line) }
205
161
 
206
162
  context 'when the line is empty' do
207
- let(:line) {}
163
+ let(:collection) {}
208
164
 
209
165
  it { subject.line.must_equal('a') }
210
166
 
@@ -268,25 +224,11 @@ module Vedeu
268
224
  end
269
225
  end
270
226
 
271
- describe '#size' do
272
- subject { instance.size }
273
-
274
- context 'when the line is empty' do
275
- let(:line) {}
276
-
277
- it { subject.must_equal(0) }
278
- end
279
-
280
- context 'when the line is not empty' do
281
- it { subject.must_equal(12) }
282
- end
283
- end
284
-
285
227
  describe '#to_s' do
286
228
  subject { instance.to_s }
287
229
 
288
230
  context 'when the line is empty' do
289
- let(:line) {}
231
+ let(:collection) {}
290
232
 
291
233
  it { subject.must_equal('') }
292
234
  end