vedeu 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/deps.md +23 -28
  3. data/lib/vedeu.rb +6 -4
  4. data/lib/vedeu/instrumentation.rb +0 -30
  5. data/lib/vedeu/models/attributes/interface_collection.rb +4 -2
  6. data/lib/vedeu/models/colour.rb +16 -30
  7. data/lib/vedeu/models/composition.rb +3 -8
  8. data/lib/vedeu/models/interface.rb +10 -21
  9. data/lib/vedeu/models/line.rb +3 -12
  10. data/lib/vedeu/models/stream.rb +4 -13
  11. data/lib/vedeu/models/style.rb +8 -20
  12. data/lib/vedeu/output/erb_parser.rb +6 -1
  13. data/lib/vedeu/output/render_interface.rb +9 -7
  14. data/lib/vedeu/output/view.rb +0 -6
  15. data/lib/vedeu/support/events.rb +2 -0
  16. data/lib/vedeu/support/helpers.rb +2 -0
  17. data/lib/vedeu/support/{persistence.rb → interface_store.rb} +9 -5
  18. data/lib/vedeu/support/{builder.rb → interface_template.rb} +6 -6
  19. data/lib/vedeu/support/menu.rb +2 -0
  20. data/lib/vedeu/support/queue.rb +3 -1
  21. data/test/lib/vedeu/models/attributes/interface_collection_test.rb +2 -2
  22. data/test/lib/vedeu/models/colour_test.rb +0 -33
  23. data/test/lib/vedeu/models/composition_test.rb +18 -38
  24. data/test/lib/vedeu/models/interface_test.rb +0 -15
  25. data/test/lib/vedeu/models/line_test.rb +0 -6
  26. data/test/lib/vedeu/models/stream_test.rb +0 -6
  27. data/test/lib/vedeu/models/style_test.rb +3 -40
  28. data/test/lib/vedeu/output/clear_interface_test.rb +2 -2
  29. data/test/lib/vedeu/output/render_interface_test.rb +2 -2
  30. data/test/lib/vedeu/support/{persistence_test.rb → interface_store_test.rb} +12 -12
  31. data/test/lib/vedeu/support/{builder_test.rb → interface_template_test.rb} +7 -7
  32. data/vedeu.gemspec +1 -2
  33. metadata +8 -25
  34. data/lib/vedeu/models/presentation.rb +0 -12
  35. data/test/lib/vedeu/models/presentation_test.rb +0 -32
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d4ccb72c3982e068887e6d1ac1e7dab94bfd25a9
4
- data.tar.gz: a92614c47e5b02740ed486f0ea76bf3c3bbb8b67
3
+ metadata.gz: 831514463a8bea83f3e218ddd59dccc347049e34
4
+ data.tar.gz: 2e6f495bc8b2bed85942a4335ff3b3bca86b07dd
5
5
  SHA512:
6
- metadata.gz: 056459bd4d73d522448bb43214420a255edf99dd58e3c5fc11d9b85da885a63badc6cc66e9cc5965e8815979f8d8e2cac846cef39154399dc4917e77bf93b375
7
- data.tar.gz: e503cbc2ef1e1714c1993b37490c0d8d2ebc1fef012ed707018051ec7dc1927f9f8d71bea4882d89484d67a0bbb85a3889cb0d5f0328952bb5dffcd91a26adbc
6
+ metadata.gz: 9de37b9db1bc093309b4465f0ca3104b29ff9e2870b3a0eca008a9040e2c3317063ea74f4b67436a32dc952310f7314e05751fade11f0f7532ba18fc7757499f
7
+ data.tar.gz: 0d681db9caef7bebfbb5fcb01b48f3a4890ef8d62d8594c8efb496d7a7c8189ca1f46a02a3794d5775a4ba56696feedddb0760727900f219467860fa7c7377b3
data/deps.md CHANGED
@@ -7,11 +7,6 @@ Application
7
7
  Process
8
8
  Terminal
9
9
 
10
- Builder
11
- Geometry
12
- Interface
13
- Persistence
14
-
15
10
  ClearInterface
16
11
 
17
12
  Collection
@@ -44,16 +39,21 @@ Input
44
39
 
45
40
  Interface
46
41
  ClearInterface
42
+ Colour
47
43
  Geometry
48
44
  LineCollection
49
- Presentation
50
45
  Queue
51
46
  RenderInterface
52
47
  Style
53
48
  Terminal
54
49
 
55
50
  InterfaceCollection
56
- Persistence
51
+ InterfaceStore
52
+
53
+ InterfaceTemplate
54
+ Geometry
55
+ Interface
56
+ InterfaceStore
57
57
 
58
58
  JSONParser
59
59
 
@@ -62,7 +62,7 @@ Launcher
62
62
  Configuration
63
63
 
64
64
  Line
65
- Presentation
65
+ Colour
66
66
  StreamCollection
67
67
  Style
68
68
 
@@ -81,12 +81,9 @@ Parser
81
81
  JSONParser
82
82
  MenuParser
83
83
 
84
- Persistence
84
+ InterfaceStore
85
85
  Interface
86
86
 
87
- Presentation
88
- Colour
89
-
90
87
  Process
91
88
  Parser
92
89
  Queue
@@ -97,7 +94,7 @@ RenderInterface
97
94
  ClearInterface
98
95
 
99
96
  Stream
100
- Presentation
97
+ Colour
101
98
  Style
102
99
 
103
100
  StreamCollection
@@ -132,10 +129,10 @@ Menu - orphaned
132
129
  Grouped
133
130
  ----------------------------------------------------------------------
134
131
 
135
- Builder
132
+ InterfaceTemplate
136
133
  Interface
137
134
  Geometry
138
- Persistence
135
+ InterfaceStore
139
136
 
140
137
  Launcher
141
138
  Application
@@ -148,9 +145,12 @@ Launcher
148
145
  Parser
149
146
  Composition
150
147
  InterfaceCollection
151
- Persistence
148
+ InterfaceStore
152
149
  Interface
153
150
  ClearInterface
151
+ Colour
152
+ Esc
153
+ Translator
154
154
  Geometry
155
155
  Esc
156
156
  Translator
@@ -160,27 +160,22 @@ Launcher
160
160
  LineCollection
161
161
  Collection
162
162
  Line
163
- Presentation
164
- Colour
165
- Esc
166
- Translator
163
+ Colour
164
+ Esc
165
+ Translator
167
166
  StreamCollection
168
167
  Collection
169
168
  Stream
170
- Presentation
171
- Colour
172
- Esc
173
- Translator
169
+ Colour
170
+ Esc
171
+ Translator
174
172
  Style
175
173
  Esc
176
174
  Translator
177
175
  Style
178
176
  Esc
179
177
  Translator
180
- Presentation
181
- Colour
182
- Esc
183
- Translator
178
+
184
179
  Queue
185
180
  RenderInterface
186
181
  ClearInterface
@@ -1,13 +1,15 @@
1
1
  require 'vedeu/instrumentation'
2
- require 'vedeu/support/builder'
2
+ require 'vedeu/support/interface_template'
3
3
  require 'vedeu/support/events'
4
- require 'vedeu/support/persistence'
4
+ require 'vedeu/support/interface_store'
5
5
 
6
6
  require 'vedeu/support/geometry'
7
7
  require 'vedeu/support/menu'
8
8
  require 'vedeu/output/view'
9
9
  require 'vedeu/launcher'
10
10
 
11
+ # Todo: mutation (events)
12
+
11
13
  module Vedeu
12
14
  # :nocov:
13
15
  def self.debug?
@@ -18,7 +20,7 @@ module Vedeu
18
20
 
19
21
  module API
20
22
  def interface(name, &block)
21
- Builder.build(name, &block)
23
+ InterfaceTemplate.save(name, &block)
22
24
  end
23
25
 
24
26
  def on(name, delay = 0, &block)
@@ -32,7 +34,7 @@ module Vedeu
32
34
  alias_method :run, :trigger
33
35
 
34
36
  def view(name)
35
- Persistence.query(name)
37
+ InterfaceStore.query(name)
36
38
  end
37
39
  end
38
40
 
@@ -1,6 +1,5 @@
1
1
  require 'date'
2
2
  require 'logger'
3
- # require 'ruby-prof'
4
3
 
5
4
  require 'vedeu'
6
5
 
@@ -30,35 +29,6 @@ module Vedeu
30
29
  end
31
30
  end
32
31
 
33
- # class Profile
34
- # def self.call(filename = 'profile.html', &block)
35
- # new(filename).profile(&block)
36
- # end
37
-
38
- # def initialize(filename)
39
- # @filename = filename
40
- # end
41
-
42
- # def profile(&block)
43
- # RubyProf.start
44
-
45
- # yield
46
-
47
- # result = RubyProf.stop.eliminate_methods!([/^Array/, /^Hash/])
48
-
49
- # File.open(filename, 'w') do |file|
50
- # RubyProf::CallStackPrinter.new(result).print(file)
51
- # RubyProf::GraphPrinter.new(result).print(file)
52
- # end
53
- # end
54
-
55
- # private
56
-
57
- # def filename
58
- # Vedeu.root_path + '/tmp/' + @filename
59
- # end
60
- # end
61
-
62
32
  class Trace
63
33
  def self.call(options = {})
64
34
  new(options).trace
@@ -1,6 +1,8 @@
1
1
  require 'virtus'
2
2
 
3
- require 'vedeu/support/persistence'
3
+ require 'vedeu/support/interface_store'
4
+
5
+ # Todo: mutation (persistence)
4
6
 
5
7
  module Vedeu
6
8
  class InterfaceCollection < Virtus::Attribute
@@ -8,7 +10,7 @@ module Vedeu
8
10
  return [] if values.nil? || values.empty?
9
11
 
10
12
  [values].flatten.map do |value|
11
- Persistence.update(value.fetch(:name, nil), value)
13
+ InterfaceStore.update(value.fetch(:name, nil), value)
12
14
  end
13
15
  end
14
16
  end
@@ -1,46 +1,32 @@
1
- require 'json'
2
1
  require 'virtus'
3
2
 
4
3
  require 'vedeu/support/esc'
5
4
 
6
5
  module Vedeu
7
- class Colour
8
- include Virtus.model
9
-
10
- attribute :foreground, String, default: ''
11
- attribute :background, String, default: ''
12
-
13
- def foreground
14
- @fg ||= Esc.foreground_colour(css_foreground)
15
- end
6
+ class Background < Virtus::Attribute
7
+ def coerce(value)
8
+ return '' if value.nil? || value.empty?
16
9
 
17
- def background
18
- @bg ||= Esc.background_colour(css_background)
10
+ Esc.background_colour(value)
19
11
  end
12
+ end
20
13
 
21
- def to_json(*args)
22
- as_hash.to_json
23
- end
14
+ class Foreground < Virtus::Attribute
15
+ def coerce(value)
16
+ return '' if value.nil? || value.empty?
24
17
 
25
- def to_s
26
- foreground + background
18
+ Esc.foreground_colour(value)
27
19
  end
20
+ end
28
21
 
29
- private
30
-
31
- def as_hash
32
- {
33
- foreground: css_foreground,
34
- background: css_background,
35
- }
36
- end
22
+ class Colour
23
+ include Virtus.model
37
24
 
38
- def css_foreground
39
- @foreground
40
- end
25
+ attribute :foreground, Foreground, default: ''
26
+ attribute :background, Background, default: ''
41
27
 
42
- def css_background
43
- @background
28
+ def to_s
29
+ foreground + background
44
30
  end
45
31
  end
46
32
  end
@@ -1,8 +1,9 @@
1
- require 'json'
2
1
  require 'virtus'
3
2
 
4
3
  require 'vedeu/models/attributes/interface_collection'
5
4
 
5
+ # Todo: mutation (interfaces)
6
+
6
7
  module Vedeu
7
8
  class Composition
8
9
  include Virtus.model
@@ -14,13 +15,7 @@ module Vedeu
14
15
  end
15
16
 
16
17
  def enqueue
17
- interfaces.map { |interface| interface.enqueue }
18
- end
19
-
20
- def to_json
21
- {
22
- interfaces: interfaces
23
- }.to_json
18
+ interfaces.map(&:enqueue)
24
19
  end
25
20
 
26
21
  def to_s
@@ -1,9 +1,8 @@
1
- require 'json'
2
1
  require 'virtus'
3
2
 
4
3
  require 'vedeu'
5
4
  require 'vedeu/models/attributes/line_collection'
6
- require 'vedeu/models/presentation'
5
+ require 'vedeu/models/colour'
7
6
  require 'vedeu/models/style'
8
7
  require 'vedeu/output/clear_interface'
9
8
  require 'vedeu/output/render_interface'
@@ -11,15 +10,17 @@ require 'vedeu/support/geometry'
11
10
  require 'vedeu/support/queue'
12
11
  require 'vedeu/support/terminal'
13
12
 
13
+ # Todo: mutation (events, current)
14
+
14
15
  module Vedeu
15
16
  class Interface
16
17
  include Vedeu::Queue
17
18
  include Virtus.model
18
- include Presentation
19
- include Style
20
19
 
21
20
  attribute :name, String
22
21
  attribute :lines, LineCollection
22
+ attribute :colour, Colour, default: Colour.new
23
+ attribute :style, Style, default: ''
23
24
  attribute :y, Integer, default: 1
24
25
  attribute :x, Integer, default: 1
25
26
  attribute :width, Integer, default: Terminal.width
@@ -27,12 +28,14 @@ module Vedeu
27
28
  attribute :current, String, default: ''
28
29
  attribute :cursor, Boolean, default: true
29
30
  attribute :centred, Boolean, default: false
30
- attribute :delay, Float, default: 0.0
31
+ attribute :delay, Float, default: 0
31
32
 
32
33
  def initialize(attributes = {})
33
- Vedeu.events.on(:refresh, attributes[:delay]) { refresh }
34
-
35
34
  super
35
+
36
+ Vedeu.events.on(:refresh, self.delay) { refresh }
37
+
38
+ self
36
39
  end
37
40
 
38
41
  def clear
@@ -67,20 +70,6 @@ module Vedeu
67
70
  self.current
68
71
  end
69
72
 
70
- def to_json(*args)
71
- {
72
- colour: colour,
73
- style: style_original,
74
- name: name,
75
- lines: lines,
76
- y: y,
77
- x: x,
78
- width: width,
79
- height: height,
80
- cursor: cursor
81
- }.to_json
82
- end
83
-
84
73
  def to_s
85
74
  RenderInterface.call(self)
86
75
  end
@@ -1,26 +1,17 @@
1
- require 'json'
2
1
  require 'virtus'
3
2
 
4
3
  require 'vedeu/models/attributes/stream_collection'
5
- require 'vedeu/models/presentation'
4
+ require 'vedeu/models/colour'
6
5
  require 'vedeu/models/style'
7
6
 
8
7
  module Vedeu
9
8
  class Line
10
9
  include Virtus.model
11
- include Presentation
12
- include Style
13
10
 
11
+ attribute :colour, Colour, default: Colour.new
14
12
  attribute :model, Hash
15
13
  attribute :streams, StreamCollection
16
-
17
- def to_json
18
- {
19
- colour: colour,
20
- style: style_original,
21
- streams: streams
22
- }.to_json
23
- end
14
+ attribute :style, Style, default: ''
24
15
 
25
16
  def to_s
26
17
  [colour, style, streams].join
@@ -1,24 +1,15 @@
1
- require 'json'
2
1
  require 'virtus'
3
2
 
4
- require 'vedeu/models/presentation'
3
+ require 'vedeu/models/colour'
5
4
  require 'vedeu/models/style'
6
5
 
7
6
  module Vedeu
8
7
  class Stream
9
8
  include Virtus.model
10
- include Presentation
11
- include Style
12
9
 
13
- attribute :text, String, default: ''
14
-
15
- def to_json
16
- {
17
- colour: colour,
18
- style: style_original,
19
- text: text
20
- }.to_json
21
- end
10
+ attribute :colour, Colour, default: Colour.new
11
+ attribute :style, Style, default: ''
12
+ attribute :text, String, default: ''
22
13
 
23
14
  def to_s(options = {})
24
15
  [colour, style, text].join
@@ -1,31 +1,19 @@
1
+ require 'virtus'
2
+
1
3
  require 'vedeu/support/esc'
2
4
 
3
5
  module Vedeu
4
- module Style
5
- def style
6
- @_style ||= if no_style?
7
- ''
8
-
9
- else
10
- @style.map { |s| Esc.string(s) }.join
6
+ class Style < Virtus::Attribute
7
+ def coerce(value_or_values)
8
+ return '' if value_or_values.nil? || value_or_values.empty?
11
9
 
12
- end
13
- end
14
-
15
- def style_original
16
- @_original ||= if no_style?
17
- ''
10
+ if value_or_values.is_a?(::Array)
11
+ value_or_values.map { |s| Esc.string(s) }.join
18
12
 
19
13
  else
20
- @style
14
+ Esc.string(value_or_values)
21
15
 
22
16
  end
23
17
  end
24
-
25
- private
26
-
27
- def no_style?
28
- @style.nil? || @style.empty?
29
- end
30
18
  end
31
19
  end
@@ -16,7 +16,12 @@ module Vedeu
16
16
 
17
17
  def parse
18
18
  {
19
- interfaces: [{ name: interface, lines: TextAdaptor.adapt(erb_output) }]
19
+ interfaces: [
20
+ {
21
+ name: interface,
22
+ lines: TextAdaptor.adapt(erb_output)
23
+ }
24
+ ]
20
25
  }
21
26
  end
22
27
 
@@ -34,18 +34,20 @@ module Vedeu
34
34
  if (line_length += stream.text.size) >= width
35
35
  remainder = width - line_length
36
36
 
37
- new_stream = Stream.new(text: truncate(stream.text, remainder),
38
- style: stream.style,
39
- colour: stream.colour)
40
- processed_streams << new_stream
37
+ processed_streams << Stream.new(
38
+ text: truncate(stream.text, remainder),
39
+ style: stream.style,
40
+ colour: stream.colour)
41
+
41
42
  else
42
43
  processed_streams << stream
44
+
43
45
  end
44
46
  end
45
47
 
46
- new_line = Line.new(streams: processed_streams,
47
- style: line.style,
48
- colour: line.colour)
48
+ Line.new(streams: processed_streams,
49
+ style: line.style,
50
+ colour: line.colour)
49
51
  end
50
52
  end
51
53
  end
@@ -38,9 +38,3 @@ module Vedeu
38
38
  end
39
39
  end
40
40
  end
41
-
42
- # ERBParser: { :interface, :path, :object }
43
- # RawParser: { 'interface_name' => String|Array }
44
- # { :interface_name => String|Array }
45
- # JSONParser: output (string which is converted into a hash)
46
- # MenuParser: ['interface_name', Vedeu::Menu instance]
@@ -1,3 +1,5 @@
1
+ # Todo: mutation (events)
2
+
1
3
  module Vedeu
2
4
  class Events
3
5
  def initialize(&block)
@@ -1,6 +1,8 @@
1
1
  require 'vedeu/support/esc'
2
2
  require 'vedeu/models/colour'
3
3
 
4
+ # Todo: style method (actually whole thing)
5
+
4
6
  module Vedeu
5
7
  module Helpers
6
8
  def foreground(value, &block)
@@ -1,27 +1,31 @@
1
1
  require 'vedeu/models/interface'
2
2
 
3
+ # Todo: mutation (persistence)
4
+
3
5
  module Vedeu
4
6
  EntityNotFound = Class.new(StandardError)
5
7
 
6
- module Persistence
8
+ module InterfaceStore
7
9
  extend self
8
10
 
9
11
  def update(name, attributes = {})
10
12
  interface = query(name)
11
13
  interface.attributes = attributes
12
14
  interface
15
+
13
16
  rescue EntityNotFound
14
17
  create(attributes)
18
+
15
19
  end
16
20
 
17
21
  def create(attributes)
18
22
  storage.store(attributes[:name], Interface.new(attributes))
19
23
  end
20
24
 
21
- def query(value)
22
- storage.select do |name, result|
23
- return result if name == value
24
- end unless value.nil? || value.empty?
25
+ def query(interface_name)
26
+ storage.select do |name, interface|
27
+ return interface if name == interface_name
28
+ end unless interface_name.nil? || interface_name.empty?
25
29
 
26
30
  fail EntityNotFound, "Interface could not be found."
27
31
  end
@@ -1,20 +1,20 @@
1
1
  require 'vedeu/support/geometry'
2
- require 'vedeu/support/persistence'
2
+ require 'vedeu/support/interface_store'
3
3
 
4
4
  module Vedeu
5
- class Builder
6
- def self.build(name, &block)
7
- new(name).build(&block)
5
+ class InterfaceTemplate
6
+ def self.save(name, &block)
7
+ new(name).save(&block)
8
8
  end
9
9
 
10
10
  def initialize(name)
11
11
  @name = name.to_s
12
12
  end
13
13
 
14
- def build(&block)
14
+ def save(&block)
15
15
  self.instance_eval(&block)
16
16
 
17
- Persistence.create(attributes)
17
+ InterfaceStore.create(attributes)
18
18
  end
19
19
 
20
20
  private
@@ -1,6 +1,8 @@
1
1
  require 'vedeu'
2
2
  require 'vedeu/support/events'
3
3
 
4
+ # Todo: mutation (events, menu)
5
+
4
6
  module Vedeu
5
7
  class Menu
6
8
  def initialize(collection)
@@ -1,3 +1,5 @@
1
+ # Todo: mutation (queue)
2
+
1
3
  module Vedeu
2
4
  module Queue
3
5
  extend self
@@ -13,7 +15,7 @@ module Vedeu
13
15
  end
14
16
 
15
17
  def enqueued?
16
- store.size > 0
18
+ store.any?
17
19
  end
18
20
 
19
21
  def reset
@@ -1,11 +1,11 @@
1
1
  require 'test_helper'
2
- require 'vedeu/models/attributes/interface_collection'
3
2
  require 'vedeu/models/composition'
3
+ require 'vedeu/models/attributes/interface_collection'
4
4
 
5
5
  module Vedeu
6
6
  describe InterfaceCollection do
7
7
  describe '#coerce' do
8
- before { Persistence.reset }
8
+ before { InterfaceStore.reset }
9
9
 
10
10
  it 'returns an empty collection when there are no interfaces' do
11
11
  composition = Composition.new
@@ -27,39 +27,6 @@ module Vedeu
27
27
  end
28
28
  end
29
29
 
30
- describe '#to_json' do
31
- it 'returns the model as JSON' do
32
- Colour.new({
33
- foreground: '#ff0000',
34
- background: '#000000'
35
- }).to_json.must_equal(
36
- "{\"foreground\":\"#ff0000\",\"background\":\"#000000\"}"
37
- )
38
- end
39
-
40
- it 'returns an escape sequence when the foreground is missing' do
41
- Colour.new({
42
- background: '#000000'
43
- }).to_json.must_equal(
44
- "{\"foreground\":\"\",\"background\":\"#000000\"}"
45
- )
46
- end
47
-
48
- it 'returns an escape sequence when the background is missing' do
49
- Colour.new({
50
- foreground: '#ff0000',
51
- }).to_json.must_equal(
52
- "{\"foreground\":\"#ff0000\",\"background\":\"\"}"
53
- )
54
- end
55
-
56
- it 'returns an empty string when both are missing' do
57
- Colour.new.to_json.must_equal(
58
- "{\"foreground\":\"\",\"background\":\"\"}"
59
- )
60
- end
61
- end
62
-
63
30
  describe '#to_s' do
64
31
  it 'returns an escape sequence' do
65
32
  Colour.new({
@@ -1,6 +1,6 @@
1
1
  require 'test_helper'
2
2
  require 'vedeu/models/composition'
3
- require 'vedeu/support/persistence'
3
+ require 'vedeu/support/interface_store'
4
4
 
5
5
  module Vedeu
6
6
  describe Composition do
@@ -31,10 +31,10 @@ module Vedeu
31
31
  }
32
32
 
33
33
  Composition.enqueue(attributes)
34
- Persistence
34
+ InterfaceStore
35
35
  .query('Composition.enqueue_1').dequeue
36
36
  .must_match(/bd459118e6175689e4394e242debc2ae/)
37
- Persistence
37
+ InterfaceStore
38
38
  .query('Composition.enqueue_2').dequeue
39
39
  .must_match(/837acb2cb2ea3ef359257851142a7830/)
40
40
  end
@@ -56,29 +56,9 @@ module Vedeu
56
56
  end
57
57
  end
58
58
 
59
- describe '#to_json' do
60
- it 'returns the model as JSON' do
61
- attributes = {
62
- interfaces: [
63
- {
64
- name: 'Composition#to_json',
65
- width: 5,
66
- height: 5,
67
- colour: {
68
- foreground: '#ffff33',
69
- background: '#ffff77'
70
- }
71
- }
72
- ]
73
- }
74
-
75
- Composition.new(attributes).to_json.must_equal("{\"interfaces\":[{\"colour\":{\"foreground\":\"\#ffff33\",\"background\":\"\#ffff77\"},\"style\":\"\",\"name\":\"Composition#to_json\",\"lines\":[],\"y\":1,\"x\":1,\"width\":5,\"height\":5,\"cursor\":true}]}")
76
- end
77
- end
78
-
79
59
  describe '#to_s' do
80
60
  it 'returns the stringified content for a single interface, single line, single stream' do
81
- Persistence.create({ name: 'int1_lin1_str1', y: 3, x: 3, width: 15, height: 3 })
61
+ InterfaceStore.create({ name: 'int1_lin1_str1', y: 3, x: 3, width: 15, height: 3 })
82
62
  json = File.read('test/support/json/int1_lin1_str1.json')
83
63
  attributes = JSON.load(json, nil, symbolize_names: true)
84
64
 
@@ -91,7 +71,7 @@ module Vedeu
91
71
  end
92
72
 
93
73
  it 'returns the stringified content for a single interface, single line, multiple streams' do
94
- Persistence.create({ name: 'int1_lin1_str3', y: 3, x: 3, width: 30, height: 3 })
74
+ InterfaceStore.create({ name: 'int1_lin1_str3', y: 3, x: 3, width: 30, height: 3 })
95
75
  json = File.read('test/support/json/int1_lin1_str3.json')
96
76
  attributes = JSON.load(json, nil, symbolize_names: true)
97
77
 
@@ -104,7 +84,7 @@ module Vedeu
104
84
  end
105
85
 
106
86
  it 'returns the stringified content for a single interface, multiple lines, single stream' do
107
- Persistence.create({ name: 'int1_lin2_str1', y: 3, x: 3, width: 15, height: 3 })
87
+ InterfaceStore.create({ name: 'int1_lin2_str1', y: 3, x: 3, width: 15, height: 3 })
108
88
  json = File.read('test/support/json/int1_lin2_str1.json')
109
89
  attributes = JSON.load(json, nil, symbolize_names: true)
110
90
 
@@ -118,7 +98,7 @@ module Vedeu
118
98
  end
119
99
 
120
100
  it 'returns the stringified content for a single interface, multiple lines, multiple streams' do
121
- Persistence.create({ name: 'int1_lin2_str3', y: 3, x: 3, width: 30, height: 3 })
101
+ InterfaceStore.create({ name: 'int1_lin2_str3', y: 3, x: 3, width: 30, height: 3 })
122
102
  json = File.read('test/support/json/int1_lin2_str3.json')
123
103
  attributes = JSON.load(json, nil, symbolize_names: true)
124
104
 
@@ -134,7 +114,7 @@ module Vedeu
134
114
  it 'returns the stringified content for a single interface, multiple lines, multiple streams, streams contain styles' do
135
115
  json = File.read('test/support/json/int1_lin2_str3_styles.json')
136
116
  attributes = JSON.load(json, nil, symbolize_names: true)
137
- Persistence.create({ name: 'int1_lin2_str3_styles', y: 3, x: 3, width: 30, height: 3 })
117
+ InterfaceStore.create({ name: 'int1_lin2_str3_styles', y: 3, x: 3, width: 30, height: 3 })
138
118
 
139
119
  Composition.new(attributes).to_s.must_equal(
140
120
  "\e[3;3H \e[3;3H" \
@@ -145,8 +125,8 @@ module Vedeu
145
125
  end
146
126
 
147
127
  it 'returns the stringified content for multiple interfaces, single line, single stream' do
148
- Persistence.create({ name: 'int2_lin1_str1_1', y: 3, x: 3, width: 15, height: 3 })
149
- Persistence.create({ name: 'int2_lin1_str1_2', y: 6, x: 6, width: 15, height: 3 })
128
+ InterfaceStore.create({ name: 'int2_lin1_str1_1', y: 3, x: 3, width: 15, height: 3 })
129
+ InterfaceStore.create({ name: 'int2_lin1_str1_2', y: 6, x: 6, width: 15, height: 3 })
150
130
  json = File.read('test/support/json/int2_lin1_str1.json')
151
131
  attributes = JSON.load(json, nil, symbolize_names: true)
152
132
 
@@ -163,8 +143,8 @@ module Vedeu
163
143
  end
164
144
 
165
145
  it 'returns the stringified content for multiple interfaces, single line, multiple streams' do
166
- Persistence.create({ name: 'int2_lin1_str3_1', y: 3, x: 3, width: 30, height: 3 })
167
- Persistence.create({ name: 'int2_lin1_str3_2', y: 6, x: 6, width: 30, height: 3 })
146
+ InterfaceStore.create({ name: 'int2_lin1_str3_1', y: 3, x: 3, width: 30, height: 3 })
147
+ InterfaceStore.create({ name: 'int2_lin1_str3_2', y: 6, x: 6, width: 30, height: 3 })
168
148
  json = File.read('test/support/json/int2_lin1_str3.json')
169
149
  attributes = JSON.load(json, nil, symbolize_names: true)
170
150
 
@@ -181,8 +161,8 @@ module Vedeu
181
161
  end
182
162
 
183
163
  it 'returns the stringified content for multiple interfaces, multiple lines, single stream' do
184
- Persistence.create({ name: 'int2_lin2_str1_1', y: 3, x: 3, width: 15, height: 3 })
185
- Persistence.create({ name: 'int2_lin2_str1_2', y: 6, x: 6, width: 15, height: 3 })
164
+ InterfaceStore.create({ name: 'int2_lin2_str1_1', y: 3, x: 3, width: 15, height: 3 })
165
+ InterfaceStore.create({ name: 'int2_lin2_str1_2', y: 6, x: 6, width: 15, height: 3 })
186
166
  json = File.read('test/support/json/int2_lin2_str1.json')
187
167
  attributes = JSON.load(json, nil, symbolize_names: true)
188
168
 
@@ -201,8 +181,8 @@ module Vedeu
201
181
  end
202
182
 
203
183
  it 'returns the stringified content for multiple interfaces, multiple lines, multiple streams' do
204
- Persistence.create({ name: 'int2_lin2_str3_1', y: 3, x: 3, width: 30, height: 3 })
205
- Persistence.create({ name: 'int2_lin2_str3_2', y: 6, x: 6, width: 30, height: 3 })
184
+ InterfaceStore.create({ name: 'int2_lin2_str3_1', y: 3, x: 3, width: 30, height: 3 })
185
+ InterfaceStore.create({ name: 'int2_lin2_str3_2', y: 6, x: 6, width: 30, height: 3 })
206
186
  json = File.read('test/support/json/int2_lin2_str3.json')
207
187
  attributes = JSON.load(json, nil, symbolize_names: true)
208
188
 
@@ -221,8 +201,8 @@ module Vedeu
221
201
  end
222
202
 
223
203
  it 'returns the stringified content for multiple interfaces, multiple lines, multiple streams, streams contain styles' do
224
- Persistence.create({ name: 'int2_lin2_str3_styles_1', y: 3, x: 3, width: 30, height: 3 })
225
- Persistence.create({ name: 'int2_lin2_str3_styles_2', y: 6, x: 6, width: 30, height: 3 })
204
+ InterfaceStore.create({ name: 'int2_lin2_str3_styles_1', y: 3, x: 3, width: 30, height: 3 })
205
+ InterfaceStore.create({ name: 'int2_lin2_str3_styles_2', y: 6, x: 6, width: 30, height: 3 })
226
206
  json = File.read('test/support/json/int2_lin2_str3_styles.json')
227
207
  attributes = JSON.load(json, nil, symbolize_names: true)
228
208
 
@@ -212,20 +212,5 @@ module Vedeu
212
212
  )
213
213
  end
214
214
  end
215
-
216
- describe '#to_json' do
217
- it 'returns an String' do
218
- Interface.new({
219
- name: '#to_json',
220
- lines: [],
221
- colour: {
222
- foreground: '#ff0000',
223
- background: '#000000'
224
- },
225
- width: 3,
226
- height: 3
227
- }).to_json.must_equal("{\"colour\":{\"foreground\":\"#ff0000\",\"background\":\"#000000\"},\"style\":\"\",\"name\":\"#to_json\",\"lines\":[],\"y\":1,\"x\":1,\"width\":3,\"height\":3,\"cursor\":true}")
228
- end
229
- end
230
215
  end
231
216
  end
@@ -27,12 +27,6 @@ module Vedeu
27
27
  line.streams.must_equal([])
28
28
  end
29
29
 
30
- describe '#to_json' do
31
- it 'returns a String' do
32
- line.to_json.must_equal("{\"colour\":{\"foreground\":\"#ff0000\",\"background\":\"#000000\"},\"style\":[\"normal\"],\"streams\":[]}")
33
- end
34
- end
35
-
36
30
  describe '#to_s' do
37
31
  it 'returns a String' do
38
32
  line.to_s.must_equal(
@@ -35,11 +35,5 @@ module Vedeu
35
35
  )
36
36
  end
37
37
  end
38
-
39
- describe '#to_json' do
40
- it 'returns a String' do
41
- stream.to_json.must_equal("{\"colour\":{\"foreground\":\"#ff0000\",\"background\":\"#000000\"},\"style\":[\"normal\"],\"text\":\"Some text\"}")
42
- end
43
- end
44
38
  end
45
39
  end
@@ -1,11 +1,11 @@
1
1
  require 'test_helper'
2
- require 'vedeu/models/presentation'
3
2
  require 'vedeu/models/style'
4
3
 
5
4
  module Vedeu
6
5
  class TestStyle
7
- include Presentation
8
- include Style
6
+ include Virtus.model
7
+
8
+ attribute :style, Style
9
9
  end
10
10
 
11
11
  describe Style do
@@ -45,42 +45,5 @@ module Vedeu
45
45
  model.style.must_equal('')
46
46
  end
47
47
  end
48
-
49
- describe '#style_original' do
50
- it 'returns an escape sequence for a single style' do
51
- model = TestStyle.new(style: 'normal')
52
- model.style_original.must_equal(['normal'])
53
- end
54
-
55
- it 'returns an escape sequence for multiple styles' do
56
- model = TestStyle.new(style: ['normal', 'underline'])
57
- model.style_original.must_equal(['normal', 'underline'])
58
- end
59
-
60
- it 'returns an empty string for an unknown style' do
61
- model = TestStyle.new(style: 'unknown')
62
- model.style_original.must_equal(['unknown'])
63
- end
64
-
65
- it 'has a style attribute' do
66
- model = TestStyle.new(style: ['normal'])
67
- model.style_original.must_equal(['normal'])
68
- end
69
-
70
- it 'returns an empty string for empty or nil' do
71
- model = TestStyle.new(style: '')
72
- model.style_original.must_equal([''])
73
- end
74
-
75
- it 'returns an empty string for empty or nil' do
76
- model = TestStyle.new(style: nil)
77
- model.style_original.must_equal('')
78
- end
79
-
80
- it 'returns an empty string for empty or nil' do
81
- model = TestStyle.new(style: [])
82
- model.style_original.must_equal('')
83
- end
84
- end
85
48
  end
86
49
  end
@@ -1,11 +1,11 @@
1
1
  require 'test_helper'
2
2
  require 'vedeu/output/clear_interface'
3
3
  require 'vedeu/models/interface'
4
- require 'vedeu/support/persistence'
4
+ require 'vedeu/support/interface_store'
5
5
 
6
6
  module Vedeu
7
7
  describe ClearInterface do
8
- before { Persistence.reset }
8
+ before { InterfaceStore.reset }
9
9
 
10
10
  describe '.call' do
11
11
  it 'returns the escape sequence to clear the whole interface' do
@@ -1,11 +1,11 @@
1
1
  require 'test_helper'
2
2
  require 'vedeu/output/render_interface'
3
3
  require 'vedeu/models/interface'
4
- require 'vedeu/support/persistence'
4
+ require 'vedeu/support/interface_store'
5
5
 
6
6
  module Vedeu
7
7
  describe RenderInterface do
8
- before { Persistence.reset }
8
+ before { InterfaceStore.reset }
9
9
 
10
10
  describe '.call' do
11
11
  it 'returns the content for the interface' do
@@ -1,50 +1,50 @@
1
1
  require 'test_helper'
2
- require 'vedeu/support/persistence'
2
+ require 'vedeu/support/interface_store'
3
3
 
4
4
  module Vedeu
5
- describe Persistence do
6
- before { Persistence.reset }
5
+ describe InterfaceStore do
6
+ before { InterfaceStore.reset }
7
7
 
8
8
  describe '.update' do
9
9
  it 'returns an Interface' do
10
- Persistence.update('dummy', { name: 'dumber' })
10
+ InterfaceStore.update('dummy', { name: 'dumber' })
11
11
  .must_be_instance_of(Interface)
12
12
  end
13
13
 
14
14
  it 'updates and returns the existing interface when the interface exists' do
15
- Persistence.update('dummy', { name: 'dumber' }).name
15
+ InterfaceStore.update('dummy', { name: 'dumber' }).name
16
16
  .must_equal('dumber')
17
17
  end
18
18
 
19
19
  it 'returns a new interface when the interface does not exist' do
20
- Persistence.update('dummy', { name: 'dumber' }).name
20
+ InterfaceStore.update('dummy', { name: 'dumber' }).name
21
21
  .must_equal('dumber')
22
22
  end
23
23
  end
24
24
 
25
25
  describe '#create' do
26
26
  it 'creates and returns the stored record' do
27
- Persistence.create({ name: 'dummy' })
27
+ InterfaceStore.create({ name: 'dummy' })
28
28
  .must_be_instance_of(Interface)
29
29
  end
30
30
  end
31
31
 
32
32
  describe '#query' do
33
33
  it 'returns the record when found' do
34
- Persistence.create({ name: 'hydrogen' })
34
+ InterfaceStore.create({ name: 'hydrogen' })
35
35
 
36
- Persistence.query('hydrogen').name.must_equal('hydrogen')
36
+ InterfaceStore.query('hydrogen').name.must_equal('hydrogen')
37
37
  end
38
38
 
39
39
  it 'raises an exception when the record cannot be found' do
40
- proc { Persistence.query('dummy') }.must_raise(EntityNotFound)
40
+ proc { InterfaceStore.query('dummy') }.must_raise(EntityNotFound)
41
41
  end
42
42
  end
43
43
 
44
44
  describe '#reset' do
45
45
  it 'deletes all records stored' do
46
- Persistence.create({ name: 'dumb' })
47
- Persistence.reset.must_equal({})
46
+ InterfaceStore.create({ name: 'dumb' })
47
+ InterfaceStore.reset.must_equal({})
48
48
  end
49
49
  end
50
50
  end
@@ -1,10 +1,10 @@
1
1
  require 'test_helper'
2
- require 'vedeu/support/builder'
2
+ require 'vedeu/support/interface_template'
3
3
 
4
4
  module Vedeu
5
- describe Builder do
5
+ describe InterfaceTemplate do
6
6
  it 'creates and stores a new interface' do
7
- interface = Builder.build('widget') do
7
+ interface = InterfaceTemplate.save('widget') do
8
8
  colour foreground: '#ff0000', background: '#5f0000'
9
9
  cursor false
10
10
  width 10
@@ -16,7 +16,7 @@ module Vedeu
16
16
 
17
17
  it 'overrides x and y when centred is true' do
18
18
  IO.console.stub :winsize, [10, 40] do
19
- interface = Builder.build('widget') do
19
+ interface = InterfaceTemplate.save('widget') do
20
20
  colour foreground: '#ff0000', background: '#5f0000'
21
21
  cursor false
22
22
  centred true
@@ -31,7 +31,7 @@ module Vedeu
31
31
  end
32
32
 
33
33
  it 'uses x and y when centred is false' do
34
- interface = Builder.build('widget') do
34
+ interface = InterfaceTemplate.save('widget') do
35
35
  colour foreground: '#ff0000', background: '#5f0000'
36
36
  cursor false
37
37
  centred false
@@ -46,14 +46,14 @@ module Vedeu
46
46
 
47
47
  it 'allows interfaces to share behaviour' do
48
48
  IO.console.stub :winsize, [10, 40] do
49
- main = Builder.build('main') do
49
+ main = InterfaceTemplate.save('main') do
50
50
  colour foreground: '#ff0000', background: '#000000'
51
51
  cursor false
52
52
  centred true
53
53
  width 10
54
54
  height 2
55
55
  end
56
- status = Builder.build('status') do
56
+ status = InterfaceTemplate.save('status') do
57
57
  colour foreground: 'aadd00', background: '#4040cc'
58
58
  cursor true
59
59
  centred true
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'vedeu'
7
- spec.version = '0.1.2'
7
+ spec.version = '0.1.3'
8
8
  spec.authors = ['Gavin Laking']
9
9
  spec.email = ['gavinlaking@gmail.com']
10
10
  spec.summary = %q{A terminal case of wonderland.}
@@ -24,7 +24,6 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency 'mocha', '1.1.0'
25
25
  spec.add_development_dependency 'pry', '0.10.0'
26
26
  spec.add_development_dependency 'rake', '10.3.2'
27
- spec.add_development_dependency 'ruby-prof', '0.15.1'
28
27
  spec.add_development_dependency 'simplecov', '0.9.0'
29
28
 
30
29
  spec.add_dependency 'virtus', '1.0.3'
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.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Laking
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-01 00:00:00.000000000 Z
11
+ date: 2014-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -122,20 +122,6 @@ dependencies:
122
122
  - - '='
123
123
  - !ruby/object:Gem::Version
124
124
  version: 10.3.2
125
- - !ruby/object:Gem::Dependency
126
- name: ruby-prof
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - '='
130
- - !ruby/object:Gem::Version
131
- version: 0.15.1
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - '='
137
- - !ruby/object:Gem::Version
138
- version: 0.15.1
139
125
  - !ruby/object:Gem::Dependency
140
126
  name: simplecov
141
127
  requirement: !ruby/object:Gem::Requirement
@@ -197,7 +183,6 @@ files:
197
183
  - lib/vedeu/models/composition.rb
198
184
  - lib/vedeu/models/interface.rb
199
185
  - lib/vedeu/models/line.rb
200
- - lib/vedeu/models/presentation.rb
201
186
  - lib/vedeu/models/stream.rb
202
187
  - lib/vedeu/models/style.rb
203
188
  - lib/vedeu/output/clear_interface.rb
@@ -208,14 +193,14 @@ files:
208
193
  - lib/vedeu/output/render_interface.rb
209
194
  - lib/vedeu/output/text_adaptor.rb
210
195
  - lib/vedeu/output/view.rb
211
- - lib/vedeu/support/builder.rb
212
196
  - lib/vedeu/support/esc.rb
213
197
  - lib/vedeu/support/events.rb
214
198
  - lib/vedeu/support/geometry.rb
215
199
  - lib/vedeu/support/helpers.rb
216
200
  - lib/vedeu/support/input.rb
201
+ - lib/vedeu/support/interface_store.rb
202
+ - lib/vedeu/support/interface_template.rb
217
203
  - lib/vedeu/support/menu.rb
218
- - lib/vedeu/support/persistence.rb
219
204
  - lib/vedeu/support/queue.rb
220
205
  - lib/vedeu/support/terminal.rb
221
206
  - lib/vedeu/support/translator.rb
@@ -232,7 +217,6 @@ files:
232
217
  - test/lib/vedeu/models/composition_test.rb
233
218
  - test/lib/vedeu/models/interface_test.rb
234
219
  - test/lib/vedeu/models/line_test.rb
235
- - test/lib/vedeu/models/presentation_test.rb
236
220
  - test/lib/vedeu/models/stream_test.rb
237
221
  - test/lib/vedeu/models/style_test.rb
238
222
  - test/lib/vedeu/output/clear_interface_test.rb
@@ -243,14 +227,14 @@ files:
243
227
  - test/lib/vedeu/output/render_interface_test.rb
244
228
  - test/lib/vedeu/output/text_adaptor_test.rb
245
229
  - test/lib/vedeu/output/view_test.rb
246
- - test/lib/vedeu/support/builder_test.rb
247
230
  - test/lib/vedeu/support/esc_test.rb
248
231
  - test/lib/vedeu/support/events_test.rb
249
232
  - test/lib/vedeu/support/geometry_test.rb
250
233
  - test/lib/vedeu/support/helpers_test.rb
251
234
  - test/lib/vedeu/support/input_test.rb
235
+ - test/lib/vedeu/support/interface_store_test.rb
236
+ - test/lib/vedeu/support/interface_template_test.rb
252
237
  - test/lib/vedeu/support/menu_test.rb
253
- - test/lib/vedeu/support/persistence_test.rb
254
238
  - test/lib/vedeu/support/queue_test.rb
255
239
  - test/lib/vedeu/support/terminal_test.rb
256
240
  - test/lib/vedeu/support/translator_test.rb
@@ -312,7 +296,6 @@ test_files:
312
296
  - test/lib/vedeu/models/composition_test.rb
313
297
  - test/lib/vedeu/models/interface_test.rb
314
298
  - test/lib/vedeu/models/line_test.rb
315
- - test/lib/vedeu/models/presentation_test.rb
316
299
  - test/lib/vedeu/models/stream_test.rb
317
300
  - test/lib/vedeu/models/style_test.rb
318
301
  - test/lib/vedeu/output/clear_interface_test.rb
@@ -323,14 +306,14 @@ test_files:
323
306
  - test/lib/vedeu/output/render_interface_test.rb
324
307
  - test/lib/vedeu/output/text_adaptor_test.rb
325
308
  - test/lib/vedeu/output/view_test.rb
326
- - test/lib/vedeu/support/builder_test.rb
327
309
  - test/lib/vedeu/support/esc_test.rb
328
310
  - test/lib/vedeu/support/events_test.rb
329
311
  - test/lib/vedeu/support/geometry_test.rb
330
312
  - test/lib/vedeu/support/helpers_test.rb
331
313
  - test/lib/vedeu/support/input_test.rb
314
+ - test/lib/vedeu/support/interface_store_test.rb
315
+ - test/lib/vedeu/support/interface_template_test.rb
332
316
  - test/lib/vedeu/support/menu_test.rb
333
- - test/lib/vedeu/support/persistence_test.rb
334
317
  - test/lib/vedeu/support/queue_test.rb
335
318
  - test/lib/vedeu/support/terminal_test.rb
336
319
  - test/lib/vedeu/support/translator_test.rb
@@ -1,12 +0,0 @@
1
- require 'virtus'
2
-
3
- require 'vedeu/models/colour'
4
-
5
- module Vedeu
6
- module Presentation
7
- include Virtus.module
8
-
9
- attribute :colour, Colour, default: Colour.new
10
- attribute :style, Array[String]
11
- end
12
- end
@@ -1,32 +0,0 @@
1
- require 'test_helper'
2
- require 'vedeu/models/presentation'
3
-
4
- module Vedeu
5
- class TestPresentation
6
- include Presentation
7
- end
8
-
9
- describe Presentation do
10
- let(:presentation) {
11
- TestPresentation.new({
12
- colour: {
13
- foreground: '#ff0000',
14
- background: '#333333'
15
- },
16
- style: ['bold', 'underline']
17
- })
18
- }
19
-
20
- describe '#colour' do
21
- it 'returns a Colour instance' do
22
- presentation.colour.must_be_instance_of(Colour)
23
- end
24
- end
25
-
26
- describe '#style' do
27
- it 'has a style attribute' do
28
- presentation.style.must_equal(['bold', 'underline'])
29
- end
30
- end
31
- end
32
- end