vedeu 0.6.44 → 0.6.45

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f4dc70c4f76f9925516a551048473859ddd3dff7
4
- data.tar.gz: a3edcec22cc3421ce2c725ea96340587e669f03b
3
+ metadata.gz: c76c4e0d9abb0d4ce8fd8f6161c07504a3d6cbbb
4
+ data.tar.gz: 7ee11459a372f200d2d2ae141fc159c96b941fbe
5
5
  SHA512:
6
- metadata.gz: 08a1c9d7c3a83c44012dd04271e717cf35ddafddde398ef1ea1131eeb6a22045e2fdd34ba1fd7dc32b057477a60214ce1db1ad68eaf3d9f090308dab7236e8a8
7
- data.tar.gz: 5fcbbb89449438c488f1206e98a93c7cba96b945de16f2bddc259c5608225c745d7f9f2ce8ac54f57748e630bf53733dc46bf49b22ca796ed3d337dea2b16cb4
6
+ metadata.gz: cc488bb31f2ba6d6a6fc2dfe6b808ea88dda9627ef7f9b767273ecf00538ef72205f20683ea7f0e6b4d96173d6dcd07b3e3747d6a604d1535dd003979a39d041
7
+ data.tar.gz: b1683006f7daa19a790928fd58ccd03fab1567064c67240db9813776389d300b65cab261bcf03cacff38e6949661aae2a02c0d86f577176bdeaa4f9103657562
@@ -97,7 +97,7 @@ module Vedeu
97
97
  @oy += 1
98
98
  @y = coordinate(oy, :y).y
99
99
 
100
- store
100
+ store_and_refresh
101
101
  end
102
102
 
103
103
  # Moves the cursor left by one column.
@@ -110,7 +110,7 @@ module Vedeu
110
110
  @ox -= 1
111
111
  @x = coordinate(ox, :x).x
112
112
 
113
- store
113
+ store_and_refresh
114
114
  end
115
115
 
116
116
  # Moves the cursor to the top left of the named interface.
@@ -138,7 +138,7 @@ module Vedeu
138
138
  @ox += 1
139
139
  @x = coordinate(ox, :x).x
140
140
 
141
- store
141
+ store_and_refresh
142
142
  end
143
143
 
144
144
  # Moves the cursor up by one row.
@@ -151,7 +151,7 @@ module Vedeu
151
151
  @oy -= 1
152
152
  @y = coordinate(oy, :y).y
153
153
 
154
- store
154
+ store_and_refresh
155
155
  end
156
156
 
157
157
  # Renders the cursor.
@@ -300,6 +300,17 @@ module Vedeu
300
300
  attributes.merge!(x: new_x, y: new_y, ox: new_ox, oy: new_oy)
301
301
  end
302
302
 
303
+ # Store the cursor and refresh the cursor.
304
+ #
305
+ # @return [void]
306
+ def store_and_refresh
307
+ store
308
+
309
+ Vedeu.trigger(:_refresh_cursor_, name)
310
+
311
+ self
312
+ end
313
+
303
314
  # Returns the escape sequence for setting the visibility of the
304
315
  # cursor.
305
316
  #
@@ -340,45 +351,29 @@ module Vedeu
340
351
 
341
352
  # See {file:docs/cursors.md}
342
353
  Vedeu.bind(:_cursor_left_) do |name|
343
- cursor = Vedeu.cursors.by_name(name)
344
-
345
- if cursor.visible?
346
- cursor.move_left
347
-
348
- Vedeu.trigger(:_refresh_cursor_, name)
354
+ Vedeu.cursors.by_name(name).tap do |cursor|
355
+ cursor.move_left if cursor.visible?
349
356
  end
350
357
  end
351
358
 
352
359
  # See {file:docs/cursors.md}
353
360
  Vedeu.bind(:_cursor_down_) do |name|
354
- cursor = Vedeu.cursors.by_name(name)
355
-
356
- if cursor.visible?
357
- cursor.move_down
358
-
359
- Vedeu.trigger(:_refresh_cursor_, name)
361
+ Vedeu.cursors.by_name(name).tap do |cursor|
362
+ cursor.move_down if cursor.visible?
360
363
  end
361
364
  end
362
365
 
363
366
  # See {file:docs/cursors.md}
364
367
  Vedeu.bind(:_cursor_up_) do |name|
365
- cursor = Vedeu.cursors.by_name(name)
366
-
367
- if cursor.visible?
368
- cursor.move_up
369
-
370
- Vedeu.trigger(:_refresh_cursor_, name)
368
+ Vedeu.cursors.by_name(name).tap do |cursor|
369
+ cursor.move_up if cursor.visible?
371
370
  end
372
371
  end
373
372
 
374
373
  # See {file:docs/cursors.md}
375
374
  Vedeu.bind(:_cursor_right_) do |name|
376
- cursor = Vedeu.cursors.by_name(name)
377
-
378
- if cursor.visible?
379
- cursor.move_right
380
-
381
- Vedeu.trigger(:_refresh_cursor_, name)
375
+ Vedeu.cursors.by_name(name).tap do |cursor|
376
+ cursor.move_right if cursor.visible?
382
377
  end
383
378
  end
384
379
 
@@ -21,6 +21,7 @@ require 'vedeu/geometry/coordinate'
21
21
  require 'vedeu/geometry/dimension'
22
22
  require 'vedeu/geometry/x_dimension'
23
23
  require 'vedeu/geometry/y_dimension'
24
+ require 'vedeu/geometry/validator'
24
25
  require 'vedeu/geometry/dsl'
25
26
  require 'vedeu/geometry/coordinate'
26
27
  require 'vedeu/geometry/geometry'
@@ -76,6 +76,7 @@ module Vedeu
76
76
  include Vedeu::Common
77
77
  include Vedeu::DSL
78
78
  include Vedeu::DSL::Use
79
+ include Vedeu::Geometry::Validator
79
80
 
80
81
  # Specify the geometry of an interface or view with a simple
81
82
  # DSL.
@@ -147,22 +148,10 @@ module Vedeu
147
148
  # is not given.
148
149
  # @return [Vedeu::Geometry::Geometry]
149
150
  def align(vertical, horizontal, width, height)
150
- fail Vedeu::Error::InvalidSyntax,
151
- 'No vertical alignment given. Valid values are :bottom, ' \
152
- ':middle, :none, :top.'.freeze unless present?(vertical)
153
- fail Vedeu::Error::InvalidSyntax,
154
- 'No horizontal alignment given. Valid values are :center, ' \
155
- ':centre, :left, :none, :right.'.freeze unless present?(horizontal)
156
-
157
- unless vertical == :none
158
- fail Vedeu::Error::InvalidSyntax,
159
- 'No height given.'.freeze if absent?(height)
160
- end
161
-
162
- unless horizontal == :none
163
- fail Vedeu::Error::InvalidSyntax,
164
- 'No width given.'.freeze if absent?(width)
165
- end
151
+ validate_vertical_alignment!(vertical)
152
+ validate_horizontal_alignment!(horizontal)
153
+ validate_height!(height) unless vertical == :none
154
+ validate_width!(width) unless horizontal == :none
166
155
 
167
156
  horizontal_alignment(horizontal, width)
168
157
  vertical_alignment(vertical, height)
@@ -173,11 +162,8 @@ module Vedeu
173
162
  # @param width [Fixnum] The number of characters/columns.
174
163
  # @return [Vedeu::Geometry::Geometry]
175
164
  def horizontal_alignment(value, width)
176
- fail Vedeu::Error::InvalidSyntax,
177
- 'No horizontal alignment given. Valid values are :center, ' \
178
- ':centre, :left, :none, :right.'.freeze unless present?(value)
179
- fail Vedeu::Error::InvalidSyntax,
180
- 'No width given.'.freeze unless present?(width)
165
+ validate_horizontal_alignment!(value)
166
+ validate_width!(width)
181
167
 
182
168
  model.horizontal_alignment = Vedeu::Geometry::HorizontalAlignment
183
169
  .coerce(value)
@@ -189,11 +175,8 @@ module Vedeu
189
175
  # @param height [Fixnum] The number of lines/rows.
190
176
  # @return [Vedeu::Geometry::Geometry]
191
177
  def vertical_alignment(value, height)
192
- fail Vedeu::Error::InvalidSyntax,
193
- 'No vertical alignment given. Valid values are :bottom, ' \
194
- ':middle, :none, :top.'.freeze unless present?(value)
195
- fail Vedeu::Error::InvalidSyntax,
196
- 'No height given.'.freeze unless present?(height)
178
+ validate_vertical_alignment!(value)
179
+ validate_height!(height)
197
180
 
198
181
  model.vertical_alignment = Vedeu::Geometry::VerticalAlignment
199
182
  .coerce(value)
@@ -0,0 +1,56 @@
1
+ module Vedeu
2
+
3
+ module Geometry
4
+
5
+ module Validator
6
+
7
+ include Vedeu::Common
8
+
9
+ # @param value [Fixnum] The number of lines/rows.
10
+ # @raise [Vedeu::Error::InvalidSyntax] When the value is nil.
11
+ # @return [TrueClass]
12
+ def validate_height!(value)
13
+ fail Vedeu::Error::InvalidSyntax,
14
+ 'No height given.'.freeze if absent?(value)
15
+
16
+ true
17
+ end
18
+
19
+ # @param value [Symbol] One of :center, :centre, :left,
20
+ # :none, :right.
21
+ # @raise [Vedeu::Error::InvalidSyntax] When the value is nil.
22
+ # @return [TrueClass]
23
+ def validate_horizontal_alignment!(value)
24
+ fail Vedeu::Error::InvalidSyntax,
25
+ 'No horizontal alignment given. Valid values are :center, ' \
26
+ ':centre, :left, :none, :right.'.freeze unless present?(value)
27
+
28
+ true
29
+ end
30
+
31
+ # @param vertical [Symbol] One of :bottom, :middle, :none, :top.
32
+ # @raise [Vedeu::Error::InvalidSyntax] When the value is nil.
33
+ # @return [TrueClass]
34
+ def validate_vertical_alignment!(value)
35
+ fail Vedeu::Error::InvalidSyntax,
36
+ 'No vertical alignment given. Valid values are :bottom, ' \
37
+ ':middle, :none, :top.'.freeze unless present?(value)
38
+
39
+ true
40
+ end
41
+
42
+ # @param value [Fixnum] The number of characters/columns.
43
+ # @raise [Vedeu::Error::InvalidSyntax] When the value is nil.
44
+ # @return [TrueClass]
45
+ def validate_width!(value)
46
+ fail Vedeu::Error::InvalidSyntax,
47
+ 'No width given.'.freeze if absent?(value)
48
+
49
+ true
50
+ end
51
+
52
+ end # Validator
53
+
54
+ end # Geometry
55
+
56
+ end # Vedeu
@@ -22,19 +22,8 @@ module Vedeu
22
22
  @options = options || {}
23
23
  end
24
24
 
25
- # Render a cleared output.
25
+ # Render the output (either content or clearing) to a file.
26
26
  #
27
- # @param output [Vedeu::Models::Page]
28
- # @param opts [Hash]
29
- # @return [String]
30
- def clear(output = '', opts = {})
31
- @options = options.merge!(opts)
32
-
33
- ::File.write(filename, out(output)) if write_file?
34
-
35
- out(output)
36
- end
37
-
38
27
  # @param output [Vedeu::Models::Page]
39
28
  # @param opts [Hash]
40
29
  # @return [String]
@@ -45,6 +34,7 @@ module Vedeu
45
34
 
46
35
  out(output)
47
36
  end
37
+ alias_method :clear, :render
48
38
 
49
39
  private
50
40
 
@@ -62,11 +52,18 @@ module Vedeu
62
52
  end
63
53
  end
64
54
 
55
+ # Return the filename given in the options, (or use the
56
+ # default), and append a timestamp if the :timestamp option was
57
+ # set to true.
58
+ #
65
59
  # @return [String]
66
60
  def filename
67
61
  options[:filename] + timestamp
68
62
  end
69
63
 
64
+ # Return a timestamp for use as part of the filename if the
65
+ # :timestamp option was set to true, otherwise an empty string.
66
+ #
70
67
  # @return [Float]
71
68
  def timestamp
72
69
  if options[:timestamp]
@@ -78,6 +75,8 @@ module Vedeu
78
75
  end
79
76
  end
80
77
 
78
+ # Returns a boolean indicating whether a file should be written.
79
+ #
81
80
  # @return [Boolean]
82
81
  def write_file?
83
82
  options[:write_file]
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.44'.freeze
4
+ VERSION = '0.6.45'.freeze
5
5
 
6
6
  end
@@ -129,6 +129,8 @@ module Vedeu
129
129
  let(:ox) { 3 }
130
130
  let(:oy) { 2 }
131
131
 
132
+ before { Vedeu.stubs(:trigger).with(:_refresh_cursor_, _name) }
133
+
132
134
  subject { instance.move_down }
133
135
 
134
136
  it { subject.must_be_instance_of(described) }
@@ -145,6 +147,8 @@ module Vedeu
145
147
  let(:ox) { 3 }
146
148
  let(:oy) { 2 }
147
149
 
150
+ before { Vedeu.stubs(:trigger).with(:_refresh_cursor_, _name) }
151
+
148
152
  subject { instance.move_left }
149
153
 
150
154
  it { subject.must_be_instance_of(described) }
@@ -177,6 +181,8 @@ module Vedeu
177
181
  let(:ox) { 3 }
178
182
  let(:oy) { 2 }
179
183
 
184
+ before { Vedeu.stubs(:trigger).with(:_refresh_cursor_, _name) }
185
+
180
186
  subject { instance.move_right }
181
187
 
182
188
  it { subject.must_be_instance_of(described) }
@@ -193,6 +199,8 @@ module Vedeu
193
199
  let(:ox) { 3 }
194
200
  let(:oy) { 2 }
195
201
 
202
+ before { Vedeu.stubs(:trigger).with(:_refresh_cursor_, _name) }
203
+
196
204
  subject { instance.move_up }
197
205
 
198
206
  it { subject.must_be_instance_of(described) }
@@ -0,0 +1,83 @@
1
+ require 'test_helper'
2
+
3
+ module Vedeu
4
+
5
+ module Geometry
6
+
7
+ class ValidatorTestClass
8
+ include Vedeu::Geometry::Validator
9
+ end
10
+
11
+ describe Validator do
12
+
13
+ let(:included) { Vedeu::Geometry::ValidatorTestClass.new }
14
+
15
+ describe '#validate_height!' do
16
+ let(:_value) {}
17
+
18
+ subject { included.validate_height!(_value) }
19
+
20
+ context 'when the value is given' do
21
+ let(:_value) { 11 }
22
+
23
+ it { subject.must_equal(true) }
24
+ end
25
+
26
+ context 'when the value is not given' do
27
+ it { proc { subject }.must_raise(Vedeu::Error::InvalidSyntax) }
28
+ end
29
+ end
30
+
31
+ describe '#validate_horizontal_alignment!' do
32
+ let(:_value) {}
33
+
34
+ subject { included.validate_horizontal_alignment!(_value) }
35
+
36
+ context 'when the value is given' do
37
+ let(:_value) { :left }
38
+
39
+ it { subject.must_equal(true) }
40
+ end
41
+
42
+ context 'when the value is not given' do
43
+ it { proc { subject }.must_raise(Vedeu::Error::InvalidSyntax) }
44
+ end
45
+ end
46
+
47
+ describe '#validate_vertical_alignment!' do
48
+ let(:_value) {}
49
+
50
+ subject { included.validate_vertical_alignment!(_value) }
51
+
52
+ context 'when the value is given' do
53
+ let(:_value) { :top }
54
+
55
+ it { subject.must_equal(true) }
56
+ end
57
+
58
+ context 'when the value is not given' do
59
+ it { proc { subject }.must_raise(Vedeu::Error::InvalidSyntax) }
60
+ end
61
+ end
62
+
63
+ describe '#validate_width!' do
64
+ let(:_value) {}
65
+
66
+ subject { included.validate_width!(_value) }
67
+
68
+ context 'when the value is given' do
69
+ let(:_value) { 11 }
70
+
71
+ it { subject.must_equal(true) }
72
+ end
73
+
74
+ context 'when the value is not given' do
75
+ it { proc { subject }.must_raise(Vedeu::Error::InvalidSyntax) }
76
+ end
77
+ end
78
+
79
+ end # Validator
80
+
81
+ end # Geometry
82
+
83
+ end # Vedeu
@@ -27,18 +27,13 @@ module Vedeu
27
27
  it { instance.instance_variable_get('@options').must_equal(options) }
28
28
  end
29
29
 
30
- describe '#clear' do
31
- subject { instance.clear }
32
-
33
- it { subject.must_be_instance_of(String) }
34
- it { subject.must_equal('') }
35
- end
36
-
37
30
  describe '#render' do
38
31
  let(:_time) { Time.new(2015, 4, 12, 20, 05, 00, "+01:00") }
39
32
 
40
33
  subject { instance.render(output) }
41
34
 
35
+ it { instance.must_respond_to(:clear) }
36
+
42
37
  # it { subject.must_be_instance_of(String) }
43
38
 
44
39
  context 'when the filename option is not set' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vedeu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.44
4
+ version: 0.6.45
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Laking
@@ -413,6 +413,7 @@ files:
413
413
  - lib/vedeu/geometry/null.rb
414
414
  - lib/vedeu/geometry/position.rb
415
415
  - lib/vedeu/geometry/repository.rb
416
+ - lib/vedeu/geometry/validator.rb
416
417
  - lib/vedeu/geometry/vertical_alignment.rb
417
418
  - lib/vedeu/geometry/x_dimension.rb
418
419
  - lib/vedeu/geometry/y_dimension.rb
@@ -586,6 +587,7 @@ files:
586
587
  - test/lib/vedeu/geometry/null_test.rb
587
588
  - test/lib/vedeu/geometry/position_test.rb
588
589
  - test/lib/vedeu/geometry/repository_test.rb
590
+ - test/lib/vedeu/geometry/validator_test.rb
589
591
  - test/lib/vedeu/geometry/vertical_alignment_test.rb
590
592
  - test/lib/vedeu/geometry/x_dimension_test.rb
591
593
  - test/lib/vedeu/geometry/y_dimension_test.rb
@@ -787,6 +789,7 @@ test_files:
787
789
  - test/lib/vedeu/geometry/null_test.rb
788
790
  - test/lib/vedeu/geometry/position_test.rb
789
791
  - test/lib/vedeu/geometry/repository_test.rb
792
+ - test/lib/vedeu/geometry/validator_test.rb
790
793
  - test/lib/vedeu/geometry/vertical_alignment_test.rb
791
794
  - test/lib/vedeu/geometry/x_dimension_test.rb
792
795
  - test/lib/vedeu/geometry/y_dimension_test.rb