vedeu 0.1.9 → 0.1.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +4 -4
  2. data/lib/vedeu.rb +43 -17
  3. data/lib/vedeu/api/api.rb +21 -0
  4. data/lib/vedeu/api/base.rb +7 -15
  5. data/lib/vedeu/api/events.rb +5 -10
  6. data/lib/vedeu/api/grid.rb +0 -2
  7. data/lib/vedeu/api/interface.rb +15 -37
  8. data/lib/vedeu/api/line.rb +0 -3
  9. data/lib/vedeu/{instrumentation.rb → api/log.rb} +2 -5
  10. data/lib/vedeu/api/store.rb +3 -9
  11. data/lib/vedeu/api/stream.rb +0 -2
  12. data/lib/vedeu/api/view.rb +4 -15
  13. data/lib/vedeu/application.rb +1 -5
  14. data/lib/vedeu/configuration.rb +0 -2
  15. data/lib/vedeu/launcher.rb +0 -3
  16. data/lib/vedeu/models/attributes/background.rb +0 -4
  17. data/lib/vedeu/models/attributes/foreground.rb +0 -4
  18. data/lib/vedeu/models/attributes/interface_collection.rb +3 -8
  19. data/lib/vedeu/models/attributes/line_collection.rb +0 -5
  20. data/lib/vedeu/models/attributes/stream_collection.rb +0 -5
  21. data/lib/vedeu/models/colour.rb +0 -5
  22. data/lib/vedeu/models/composition.rb +0 -15
  23. data/lib/vedeu/models/geometry.rb +0 -5
  24. data/lib/vedeu/models/interface.rb +0 -14
  25. data/lib/vedeu/models/line.rb +0 -6
  26. data/lib/vedeu/models/stream.rb +0 -5
  27. data/lib/vedeu/models/style.rb +0 -4
  28. data/lib/vedeu/output/buffers.rb +13 -4
  29. data/lib/vedeu/output/render.rb +1 -4
  30. data/lib/vedeu/output/view.rb +7 -3
  31. data/lib/vedeu/support/input.rb +0 -3
  32. data/lib/vedeu/support/menu.rb +0 -5
  33. data/lib/vedeu/support/terminal.rb +0 -4
  34. data/test/lib/vedeu/api/events_test.rb +0 -1
  35. data/test/lib/vedeu/api/grid_test.rb +0 -2
  36. data/test/lib/vedeu/api/interface_test.rb +0 -1
  37. data/test/lib/vedeu/api/store_test.rb +0 -1
  38. data/test/lib/vedeu/api/view_test.rb +1 -4
  39. data/test/lib/vedeu/configuration_test.rb +0 -1
  40. data/test/lib/vedeu/models/attributes/collection_test.rb +0 -1
  41. data/test/lib/vedeu/models/attributes/interface_collection_test.rb +0 -5
  42. data/test/lib/vedeu/models/attributes/line_collection_test.rb +0 -2
  43. data/test/lib/vedeu/models/attributes/stream_collection_test.rb +0 -2
  44. data/test/lib/vedeu/models/colour_test.rb +0 -1
  45. data/test/lib/vedeu/models/composition_test.rb +14 -34
  46. data/test/lib/vedeu/models/geometry_test.rb +0 -1
  47. data/test/lib/vedeu/models/interface_test.rb +0 -1
  48. data/test/lib/vedeu/models/line_test.rb +0 -1
  49. data/test/lib/vedeu/models/stream_test.rb +0 -1
  50. data/test/lib/vedeu/models/style_test.rb +0 -1
  51. data/test/lib/vedeu/output/buffers_test.rb +0 -2
  52. data/test/lib/vedeu/output/clear_test.rb +0 -3
  53. data/test/lib/vedeu/output/render_test.rb +0 -3
  54. data/test/lib/vedeu/support/esc_test.rb +0 -1
  55. data/test/lib/vedeu/support/input_test.rb +0 -1
  56. data/test/lib/vedeu/support/menu_test.rb +0 -1
  57. data/test/lib/vedeu/support/terminal_test.rb +0 -1
  58. data/test/support/model_test_data.json +437 -0
  59. data/test/test_helper.rb +4 -2
  60. data/vedeu.gemspec +1 -1
  61. metadata +6 -44
  62. data/lib/vedeu/support/wordwrap.rb +0 -88
  63. data/test/lib/vedeu/api/base_test.rb +0 -12
  64. data/test/lib/vedeu/api/line_test.rb +0 -10
  65. data/test/lib/vedeu/api/stream_test.rb +0 -12
  66. data/test/lib/vedeu/application_test.rb +0 -10
  67. data/test/lib/vedeu/launcher_test.rb +0 -7
  68. data/test/lib/vedeu/models/attributes/background_test.rb +0 -8
  69. data/test/lib/vedeu/models/attributes/foreground_test.rb +0 -8
  70. data/test/lib/vedeu/output/view_test.rb +0 -9
  71. data/test/lib/vedeu/support/wordwrap_test.rb +0 -56
  72. data/test/lib/vedeu_test.rb +0 -10
  73. data/test/support/json/int1_lin1_str1.json +0 -10
  74. data/test/support/json/int1_lin1_str3.json +0 -18
  75. data/test/support/json/int1_lin2_str1.json +0 -17
  76. data/test/support/json/int1_lin2_str3.json +0 -33
  77. data/test/support/json/int1_lin2_str3_styles.json +0 -43
  78. data/test/support/json/int2_lin1_str1.json +0 -20
  79. data/test/support/json/int2_lin1_str3.json +0 -36
  80. data/test/support/json/int2_lin2_str1.json +0 -34
  81. data/test/support/json/int2_lin2_str3.json +0 -66
  82. data/test/support/json/int2_lin2_str3_styles.json +0 -158
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 2e5e01aa9e53954f48c2dec1ab53d3cbf2bdbe9f
4
- data.tar.gz: 3ee412af2d4751e6e7cf7def63f59b049283fc89
3
+ metadata.gz: 8aeb09ef744842c704e9bdf1e1fb5b4aedc8f130
4
+ data.tar.gz: 84c802a8a7d76a20896f2062dc150f2a02294acb
5
5
  SHA512:
6
- metadata.gz: ce32b74810f69dcbf687a527f2399d05f908095113a9fda6d213c49ddc9d0ef372f3dc70d78e1cf4aa8658330c3d6a8ad73042c94308ecc4c338200f23c9070a
7
- data.tar.gz: 853a70f364f8876adec5284120a18f4ddc85027db12decf0b3a8d2a17a4dd621076f73c68e73958a89551357ac6c10a2528f2f6b119a1d6de884575599f53e65
6
+ metadata.gz: ad4a0e07634064d86fc758f62a6bdba2d17366e5295e890bac15024991149a0910c1a90ce125ea227cf740ca871def5b3bd88547a12ac2f9f9c84ce713e06613
7
+ data.tar.gz: 269d83fef585811e1b3ea07b261809b405f7753827a2a24f8f0a2e964be7c44e5438bce495954d1551da4ca261dc2fb79de1680cf970577cdf70688d3cfdbfb5
data/lib/vedeu.rb CHANGED
@@ -1,30 +1,56 @@
1
- require 'vedeu/instrumentation'
1
+ module Vedeu
2
+
3
+ def self.included(receiver)
4
+ receiver.send(:include, API)
5
+ receiver.extend(API)
6
+ end
2
7
 
8
+ end
9
+
10
+ require 'date'
11
+ require 'forwardable'
12
+ require 'io/console'
13
+ require 'logger'
14
+ require 'optparse'
15
+
16
+ require 'virtus'
17
+
18
+ require 'vedeu/api/api'
19
+ require 'vedeu/api/base'
3
20
  require 'vedeu/api/events'
4
21
  require 'vedeu/api/grid'
5
22
  require 'vedeu/api/interface'
6
23
  require 'vedeu/api/line'
24
+ require 'vedeu/api/log'
7
25
  require 'vedeu/api/store'
8
26
  require 'vedeu/api/stream'
9
27
  require 'vedeu/api/view'
10
- require 'vedeu/output/view'
11
28
 
12
- require 'vedeu/support/menu'
29
+ require 'vedeu/application'
30
+ require 'vedeu/configuration'
13
31
  require 'vedeu/launcher'
14
32
 
15
- module Vedeu
16
- extend API
17
-
18
- def self.log(message)
19
- Vedeu::Instrumentation::Log.logger.debug(message)
20
- end
33
+ require 'vedeu/models/attributes/background'
34
+ require 'vedeu/models/attributes/collection'
35
+ require 'vedeu/models/attributes/colour_translator'
36
+ require 'vedeu/models/attributes/foreground'
37
+ require 'vedeu/models/attributes/interface_collection'
38
+ require 'vedeu/models/attributes/line_collection'
39
+ require 'vedeu/models/attributes/stream_collection'
40
+ require 'vedeu/models/composition'
41
+ require 'vedeu/support/terminal'
42
+ require 'vedeu/models/geometry'
43
+ require 'vedeu/models/colour'
44
+ require 'vedeu/models/style'
45
+ require 'vedeu/models/interface'
46
+ require 'vedeu/models/line'
47
+ require 'vedeu/models/stream'
21
48
 
22
- def self.error(exception)
23
- Vedeu::Instrumentation::Log.error(exception)
24
- end
49
+ require 'vedeu/output/buffers'
50
+ require 'vedeu/output/clear'
51
+ require 'vedeu/output/render'
52
+ require 'vedeu/output/view'
25
53
 
26
- def self.included(receiver)
27
- receiver.send(:include, API)
28
- receiver.extend(API)
29
- end
30
- end
54
+ require 'vedeu/support/esc'
55
+ require 'vedeu/support/input'
56
+ require 'vedeu/support/menu'
@@ -0,0 +1,21 @@
1
+ module Vedeu
2
+ module API
3
+ def interface(name, &block)
4
+ API::Interface.save(name, &block)
5
+ end
6
+
7
+ def log(message)
8
+ API::Log.logger.debug(message)
9
+ end
10
+
11
+ # def render(object = nil)
12
+ # Vedeu::View.render(object)
13
+ # end
14
+
15
+ def view(name, &block)
16
+ API::View.build(name, &block)
17
+ end
18
+ end
19
+
20
+ extend API
21
+ end
@@ -6,25 +6,17 @@ module Vedeu
6
6
  end
7
7
 
8
8
  def initialize(attributes = {}, &block)
9
- @attributes = attributes
9
+ @attributes = attributes
10
+ @self_before_instance_eval = eval('self', block.binding)
10
11
 
11
- @self_before_instance_eval = eval 'self', block.binding
12
-
13
- self.instance_eval(&block)
12
+ instance_eval(&block)
14
13
  end
15
14
 
16
- def colour(*args)
17
- if args.is_a?(Array) && args.size == 2
18
- attributes[:colour] = { background: args.first,
19
- foreground: args.last }
20
-
21
- elsif args.is_a?(Array) && args.size == 1 && args.first.is_a?(Hash)
22
- attributes[:colour] = args.first
15
+ def colour(values = {})
16
+ fail InvalidArgument, '#colour expects a Hash containing :foreground,' \
17
+ ' :background or both.' unless values.is_a?(Hash)
23
18
 
24
- else
25
- attributes[:colour] = {}
26
-
27
- end
19
+ attributes[:colour] = values
28
20
  end
29
21
 
30
22
  def style(values = [], &block)
@@ -1,5 +1,3 @@
1
- # Todo: mutation (events)
2
-
3
1
  module Vedeu
4
2
  module API
5
3
  def on(name, delay = 0, &block)
@@ -36,14 +34,13 @@ module Vedeu
36
34
  last_exec: 0,
37
35
  }
38
36
  end
39
- self.instance_eval(&block) if block_given?
40
- self
37
+ instance_eval(&block) if block_given?
41
38
  end
42
39
 
43
40
  def add(object, &block)
44
- @self_before_instance_eval = eval 'self', block.binding
41
+ @self_before_instance_eval = eval('self', block.binding)
45
42
 
46
- self.instance_eval(&block)
43
+ instance_eval(&block)
47
44
  end
48
45
 
49
46
  def on(event, delay = 0, &block)
@@ -58,15 +55,13 @@ module Vedeu
58
55
  if elapsed > handlers[event][:delay]
59
56
  handlers[event][:last_exec] = Time.now.to_f
60
57
 
61
- handlers[event][:events].each do |handler|
62
- handler.call(*args)
63
- end
58
+ handlers[event][:events].each { |handler| handler.call(*args) }
64
59
  end
65
60
  end
66
61
 
67
62
  private
68
63
 
69
- attr_reader :handlers, :throttles
64
+ attr_reader :handlers
70
65
 
71
66
  def method_missing(method, *args, &block)
72
67
  @self_before_instance_eval.send method, *args, &block
@@ -1,5 +1,3 @@
1
- require 'vedeu/support/terminal'
2
-
3
1
  class Fixnum
4
2
  # Augment Fixnum to calculate column width in a grid-based layout.
5
3
  #
@@ -1,20 +1,10 @@
1
- require 'vedeu/models/geometry'
2
- require 'vedeu/models/composition'
3
- require 'vedeu/api/grid'
4
- require 'vedeu/api/store'
5
- require 'vedeu/support/terminal'
6
-
7
1
  module Vedeu
8
- module API
9
- InvalidHeight = Class.new(StandardError)
10
- InvalidWidth = Class.new(StandardError)
11
- XOutOfBounds = Class.new(StandardError)
12
- YOutOfBounds = Class.new(StandardError)
13
-
14
- def interface(name, &block)
15
- Interface.save(name, &block)
16
- end
2
+ InvalidHeight = Class.new(StandardError)
3
+ InvalidWidth = Class.new(StandardError)
4
+ XOutOfBounds = Class.new(StandardError)
5
+ YOutOfBounds = Class.new(StandardError)
17
6
 
7
+ module API
18
8
  class Interface
19
9
  def self.save(name, &block)
20
10
  new(name).save(&block)
@@ -25,24 +15,12 @@ module Vedeu
25
15
  end
26
16
 
27
17
  def save(&block)
28
- self.instance_eval(&block) if block_given?
18
+ instance_eval(&block) if block_given?
29
19
 
30
20
  stored_attributes = Store.create(attributes)
31
21
  interface = Vedeu::Interface.new(stored_attributes)
32
22
 
33
- Vedeu::Buffers.create(interface.name, interface.clear)
34
-
35
- Vedeu.events.on("_refresh_#{interface.name}_".to_sym, interface.delay) do
36
- Vedeu::Buffers.refresh(interface.name)
37
- end
38
-
39
- # TODO:
40
- # cannot do group at this time
41
- # unless interface.group.nil? || interface.group.empty?
42
- # Vedeu.events.on("_refresh_group_#{interface.group}_".to_sym, interface.delay) do
43
- # buffer.refresh_group(interface.group)
44
- # end
45
- # end
23
+ Vedeu::Buffers.create(interface)
46
24
 
47
25
  interface
48
26
  end
@@ -83,14 +61,6 @@ module Vedeu
83
61
  attributes[:geometry][:centred] = value
84
62
  end
85
63
 
86
- def attributes
87
- @attributes ||= { name: name, geometry: {} }
88
- end
89
-
90
- def method_missing(method_name, arg, &block)
91
- attributes[method_name] = arg
92
- end
93
-
94
64
  def y_out_of_bounds?(value)
95
65
  value < 1 || value > Terminal.height
96
66
  end
@@ -98,6 +68,14 @@ module Vedeu
98
68
  def x_out_of_bounds?(value)
99
69
  value < 1 || value > Terminal.width
100
70
  end
71
+
72
+ def method_missing(method_name, arg, &block)
73
+ attributes[method_name] = arg
74
+ end
75
+
76
+ def attributes
77
+ @attributes ||= { name: name, geometry: {} }
78
+ end
101
79
  end
102
80
  end
103
81
  end
@@ -1,6 +1,3 @@
1
- require 'vedeu/api/base'
2
- require 'vedeu/api/stream'
3
-
4
1
  module Vedeu
5
2
  module API
6
3
  class Line < Base
@@ -1,8 +1,5 @@
1
- require 'date'
2
- require 'logger'
3
-
4
1
  module Vedeu
5
- module Instrumentation
2
+ module API
6
3
  class Log
7
4
  def self.logger
8
5
  @logger ||= Logger.new(filename).tap do |log|
@@ -63,7 +60,7 @@ module Vedeu
63
60
  def defaults
64
61
  {
65
62
  event: 'call',
66
- klass: /^Vedeu::(?!.*Instrumentation|Interface|Line|Stream|Style|Colour|Geometry|Terminal|Esc|ColourTranslator).*/
63
+ klass: /^Vedeu::(?!.*Log|Interface|Line|Stream|Style|Colour|Geometry|Terminal|Esc|ColourTranslator).*/
67
64
  }
68
65
  end
69
66
 
@@ -1,11 +1,7 @@
1
- require 'vedeu/models/interface'
2
-
3
- # Todo: mutation (persistence)
4
-
5
1
  module Vedeu
6
- module API
7
- EntityNotFound = Class.new(StandardError)
2
+ EntityNotFound = Class.new(StandardError)
8
3
 
4
+ module API
9
5
  def use(name)
10
6
  Vedeu::Interface.new(Store.query(name))
11
7
  end
@@ -18,9 +14,7 @@ module Vedeu
18
14
  end
19
15
 
20
16
  def query(name)
21
- attributes = storage.fetch(name) do
22
- fail EntityNotFound, 'Interface was not found.'
23
- end
17
+ storage.fetch(name) { fail EntityNotFound, 'Interface was not found.' }
24
18
  end
25
19
 
26
20
  def reset
@@ -1,5 +1,3 @@
1
- require 'vedeu/api/base'
2
-
3
1
  module Vedeu
4
2
  module API
5
3
  class Stream < Base
@@ -1,33 +1,22 @@
1
- require 'vedeu/api/line'
2
- require 'vedeu/api/store'
3
-
4
1
  module Vedeu
5
2
  module API
6
3
  InterfaceNotSpecified = Class.new(StandardError)
7
4
 
8
- def render(object = nil)
9
- Vedeu::View.render(object)
10
- end
11
-
12
- def view(name = '', &block)
13
- Vedeu::API::View.build(name, &block)
14
- end
15
-
16
5
  class View
17
- def self.build(name = '', &block)
6
+ def self.build(name, &block)
18
7
  new(name).build(&block)
19
8
  end
20
9
 
21
- def initialize(name = '')
10
+ def initialize(name)
22
11
  fail InterfaceNotSpecified if name.nil? || name.empty?
23
12
 
24
13
  @name = name.to_s
25
14
  end
26
15
 
27
16
  def build(&block)
28
- @self_before_instance_eval = eval 'self', block.binding
17
+ @self_before_instance_eval = eval('self', block.binding)
29
18
 
30
- self.instance_eval(&block) if block_given?
19
+ instance_eval(&block) if block_given?
31
20
 
32
21
  attributes
33
22
  end
@@ -1,7 +1,3 @@
1
- require 'vedeu/instrumentation'
2
- require 'vedeu/support/input'
3
- require 'vedeu/support/terminal'
4
-
5
1
  module Vedeu
6
2
  ModeSwitch = Class.new(StandardError)
7
3
 
@@ -68,7 +64,7 @@ module Vedeu
68
64
  end
69
65
 
70
66
  def debug
71
- Vedeu::Instrumentation::Trace.call if options.fetch(:debug)
67
+ Vedeu::API::Trace.call if options.fetch(:debug)
72
68
  end
73
69
 
74
70
  def options
@@ -1,5 +1,3 @@
1
- require 'optparse'
2
-
3
1
  module Vedeu
4
2
  class Configuration
5
3
  def self.configure(args = [])
@@ -1,6 +1,3 @@
1
- require 'vedeu/application'
2
- require 'vedeu/configuration'
3
-
4
1
  module Vedeu
5
2
  class Launcher
6
3
  def initialize(argv, stdin = STDIN,
@@ -1,7 +1,3 @@
1
- require 'virtus'
2
-
3
- require 'vedeu/models/attributes/colour_translator'
4
-
5
1
  module Vedeu
6
2
  class Background < Virtus::Attribute
7
3
  def coerce(value)
@@ -1,7 +1,3 @@
1
- require 'virtus'
2
-
3
- require 'vedeu/models/attributes/colour_translator'
4
-
5
1
  module Vedeu
6
2
  class Foreground < Virtus::Attribute
7
3
  def coerce(value)
@@ -1,17 +1,12 @@
1
- require 'virtus'
2
-
3
- require 'vedeu/models/interface'
4
- require 'vedeu/api/store'
5
-
6
1
  module Vedeu
7
2
  class InterfaceCollection < Virtus::Attribute
8
3
  def coerce(values)
9
4
  return [] if values.nil? || values.empty?
10
5
 
11
- [values].flatten.map do |buffer_attributes|
12
- interface_attributes = API::Store.query(buffer_attributes[:name])
6
+ [values].flatten.map do |view_attributes|
7
+ stored_attributes = API::Store.query(view_attributes[:name])
13
8
 
14
- Interface.new(buffer_attributes.merge!(interface_attributes))
9
+ Interface.new(stored_attributes.merge!(view_attributes))
15
10
  end
16
11
  end
17
12
  end