vedeu 0.8.13 → 0.8.14

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -0
  3. data/lib/vedeu/buffers/empty.rb +1 -2
  4. data/lib/vedeu/buffers/view.rb +13 -26
  5. data/lib/vedeu/cells/border.rb +0 -1
  6. data/lib/vedeu/cells/empty.rb +1 -4
  7. data/lib/vedeu/coercers/editor_lines.rb +1 -1
  8. data/lib/vedeu/coercers/page.rb +2 -2
  9. data/lib/vedeu/coercers/position.rb +2 -7
  10. data/lib/vedeu/coercers/row.rb +1 -1
  11. data/lib/vedeu/coercers/style.rb +1 -1
  12. data/lib/vedeu/common.rb +8 -0
  13. data/lib/vedeu/configuration/api.rb +2 -2
  14. data/lib/vedeu/configuration/configuration.rb +58 -3
  15. data/lib/vedeu/editor/delete.rb +1 -1
  16. data/lib/vedeu/interfaces/dsl.rb +1 -1
  17. data/lib/vedeu/logging/debug.rb +1 -1
  18. data/lib/vedeu/logging/log.rb +5 -54
  19. data/lib/vedeu/presentation/colour.rb +9 -0
  20. data/lib/vedeu/presentation/position.rb +10 -0
  21. data/lib/vedeu/presentation/presentation.rb +0 -28
  22. data/lib/vedeu/presentation/styles.rb +11 -0
  23. data/lib/vedeu/renderers/all.rb +3 -2
  24. data/lib/vedeu/renderers/{file.rb → support/file.rb} +0 -0
  25. data/lib/vedeu/renderers/{options.rb → support/options.rb} +0 -0
  26. data/lib/vedeu/repositories/collection.rb +1 -0
  27. data/lib/vedeu/repositories/repository.rb +1 -1
  28. data/lib/vedeu/repositories/store.rb +1 -1
  29. data/lib/vedeu/version.rb +1 -1
  30. data/lib/vedeu/views/chars.rb +39 -33
  31. data/lib/vedeu/views/lines.rb +31 -25
  32. data/lib/vedeu/views/streams.rb +35 -29
  33. data/test/lib/vedeu/cells/empty_test.rb +6 -4
  34. data/test/lib/vedeu/common_test.rb +16 -0
  35. data/test/lib/vedeu/configuration/api_test.rb +2 -11
  36. data/test/lib/vedeu/configuration/configuration_test.rb +56 -28
  37. data/test/lib/vedeu/renderers/{file_test.rb → support/file_test.rb} +0 -0
  38. data/test/lib/vedeu/renderers/{options_test.rb → support/options_test.rb} +0 -0
  39. data/test/lib/vedeu/repositories/repository_test.rb +1 -1
  40. metadata +8 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 002c233933994a1c074caa09713374413fb3ec7e
4
- data.tar.gz: f083bf135c2d9307329af03198159f73ecc88548
3
+ metadata.gz: 34e3c347f479d6c178f4aacae2dd5cee4018d555
4
+ data.tar.gz: 92cb71dfedee65fb74c2808c843bea8222802808
5
5
  SHA512:
6
- metadata.gz: a0c4f251a4537d4907ec3b9b1eea499be60b8be212fc8544e3ce7beef9eaff3b33ed8d5ef73cd0dc6ad85965a88f77aa0f7dd06336bb2f5718db33e0dabfaa3e
7
- data.tar.gz: 86f69b80ad1db0b0df5ef2bce701c33e6f09e8d57ab9784331f1cca01b3eb48781992ce61d451915b9caf0557564a8ec91d451bed3ba27b3187803907c486f78
6
+ metadata.gz: 338a4fd459b7f6d89e56e3247921aa215069b5bf30b947084fbd55c5aec2a42d44cecaf6d8a4a5ca7e38fd0084b5908239bffe9a760c444476ff336e1c51ef16
7
+ data.tar.gz: a84a360d6c8f4153ca61aa89ea819178d866d9e9d4b306b23da5a9da57bba8146840155b24626a24108bd1a3a6addcdde33a93c0b8582379933a1462ab7f83a2
data/.rubocop.yml CHANGED
@@ -41,6 +41,9 @@ Style/EmptyLinesAroundClassBody:
41
41
  Style/EmptyLinesAroundModuleBody:
42
42
  EnforcedStyle: empty_lines
43
43
 
44
+ Style/ExtraSpacing:
45
+ Enabled: false
46
+
44
47
  # Style/GlobalVars:
45
48
  # AllowedVariables: [$LIB_DIR]
46
49
 
@@ -57,8 +57,7 @@ module Vedeu
57
57
  def empty
58
58
  Array.new(height) do |h|
59
59
  Array.new(width) do |w|
60
- position = Vedeu::Geometries::Position.new((y + h), (x + w))
61
- Vedeu::Cells::Empty.new(name: name, position: position)
60
+ Vedeu::Cells::Empty.new(name: name, position: [(y + h), (x + w)])
62
61
  end
63
62
  end
64
63
  end
@@ -48,7 +48,9 @@ module Vedeu
48
48
  # Vedeu::Cells::Char]
49
49
  # @return [Vedeu::Buffers::View]
50
50
  def update(value_or_values)
51
- Array(value_or_values).flatten.each { |value| write(value) }
51
+ Array(value_or_values).flatten.each do |value|
52
+ write(value) if positionable?(value)
53
+ end
52
54
 
53
55
  self
54
56
  end
@@ -61,6 +63,12 @@ module Vedeu
61
63
 
62
64
  private
63
65
 
66
+ # @param value [void]
67
+ # @return [Fixnum]
68
+ def column(value)
69
+ Vedeu::Point.coerce(value: value.position.x, min: bx, max: bxn).value
70
+ end
71
+
64
72
  # @return [Array<Vedeu::Cells::Empty>]
65
73
  def current
66
74
  @current ||= Vedeu::Buffers::Empty.new(height: bordered_height,
@@ -82,31 +90,10 @@ module Vedeu
82
90
  @_geometry ||= Vedeu.geometries.by_name(name)
83
91
  end
84
92
 
85
- # Returns a boolean indicating the value has a position
86
- # attribute and is within the terminal boundary.
87
- #
88
93
  # @param value [void]
89
- # @return [Boolean]
90
- def valid?(value)
91
- positionable?(value) &&
92
- valid_y?(value.position.y) &&
93
- valid_x?(value.position.x)
94
- end
95
-
96
- # Returns a boolean indicating whether the x position of the
97
- # value object is valid for this geometry.
98
- #
99
- # @return [Boolean]
100
- def valid_x?(x)
101
- Vedeu::Point.valid?(value: x, min: bx, max: bxn)
102
- end
103
-
104
- # Returns a boolean indicating whether the y position of the
105
- # value object is valid for this geometry.
106
- #
107
- # @return [Boolean]
108
- def valid_y?(y)
109
- Vedeu::Point.valid?(value: y, min: by, max: byn)
94
+ # @return [Fixnum]
95
+ def row(value)
96
+ Vedeu::Point.coerce(value: value.position.y, min: by, max: byn).value
110
97
  end
111
98
 
112
99
  # Write the value into the respective cell as defined by the
@@ -115,7 +102,7 @@ module Vedeu
115
102
  # @param value [void]
116
103
  # @return [NilClass|void]
117
104
  def write(value)
118
- current[value.position.y][value.position.x] = value if valid?(value)
105
+ current[row(value)][column(value)] = value
119
106
  end
120
107
 
121
108
  end # View
@@ -12,7 +12,6 @@ module Vedeu
12
12
  class Border < Vedeu::Cells::Empty
13
13
 
14
14
  extend Forwardable
15
- include Vedeu::Presentation
16
15
 
17
16
  def_delegators :geometry,
18
17
  :x,
@@ -38,10 +38,7 @@ module Vedeu
38
38
  # @param other [void]
39
39
  # @return [Boolean]
40
40
  def eql?(other)
41
- self.class.equal?(other.class) &&
42
- position == other.position &&
43
- value == other.value &&
44
- colour == other.colour
41
+ self.class.equal?(other.class) && position == other.position
45
42
  end
46
43
  alias == eql?
47
44
 
@@ -17,7 +17,7 @@ module Vedeu
17
17
  if coerced?
18
18
  klass.new(value.lines)
19
19
 
20
- elsif value.is_a?(Array)
20
+ elsif array?(value)
21
21
  collection = value.map do |line|
22
22
  Vedeu::Editor::Line.coerce(line)
23
23
  end
@@ -20,10 +20,10 @@ module Vedeu
20
20
  elsif value.is_a?(Vedeu::Models::Row)
21
21
  klass.new([value])
22
22
 
23
- elsif value.is_a?(Array) && value.empty?
23
+ elsif array?(value) && value.empty?
24
24
  klass.new([Vedeu::Models::Row.coerce(value)])
25
25
 
26
- elsif value.is_a?(Array) || value.is_a?(Vedeu::Buffers::View)
26
+ elsif array?(value) || value.is_a?(Vedeu::Buffers::View)
27
27
  values = value.map { |v| Vedeu::Models::Row.coerce(v) }
28
28
 
29
29
  klass.new(values)
@@ -20,7 +20,7 @@ module Vedeu
20
20
  elsif tuple?
21
21
  klass.new(*value)
22
22
 
23
- elsif hash?
23
+ elsif hash?(value)
24
24
  klass.new(value.fetch(:y, 1), value.fetch(:x, 1))
25
25
 
26
26
  elsif numeric?(value)
@@ -34,11 +34,6 @@ module Vedeu
34
34
 
35
35
  private
36
36
 
37
- # @return [Boolean]
38
- def hash?
39
- value.is_a?(Hash)
40
- end
41
-
42
37
  # @return [Class]
43
38
  def klass
44
39
  Vedeu::Geometries::Position
@@ -47,7 +42,7 @@ module Vedeu
47
42
  # @macro raise_fatal
48
43
  # @return [Boolean]
49
44
  def tuple?
50
- return false unless value.is_a?(Array)
45
+ return false unless array?(value)
51
46
  return true if value.size == 2
52
47
 
53
48
  raise Vedeu::Error::Fatal,
@@ -16,7 +16,7 @@ module Vedeu
16
16
  if coerced?
17
17
  value
18
18
 
19
- elsif value.is_a?(Array)
19
+ elsif array?(value)
20
20
  klass.new(value.compact)
21
21
 
22
22
  elsif value.nil?
@@ -19,7 +19,7 @@ module Vedeu
19
19
  if coerced?
20
20
  value
21
21
 
22
- elsif value.is_a?(Hash)
22
+ elsif hash?(value)
23
23
  if present?(value[:style])
24
24
  if value[:style].is_a?(klass)
25
25
  value[:style]
data/lib/vedeu/common.rb CHANGED
@@ -17,6 +17,14 @@ module Vedeu
17
17
  !present?(variable)
18
18
  end
19
19
 
20
+ # Returns a boolean indicating whether the value is an Array.
21
+ #
22
+ # @param value [Array|void]
23
+ # @return [Boolean]
24
+ def array?(value)
25
+ value.is_a?(Array)
26
+ end
27
+
20
28
  # Returns a boolean indicating the value was a boolean.
21
29
  #
22
30
  # @param value [void]
@@ -243,7 +243,7 @@ module Vedeu
243
243
 
244
244
  # Log specific message types except those given. A complete list
245
245
  # of message types can be found at
246
- # {Vedeu::Logging::Log.message_types}.
246
+ # {Vedeu::Configuration.log_types}.
247
247
  #
248
248
  # Vedeu.configure do
249
249
  # log_except :debug, :event
@@ -262,7 +262,7 @@ module Vedeu
262
262
  end
263
263
 
264
264
  # Only log specific message types. A complete list of message
265
- # types can be found at {Vedeu::Logging::Log.message_types}.
265
+ # types can be found at {Vedeu::Configuration.log_types}.
266
266
  #
267
267
  # Vedeu.configure do
268
268
  # log_only :debug, :event
@@ -180,12 +180,54 @@ module Vedeu
180
180
 
181
181
  # @return [Array<Symbol>]
182
182
  def log_except
183
- instance.options[:log_except] || []
183
+ instance.options[:log_except]
184
184
  end
185
185
 
186
186
  # @return [Array<Symbol>]
187
187
  def log_only
188
- instance.options[:log_only] || []
188
+ instance.options[:log_only]
189
+ end
190
+
191
+ # The defined message types for Vedeu with their respective
192
+ # colours. When used, produces a log entry of the format:
193
+ #
194
+ # [type] message
195
+ #
196
+ # The 'type' will be shown as the first colour defined in the
197
+ # value array, whilst the 'message' will be shown using the
198
+ # last colour.
199
+ #
200
+ # @return [Hash<Symbol => Array<Symbol>>]
201
+ def log_types
202
+ {
203
+ blue: [:light_blue, :blue],
204
+ buffer: [:light_green, :green],
205
+ compress: [:white, :light_grey],
206
+ config: [:light_blue, :blue],
207
+ create: [:light_cyan, :cyan],
208
+ cursor: [:light_green, :green],
209
+ cyan: [:light_cyan, :cyan],
210
+ debug: [:white, :light_grey],
211
+ drb: [:light_blue, :blue],
212
+ dsl: [:light_blue, :blue],
213
+ editor: [:light_blue, :blue],
214
+ error: [:light_red, :red],
215
+ event: [:light_magenta, :magenta],
216
+ green: [:light_green, :green],
217
+ info: [:white, :light_grey],
218
+ input: [:light_yellow, :yellow],
219
+ magenta: [:light_magenta, :magenta],
220
+ output: [:light_yellow, :yellow],
221
+ red: [:light_red, :red],
222
+ render: [:light_green, :green],
223
+ reset: [:light_cyan, :cyan],
224
+ store: [:light_cyan, :cyan],
225
+ test: [:white, :light_grey],
226
+ timer: [:light_blue, :blue],
227
+ update: [:light_cyan, :cyan],
228
+ white: [:white, :light_grey],
229
+ yellow: [:light_yellow, :yellow],
230
+ }
189
231
  end
190
232
 
191
233
  # Returns true if the given type was included in the :log_only
@@ -195,7 +237,20 @@ module Vedeu
195
237
  # @param type [Symbol]
196
238
  # @return [Boolean]
197
239
  def loggable?(type)
198
- log_only.include?(type) || !log_except.include?(type)
240
+ return false unless log_types.keys.include?(type)
241
+ return true if log_only.empty? && log_except.empty?
242
+
243
+ types = if log_except.any?
244
+ log_types.keys - log_except
245
+ else
246
+ log_types.keys
247
+ end
248
+
249
+ if log_only.any?
250
+ log_only.include?(type)
251
+ else
252
+ types.include?(type) ? true : false
253
+ end
199
254
  end
200
255
 
201
256
  # Returns whether mouse support was enabled or disabled.
@@ -70,7 +70,7 @@ module Vedeu
70
70
  #
71
71
  # @return [Boolean]
72
72
  def lines?
73
- collection.is_a?(Array)
73
+ array?(collection)
74
74
  end
75
75
 
76
76
  # Returns a boolean indicating whether the index was given or
@@ -322,7 +322,7 @@ module Vedeu
322
322
  model.zindex = value
323
323
  end
324
324
  alias z_index zindex
325
- alias z zindex
325
+ alias z zindex
326
326
 
327
327
  end # DSL
328
328
 
@@ -65,7 +65,7 @@ module Vedeu
65
65
  # - Creates a HTML visualization of the Ruby stack
66
66
  ::RubyProf::CallStackPrinter.new(result).print(file)
67
67
 
68
- # Used with QTCacheGrind to analyse performance.
68
+ # Used with KCachegrind to analyse performance.
69
69
  # ::RubyProf::CallTreePrinter.new(result).print(file)
70
70
 
71
71
  # Creates a flat report in text format
@@ -27,7 +27,8 @@ module Vedeu
27
27
  # to write to the log file regardless of the Configuration
28
28
  # setting.
29
29
  # @param type [Symbol] Colour code messages in the log file
30
- # depending on their source. See {message_types}
30
+ # depending on their source. See
31
+ # {Vedeu::Configuration.log_types}
31
32
  #
32
33
  # @return [String]
33
34
  def log(message:, force: false, type: :info)
@@ -40,7 +41,7 @@ module Vedeu
40
41
 
41
42
  # {include:file:docs/dsl/by_method/log_stdout.md}
42
43
  # @macro vedeu_logging_log_param_message
43
- # @param type [Symbol] See {Vedeu::Logging::Log.message_types}
44
+ # @param type [Symbol] See {Vedeu::Configuration.log_types}
44
45
  # for valid values.
45
46
  # @return [String]
46
47
  def log_stdout(message:, type: :info)
@@ -51,7 +52,7 @@ module Vedeu
51
52
 
52
53
  # {include:file:docs/dsl/by_method/log_stderr.md}
53
54
  # @macro vedeu_logging_log_param_message
54
- # @param type [Symbol] See {Vedeu::Logging::Log.message_types}
55
+ # @param type [Symbol] See {Vedeu::Logging::Log.types}
55
56
  # for valid values.
56
57
  # @return [String]
57
58
  def log_stderr(message:, type: :error)
@@ -102,7 +103,7 @@ module Vedeu
102
103
  # @macro vedeu_logging_log_param_message
103
104
  # @return [String]
104
105
  def log_entry(type, message)
105
- colours = message_types.fetch(type, [:default, :default])
106
+ colours = Vedeu.config.log_types.fetch(type, [:default, :default])
106
107
 
107
108
  [
108
109
  Vedeu.esc.colour(colours[0]) { "[#{type}]".ljust(11) },
@@ -110,56 +111,6 @@ module Vedeu
110
111
  ].join
111
112
  end
112
113
 
113
- # The defined message types for Vedeu with their respective
114
- # colours. When used, produces a log entry of the format:
115
- #
116
- # [type] message
117
- #
118
- # The 'type' will be shown as the first colour defined in the
119
- # value array, whilst the 'message' will be shown using the
120
- # last colour.
121
- #
122
- # @return [Hash<Symbol => Array<Symbol>>]
123
- def message_types
124
- {
125
- create: [:light_cyan, :cyan],
126
- store: [:light_cyan, :cyan],
127
- update: [:light_cyan, :cyan],
128
- reset: [:light_cyan, :cyan],
129
-
130
- event: [:light_magenta, :magenta],
131
-
132
- timer: [:light_blue, :blue],
133
-
134
- info: [:white, :light_grey],
135
- test: [:white, :light_grey],
136
- debug: [:white, :light_grey],
137
- compress: [:white, :light_grey],
138
-
139
- input: [:light_yellow, :yellow],
140
- output: [:light_yellow, :yellow],
141
-
142
- cursor: [:light_green, :green],
143
- buffer: [:light_green, :green],
144
- render: [:light_green, :green],
145
-
146
- error: [:light_red, :red],
147
-
148
- config: [:light_blue, :blue],
149
- dsl: [:light_blue, :blue],
150
- editor: [:light_blue, :blue],
151
- drb: [:light_blue, :blue],
152
-
153
- blue: [:light_blue, :blue],
154
- cyan: [:light_cyan, :cyan],
155
- green: [:light_green, :green],
156
- magenta: [:light_magenta, :magenta],
157
- red: [:light_red, :red],
158
- white: [:white, :light_grey],
159
- yellow: [:light_yellow, :yellow],
160
- }
161
- end
162
-
163
114
  end # Eigenclass
164
115
 
165
116
  end # Log
@@ -140,6 +140,15 @@ module Vedeu
140
140
  present?(parent) && parent.respond_to?(:colour?)
141
141
  end
142
142
 
143
+ # Renders the colour attributes of the receiver and yields (to
144
+ # then render the styles).
145
+ #
146
+ # @param block [Proc]
147
+ # @return [String]
148
+ def render_colour(&block)
149
+ "#{colour}#{yield}"
150
+ end
151
+
143
152
  end # Colour
144
153
 
145
154
  end # Presentation
@@ -50,6 +50,16 @@ module Vedeu
50
50
  position.y if position?
51
51
  end
52
52
 
53
+ private
54
+
55
+ # @param block [Proc]
56
+ # @return [String]
57
+ def render_position(&block)
58
+ return position.to_s { yield } if position?
59
+
60
+ yield
61
+ end
62
+
53
63
  end # Position
54
64
 
55
65
  end # Presentation
@@ -18,34 +18,6 @@ module Vedeu
18
18
  end
19
19
  alias to_str to_s
20
20
 
21
- private
22
-
23
- # Renders the colour attributes of the receiver and yields (to
24
- # then render the styles).
25
- #
26
- # @param block [Proc]
27
- # @return [String]
28
- def render_colour(&block)
29
- "#{colour}#{yield}"
30
- end
31
-
32
- # @param block [Proc]
33
- # @return [String]
34
- def render_position(&block)
35
- return position.to_s { yield } if position?
36
-
37
- yield
38
- end
39
-
40
- # Renders the style attributes of the receiver and yields (to
41
- # then render the next model, or finally, the content).
42
- #
43
- # @param block [Proc]
44
- # @return [String]
45
- def render_style(&block)
46
- "#{style}#{yield}"
47
- end
48
-
49
21
  end # Presentation
50
22
 
51
23
  end # Vedeu
@@ -52,6 +52,17 @@ module Vedeu
52
52
  @_style = @style = Vedeu::Presentation::Style.coerce(value)
53
53
  end
54
54
 
55
+ private
56
+
57
+ # Renders the style attributes of the receiver and yields (to
58
+ # then render the next model, or finally, the content).
59
+ #
60
+ # @param block [Proc]
61
+ # @return [String]
62
+ def render_style(&block)
63
+ "#{style}#{yield}"
64
+ end
65
+
55
66
  end # Style
56
67
 
57
68
  end # Presentation
@@ -132,8 +132,9 @@ module Vedeu
132
132
 
133
133
  end # Vedeu
134
134
 
135
- require 'vedeu/renderers/options'
136
- require 'vedeu/renderers/file'
135
+ require 'vedeu/renderers/support/options'
136
+ require 'vedeu/renderers/support/file'
137
+
137
138
  require 'vedeu/renderers/escape'
138
139
  require 'vedeu/renderers/html'
139
140
  require 'vedeu/renderers/json'
File without changes
@@ -11,6 +11,7 @@ module Vedeu
11
11
  #
12
12
  class Collection
13
13
 
14
+ include Vedeu::Common
14
15
  include Vedeu::Repositories::Assemblage
15
16
 
16
17
  # @!attribute [r] collection
@@ -47,7 +47,7 @@ module Vedeu
47
47
  #
48
48
  # @return [Array<void>] An array containing each stored model.
49
49
  def all
50
- return storage.values if storage.is_a?(Hash)
50
+ return storage.values if hash?(storage)
51
51
 
52
52
  registered
53
53
  end
@@ -48,7 +48,7 @@ module Vedeu
48
48
  # @return [Array]
49
49
  def registered
50
50
  return [] if empty?
51
- return storage.keys if storage.is_a?(Hash)
51
+ return storage.keys if hash?(storage)
52
52
  return storage.to_a if storage.is_a?(Set)
53
53
 
54
54
  storage
data/lib/vedeu/version.rb CHANGED
@@ -3,6 +3,6 @@
3
3
  module Vedeu
4
4
 
5
5
  # The current version of Vedeu.
6
- VERSION = '0.8.13'
6
+ VERSION = '0.8.14'
7
7
 
8
8
  end
@@ -10,47 +10,53 @@ module Vedeu
10
10
  #
11
11
  class Chars < Vedeu::Repositories::Collection
12
12
 
13
- # @param collection [void]
14
- # @param parent [Vedeu::Views::Stream]
15
- # @param name [NilClass|Symbol|String]
16
- # @macro raise_invalid_syntax
17
- # @return [Vedeu::Views::Chars]
18
- def self.coerce(collection = [], parent = nil, name = nil)
19
- if collection.is_a?(Vedeu::Views::Chars)
20
- collection
21
-
22
- elsif collection.is_a?(Array)
23
- return new(collection, parent, name) if collection.empty?
24
-
25
- coerced_collection = []
26
- collection.each do |element|
27
- coerced_collection << element if element.is_a?(Vedeu::Cells::Char)
28
- end
13
+ class << self
29
14
 
30
- new(coerced_collection, parent, name)
15
+ include Vedeu::Common
31
16
 
32
- elsif collection.is_a?(Vedeu::Views::Stream)
33
- Vedeu::Views::Chars.coerce(collection.value,
34
- collection.parent,
35
- collection.name)
17
+ # @param collection [void]
18
+ # @param parent [Vedeu::Views::Stream]
19
+ # @param name [NilClass|Symbol|String]
20
+ # @macro raise_invalid_syntax
21
+ # @return [Vedeu::Views::Chars]
22
+ def coerce(collection = [], parent = nil, name = nil)
23
+ if collection.is_a?(Vedeu::Views::Chars)
24
+ collection
36
25
 
37
- elsif collection.is_a?(String)
38
- return new([], parent, name) if collection.empty?
26
+ elsif array?(collection)
27
+ return new(collection, parent, name) if collection.empty?
39
28
 
40
- if parent && parent.attributes
41
- new_collection = Vedeu::DSL::Text.new(collection,
42
- parent.attributes).chars
29
+ coerced_collection = []
30
+ collection.each do |element|
31
+ coerced_collection << element if element.is_a?(Vedeu::Cells::Char)
32
+ end
43
33
 
44
- new(new_collection, parent, name)
45
- end
34
+ new(coerced_collection, parent, name)
35
+
36
+ elsif collection.is_a?(Vedeu::Views::Stream)
37
+ Vedeu::Views::Chars.coerce(collection.value,
38
+ collection.parent,
39
+ collection.name)
40
+
41
+ elsif string?(collection)
42
+ return new([], parent, name) if collection.empty?
46
43
 
47
- else
48
- raise Vedeu::Error::InvalidSyntax,
49
- 'Cannot coerce for Vedeu::View::Chars, as collection is ' \
50
- 'unrecognised.'
44
+ if parent && parent.attributes
45
+ new_collection = Vedeu::DSL::Text.new(collection,
46
+ parent.attributes).chars
51
47
 
48
+ new(new_collection, parent, name)
49
+ end
50
+
51
+ else
52
+ raise Vedeu::Error::InvalidSyntax,
53
+ 'Cannot coerce for Vedeu::View::Chars, as collection is ' \
54
+ 'unrecognised.'
55
+
56
+ end
52
57
  end
53
- end
58
+
59
+ end # Eigenclass
54
60
 
55
61
  alias chars value
56
62
 
@@ -10,38 +10,44 @@ module Vedeu
10
10
  #
11
11
  class Lines < Vedeu::Repositories::Collection
12
12
 
13
- # @param (see Vedeu::Repositories::Collection#initialize)
14
- # @macro raise_invalid_syntax
15
- # @return [Vedeu::Views::Lines]
16
- def self.coerce(collection = [], parent = nil, name = nil)
17
- if collection.is_a?(Vedeu::Views::Lines)
18
- collection
19
-
20
- elsif collection.is_a?(Vedeu::Views::Streams)
21
- if collection.empty?
22
- # @todo Investigate whether this is being used.
23
- end
13
+ class << self
24
14
 
25
- elsif collection.is_a?(Array)
26
- return new(collection, parent, name) if collection.empty?
15
+ include Vedeu::Common
27
16
 
28
- coerced_collection = []
29
- collection.each do |element|
30
- coerced_collection << element if element.is_a?(Vedeu::Views::Line)
31
- end
17
+ # @param (see Vedeu::Repositories::Collection#initialize)
18
+ # @macro raise_invalid_syntax
19
+ # @return [Vedeu::Views::Lines]
20
+ def coerce(collection = [], parent = nil, name = nil)
21
+ if collection.is_a?(Vedeu::Views::Lines)
22
+ collection
23
+
24
+ elsif collection.is_a?(Vedeu::Views::Streams)
25
+ if collection.empty?
26
+ # @todo Investigate whether this is being used.
27
+ end
28
+
29
+ elsif array?(collection)
30
+ return new(collection, parent, name) if collection.empty?
32
31
 
33
- new(coerced_collection, parent, name)
32
+ coerced_collection = []
33
+ collection.each do |element|
34
+ coerced_collection << element if element.is_a?(Vedeu::Views::Line)
35
+ end
34
36
 
35
- elsif collection.is_a?(Vedeu::Views::Line)
36
- new([collection], parent, name)
37
+ new(coerced_collection, parent, name)
37
38
 
38
- else
39
- raise Vedeu::Error::InvalidSyntax,
40
- 'Cannot coerce for Vedeu::View::Lines, as collection ' \
41
- 'unrecognised.'
39
+ elsif collection.is_a?(Vedeu::Views::Line)
40
+ new([collection], parent, name)
42
41
 
42
+ else
43
+ raise Vedeu::Error::InvalidSyntax,
44
+ 'Cannot coerce for Vedeu::View::Lines, as collection ' \
45
+ 'unrecognised.'
46
+
47
+ end
43
48
  end
44
- end
49
+
50
+ end # Eigenclass
45
51
 
46
52
  alias lines value
47
53
 
@@ -10,49 +10,55 @@ module Vedeu
10
10
  #
11
11
  class Streams < Vedeu::Repositories::Collection
12
12
 
13
- # @param (see Vedeu::Repositories::Collection#initialize)
14
- # @macro raise_invalid_syntax
15
- # @return [Vedeu::Views::Streams]
16
- def self.coerce(collection = [], parent = nil, name = nil)
17
- if collection.is_a?(Vedeu::Views::Streams)
18
- collection
13
+ class << self
19
14
 
20
- elsif collection.is_a?(Array)
21
- return new(collection, parent, name) if collection.empty?
15
+ include Vedeu::Common
22
16
 
23
- coerced_collection = []
24
- collection.each do |element|
25
- if element.is_a?(Vedeu::Views::Stream)
26
- coerced_collection << element
17
+ # @param (see Vedeu::Repositories::Collection#initialize)
18
+ # @macro raise_invalid_syntax
19
+ # @return [Vedeu::Views::Streams]
20
+ def coerce(collection = [], parent = nil, name = nil)
21
+ if collection.is_a?(Vedeu::Views::Streams)
22
+ collection
27
23
 
28
- elsif element.is_a?(String)
29
- coerced_collection << Vedeu::Views::Stream.new(value: element)
24
+ elsif array?(collection)
25
+ return new(collection, parent, name) if collection.empty?
30
26
 
27
+ coerced_collection = []
28
+ collection.each do |element|
29
+ if element.is_a?(Vedeu::Views::Stream)
30
+ coerced_collection << element
31
+
32
+ elsif string?(element)
33
+ coerced_collection << Vedeu::Views::Stream.new(value: element)
34
+
35
+ end
31
36
  end
32
- end
33
37
 
34
- new(coerced_collection, parent, name)
38
+ new(coerced_collection, parent, name)
35
39
 
36
- elsif collection.is_a?(Vedeu::Views::Stream)
37
- new([collection], parent, name)
40
+ elsif collection.is_a?(Vedeu::Views::Stream)
41
+ new([collection], parent, name)
38
42
 
39
- elsif collection.is_a?(Vedeu::Views::Chars)
40
- return new([], parent, name) if collection.empty?
43
+ elsif collection.is_a?(Vedeu::Views::Chars)
44
+ return new([], parent, name) if collection.empty?
41
45
 
42
- new([Vedeu::Views::Stream.new(value: collection)], parent, name)
46
+ new([Vedeu::Views::Stream.new(value: collection)], parent, name)
43
47
 
44
- elsif collection.is_a?(String)
45
- return new([], parent, name) if collection.empty?
48
+ elsif string?(collection)
49
+ return new([], parent, name) if collection.empty?
46
50
 
47
- new([Vedeu::Views::Stream.new(value: collection)], parent, name)
51
+ new([Vedeu::Views::Stream.new(value: collection)], parent, name)
48
52
 
49
- else
50
- raise Vedeu::Error::InvalidSyntax,
51
- 'Cannot coerce for Vedeu::View::Streams, as collection ' \
52
- "unrecognised. (#{collection.class.name})"
53
+ else
54
+ raise Vedeu::Error::InvalidSyntax,
55
+ 'Cannot coerce for Vedeu::View::Streams, as collection ' \
56
+ "unrecognised. (#{collection.class.name})"
53
57
 
58
+ end
54
59
  end
55
- end
60
+
61
+ end # Eigenclass
56
62
 
57
63
  alias streams value
58
64
 
@@ -21,7 +21,7 @@ module Vedeu
21
21
  }
22
22
  let(:colour) { {} }
23
23
  let(:_name) { '' }
24
- let(:position) {}
24
+ let(:position) { Vedeu::Geometries::Position.new(1, 1) }
25
25
  let(:style) { '' }
26
26
  let(:_value) { '' }
27
27
 
@@ -47,7 +47,9 @@ module Vedeu
47
47
  it { subject.must_equal(true) }
48
48
 
49
49
  context 'when different to other' do
50
- let(:other) { described.new(value: 'b') }
50
+ let(:other) {
51
+ described.new(position: Vedeu::Geometries::Position.new(1, 2))
52
+ }
51
53
 
52
54
  it { subject.must_equal(false) }
53
55
  end
@@ -64,7 +66,6 @@ module Vedeu
64
66
  end
65
67
 
66
68
  describe '#to_h' do
67
- let(:position) { Vedeu::Geometries::Position.new(1, 1) }
68
69
  let(:colour) { Vedeu::Colours::Colour.new(background: '#000000') }
69
70
  let(:expected) {
70
71
  {
@@ -101,7 +102,8 @@ module Vedeu
101
102
  end
102
103
 
103
104
  describe '#to_s' do
104
- let(:_value) { 'a' }
105
+ let(:position) {}
106
+ let(:_value) { 'a' }
105
107
 
106
108
  subject { instance.to_s }
107
109
 
@@ -63,6 +63,22 @@ module Vedeu
63
63
  end
64
64
  end
65
65
 
66
+ describe '#array?' do
67
+ let(:_value) {}
68
+
69
+ subject { instance.array?(_value) }
70
+
71
+ context 'when the value is an Array' do
72
+ let(:_value) { [:hydrogen] }
73
+
74
+ it { subject.must_equal(true) }
75
+ end
76
+
77
+ context 'when the value is not an Array' do
78
+ it { subject.must_equal(false) }
79
+ end
80
+ end
81
+
66
82
  describe '#boolean' do
67
83
  subject { instance.boolean(_value) }
68
84
 
@@ -264,12 +264,8 @@ module Vedeu
264
264
  describe '#log_except' do
265
265
  it 'sets the options to the desired value' do
266
266
  configuration = Vedeu.configure { log_except :debug, :store }
267
- configuration.log_except.must_equal([:debug, :store])
268
- end
269
-
270
- it 'sets the options to the desired value' do
271
- configuration = Vedeu.configure { log_except [:debug, :info] }
272
- configuration.log_except.must_equal([:debug, :info])
267
+ configuration.log_except.must_include(:debug)
268
+ configuration.log_except.must_include(:store)
273
269
  end
274
270
  end
275
271
 
@@ -278,11 +274,6 @@ module Vedeu
278
274
  configuration = Vedeu.configure { log_only :debug, :store }
279
275
  configuration.log_only.must_equal([:debug, :store])
280
276
  end
281
-
282
- it 'sets the options to the desired value' do
283
- configuration = Vedeu.configure { log_only [:debug, :info] }
284
- configuration.log_only.must_equal([:debug, :info])
285
- end
286
277
  end
287
278
 
288
279
  describe '#renderer' do
@@ -107,7 +107,8 @@ module Vedeu
107
107
  end
108
108
  end
109
109
 
110
- it { described.log_except.must_equal([:timer, :event]) }
110
+ it { described.log_except.must_include(:timer) }
111
+ it { described.log_except.must_include(:event) }
111
112
  end
112
113
  end
113
114
 
@@ -123,49 +124,76 @@ module Vedeu
123
124
  end
124
125
  end
125
126
 
126
- it { described.log_only.must_equal([:timer, :event]) }
127
+ it { described.log_only.must_include(:timer) }
128
+ it { described.log_only.must_include(:event) }
127
129
  end
128
130
  end
129
131
 
130
- describe '.loggable?' do
131
- let(:type) { :hydrogen }
132
+ describe '.log_types' do
133
+ subject { described.log_types }
134
+
135
+ it { subject.must_be_instance_of(Hash) }
136
+ end
132
137
 
138
+ describe '.loggable?' do
133
139
  subject { described.loggable?(type) }
134
140
 
135
- context 'when the type exists in log_only and log_except' do
136
- before do
137
- described.stubs(:log_only).returns([:hydrogen])
138
- described.stubs(:log_except).returns([:hydrogen])
139
- end
141
+ context 'when the type is invalid' do
142
+ let(:type) { :hydrogen }
140
143
 
141
- it { subject.must_equal(true) }
144
+ it { subject.must_equal(false) }
142
145
  end
143
146
 
144
- context 'when the type exists in log_only' do
145
- before do
146
- described.stubs(:log_only).returns([:hydrogen])
147
- described.stubs(:log_except).returns([])
147
+ context 'when the type is valid' do
148
+ let(:type) { :debug }
149
+
150
+ context 'when log_only and log_except are both empty' do
151
+ it { subject.must_equal(true) }
148
152
  end
149
153
 
150
- it { subject.must_equal(true) }
151
- end
154
+ context 'when log_only contains entries' do
155
+ context 'when log_only includes the type' do
156
+ before do
157
+ Vedeu.configure do
158
+ log_only [:info, :debug, :error]
159
+ end
160
+ end
152
161
 
153
- context 'when the type exists in log_except' do
154
- before do
155
- described.stubs(:log_only).returns([])
156
- described.stubs(:log_except).returns([:hydrogen])
157
- end
162
+ it { subject.must_equal(true) }
163
+ end
158
164
 
159
- it { subject.must_equal(false) }
160
- end
165
+ context 'when log_only does not include the type' do
166
+ before do
167
+ Vedeu.configure do
168
+ log_only [:info, :error]
169
+ end
170
+ end
161
171
 
162
- context 'when the type does not exist in either' do
163
- before do
164
- described.stubs(:log_only).returns([])
165
- described.stubs(:log_except).returns([])
172
+ it { subject.must_equal(false) }
173
+ end
166
174
  end
167
175
 
168
- it { subject.must_equal(true) }
176
+ context 'when log_except contains entries' do
177
+ context 'when log_except includes the type' do
178
+ before do
179
+ Vedeu.configure do
180
+ log_except [:info, :debug, :error]
181
+ end
182
+ end
183
+
184
+ it { subject.must_equal(false) }
185
+ end
186
+
187
+ context 'when log_except does not include the type' do
188
+ before do
189
+ Vedeu.configure do
190
+ log_only [:info, :error]
191
+ end
192
+ end
193
+
194
+ it { subject.must_equal(false) }
195
+ end
196
+ end
169
197
  end
170
198
  end
171
199
 
@@ -16,7 +16,7 @@ module Vedeu
16
16
  end
17
17
 
18
18
  def add(model)
19
- if storage.is_a?(Hash)
19
+ if hash?(storage)
20
20
  @storage = in_memory.merge!(model)
21
21
 
22
22
  else
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vedeu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.13
4
+ version: 0.8.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Laking
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-02-07 00:00:00.000000000 Z
11
+ date: 2016-02-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: guard
@@ -783,10 +783,10 @@ files:
783
783
  - lib/vedeu/presentation/styles.rb
784
784
  - lib/vedeu/renderers/all.rb
785
785
  - lib/vedeu/renderers/escape.rb
786
- - lib/vedeu/renderers/file.rb
787
786
  - lib/vedeu/renderers/html.rb
788
787
  - lib/vedeu/renderers/json.rb
789
- - lib/vedeu/renderers/options.rb
788
+ - lib/vedeu/renderers/support/file.rb
789
+ - lib/vedeu/renderers/support/options.rb
790
790
  - lib/vedeu/renderers/templates/html_renderer.vedeu
791
791
  - lib/vedeu/renderers/terminal.rb
792
792
  - lib/vedeu/renderers/text.rb
@@ -1010,10 +1010,10 @@ files:
1010
1010
  - test/lib/vedeu/presentation/styles_test.rb
1011
1011
  - test/lib/vedeu/renderers/all_test.rb
1012
1012
  - test/lib/vedeu/renderers/escape_test.rb
1013
- - test/lib/vedeu/renderers/file_test.rb
1014
1013
  - test/lib/vedeu/renderers/html_test.rb
1015
1014
  - test/lib/vedeu/renderers/json_test.rb
1016
- - test/lib/vedeu/renderers/options_test.rb
1015
+ - test/lib/vedeu/renderers/support/file_test.rb
1016
+ - test/lib/vedeu/renderers/support/options_test.rb
1017
1017
  - test/lib/vedeu/renderers/terminal_test.rb
1018
1018
  - test/lib/vedeu/renderers/text_test.rb
1019
1019
  - test/lib/vedeu/repositories/assemblage_test.rb
@@ -1275,10 +1275,10 @@ test_files:
1275
1275
  - test/lib/vedeu/presentation/styles_test.rb
1276
1276
  - test/lib/vedeu/renderers/all_test.rb
1277
1277
  - test/lib/vedeu/renderers/escape_test.rb
1278
- - test/lib/vedeu/renderers/file_test.rb
1279
1278
  - test/lib/vedeu/renderers/html_test.rb
1280
1279
  - test/lib/vedeu/renderers/json_test.rb
1281
- - test/lib/vedeu/renderers/options_test.rb
1280
+ - test/lib/vedeu/renderers/support/file_test.rb
1281
+ - test/lib/vedeu/renderers/support/options_test.rb
1282
1282
  - test/lib/vedeu/renderers/terminal_test.rb
1283
1283
  - test/lib/vedeu/renderers/text_test.rb
1284
1284
  - test/lib/vedeu/repositories/assemblage_test.rb