vedeu 0.2.9 → 0.2.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -6,6 +6,8 @@ module Vedeu
6
6
  # @api private
7
7
  class Input
8
8
 
9
+ # Instantiate Input and capture keypress(es).
10
+ #
9
11
  # @return [String|Symbol]
10
12
  def self.capture
11
13
  new.capture
@@ -41,6 +41,8 @@ module Vedeu
41
41
 
42
42
  private
43
43
 
44
+ # The default values for a new instance of Colour.
45
+ #
44
46
  # @return [Hash]
45
47
  def defaults
46
48
  {
@@ -134,21 +134,29 @@ module Vedeu
134
134
  nil
135
135
  end
136
136
 
137
+ # Return the amount of time in seconds to debounce the event by.
138
+ #
137
139
  # @return [Fixnum|Float]
138
140
  def debounce
139
141
  options[:debounce] || defaults[:debounce]
140
142
  end
141
143
 
144
+ # Return the amount of time in seconds to throttle the event by.
145
+ #
142
146
  # @return [Fixnum|Float]
143
147
  def delay
144
148
  options[:delay] || defaults[:delay]
145
149
  end
146
150
 
151
+ # Combines the options provided at instantiation with the default values.
152
+ #
147
153
  # @return [Hash]
148
154
  def options
149
155
  defaults.merge!(@options)
150
156
  end
151
157
 
158
+ # The default values for a new instance of Event.
159
+ #
152
160
  # @return [Hash]
153
161
  def defaults
154
162
  {
@@ -1,137 +1,36 @@
1
- require 'fileutils'
2
- require 'time'
3
-
4
1
  module Vedeu
5
2
 
6
- # Allows the creation of a lock-less log device.
3
+ # Provides the ability to log anything to the Vedeu log file.
7
4
  #
8
5
  # @api private
9
- class MonoLogger < Logger
10
-
11
- # Create a trappable Logger instance.
12
- #
13
- # @param logdev [String|IO] The filename (String) or IO object (typically
14
- # STDOUT, STDERR or an open file).
15
- # @param shift_age [] Number of old log files to keep, or frequency of
16
- # rotation (daily, weekly, monthly).
17
- # @param shift_size [] Maximum log file size (only applies when shift_age
18
- # is a number).
19
- #
20
- # @example
21
- # Logger.new(name, shift_age = 7, shift_size = 1048576)
22
- # Logger.new(name, shift_age = 'weekly')
23
- #
24
- def initialize(logdev, shift_age=nil, shift_size=nil)
25
- @progname = nil
26
- @level = DEBUG
27
- @default_formatter = Formatter.new
28
- @formatter = nil
29
- @logdev = nil
30
- if logdev
31
- @logdev = LocklessLogDevice.new(logdev)
32
- end
33
- end
6
+ class Log
34
7
 
35
- # Ensures we can always write to the log file by creating a lock-less
36
- # log device.
37
- class LocklessLogDevice < LogDevice
8
+ class << self
38
9
 
39
- # @return []
40
- def initialize(log = nil)
41
- @dev = @filename = @shift_age = @shift_size = nil
42
- if log.respond_to?(:write) and log.respond_to?(:close)
43
- @dev = log
44
- else
45
- @dev = open_logfile(log)
46
- @dev.sync = true
47
- @filename = log
10
+ # @return [TrueClass]
11
+ def logger
12
+ Logger.new(Configuration.log).tap do |log|
13
+ log.formatter = proc do |_, time, _, message|
14
+ [timestamp(time.utc.iso8601), message, "\n"].join
15
+ end
48
16
  end
49
17
  end
50
18
 
51
- # @return []
52
- def write(message)
53
- @dev.write(message)
54
- rescue Exception => ignored
55
- warn("log writing failed. #{ignored}")
56
- end
57
-
58
- # @return []
59
- def close
60
- @dev.close rescue nil
61
- end
62
-
63
19
  private
64
20
 
65
- # @return []
66
- def open_logfile(filename)
67
- if (FileTest.exist?(filename))
68
- open(filename, (File::WRONLY | File::APPEND))
69
- else
70
- create_logfile(filename)
71
- end
72
- end
21
+ # Returns a formatted (red, underlined) UTC timestamp,
22
+ # eg. 2014-10-24T12:34:56Z
23
+ #
24
+ # @return [String]
25
+ def timestamp(utc_time)
26
+ return '' if @last_seen == utc_time
73
27
 
74
- # @return []
75
- def create_logfile(filename)
76
- logdev = open(filename, (File::WRONLY | File::APPEND | File::CREAT))
77
- logdev.sync = true
78
- add_log_header(logdev)
79
- logdev
80
- end
28
+ @last_seen = utc_time
81
29
 
82
- # @return []
83
- def add_log_header(file)
84
- file.write(
85
- "# Logfile created on %s by %s\n" % [Time.now.to_s, Logger::ProgName]
86
- )
30
+ "\n\e[4m\e[31m" + utc_time + "\e[39m\e[24m\n"
87
31
  end
88
- end
89
-
90
- end
91
-
92
- # Provides the ability to Log anything to the Vedeu log file which is
93
- # hard-coded to reside in `$HOME/.vedeu/vedeu.log`.
94
- #
95
- # @api private
96
- class Log
97
-
98
- # @return [TrueClass]
99
- def self.logger
100
- @logger ||= MonoLogger.new(filename).tap do |log|
101
- log.formatter = proc do |_, time, _, message|
102
- utc_time = time.utc.iso8601
103
-
104
- [timestamp(utc_time), message, "\n"].join
105
- end
106
- end
107
- end
108
-
109
- private
110
-
111
- def self.timestamp(utc_time)
112
- return "" if @last_seen == utc_time
113
-
114
- @last_seen = utc_time
115
-
116
- "\n\e[4m\e[31m" + utc_time + "\e[39m\e[24m\n"
117
- end
118
-
119
- # @return [String]
120
- def self.filename
121
- @_filename ||= directory + '/vedeu.log'
122
- end
123
-
124
- # @return [String]
125
- def self.directory
126
- FileUtils.mkdir_p(path) unless File.directory?(path)
127
-
128
- path
129
- end
130
32
 
131
- # @return [String]
132
- def self.path
133
- Dir.home + '/.vedeu'
134
- end
33
+ end # Log eigenclass
135
34
 
136
35
  end # Log
137
36
 
@@ -6,12 +6,23 @@ module Vedeu
6
6
  # @api private
7
7
  class Registrar
8
8
 
9
+ REPOSITORIES = [Buffers, Cursors, Focus, Groups, Interfaces, Offsets]
10
+
9
11
  # @param attributes [Hash]
10
12
  # @return [TrueClass|MissingRequired]
11
13
  def self.record(attributes = {})
12
14
  new(attributes).record
13
15
  end
14
16
 
17
+ # Removes all entities from all repositories. Use with caution.
18
+ #
19
+ # @return [TrueClass]
20
+ def self.reset!
21
+ REPOSITORIES.each { |repository| repository.reset }
22
+
23
+ true
24
+ end
25
+
15
26
  # @param attributes [Hash]
16
27
  # @return [Registrar]
17
28
  def initialize(attributes = {})
@@ -22,9 +33,7 @@ module Vedeu
22
33
  #
23
34
  # @return [TrueClass|MissingRequired]
24
35
  def record
25
- [Buffers, Offsets, Interfaces, Cursors, Groups, Focus].map do |repository|
26
- repository.add(attributes)
27
- end
36
+ REPOSITORIES.each { |repository| repository.add(attributes) }
28
37
 
29
38
  true
30
39
  end
@@ -361,7 +361,11 @@ module Vedeu
361
361
 
362
362
  describe '#x' do
363
363
  it 'sets the attribute to the block if a block is given' do
364
- skip
364
+ Vedeu.interface 'iron' do
365
+ x { 9 }
366
+ end
367
+
368
+ Vedeu.use('iron').geometry.x.must_equal(9)
365
369
  end
366
370
 
367
371
  it 'sets the attribute to the value if a block is not given' do
@@ -375,7 +379,11 @@ module Vedeu
375
379
 
376
380
  describe '#y' do
377
381
  it 'sets the attribute to the block if a block is given' do
378
- skip
382
+ Vedeu.interface 'iron' do
383
+ y { 6 }
384
+ end
385
+
386
+ Vedeu.use('iron').geometry.y.must_equal(6)
379
387
  end
380
388
 
381
389
  it 'sets the attribute to the value if a block is not given' do
@@ -2,12 +2,12 @@ require 'test_helper'
2
2
 
3
3
  module Vedeu
4
4
 
5
- module Configuration
5
+ module Config
6
6
 
7
7
  describe API do
8
8
 
9
- before { Configuration.reset }
10
- after { Configuration.reset }
9
+ before { Configuration.reset! }
10
+ after { test_configuration }
11
11
 
12
12
  describe '.configure' do
13
13
  it 'returns the default configuration' do
@@ -15,9 +15,10 @@ module Vedeu
15
15
  # ...
16
16
  end.must_equal(
17
17
  {
18
- colour_mode: 16777216,
18
+ colour_mode: 256,
19
19
  debug: false,
20
20
  interactive: true,
21
+ log: '/tmp/vedeu.log',
21
22
  once: false,
22
23
  system_keys: {
23
24
  exit: 'q',
@@ -208,6 +209,13 @@ module Vedeu
208
209
  end
209
210
  end
210
211
 
212
+ describe '#log' do
213
+ it 'sets the options to the desired value' do
214
+ configuration = Vedeu.configure { log('/tmp/vedeu_api_test.log') }
215
+ configuration[:log].must_equal('/tmp/vedeu_api_test.log')
216
+ end
217
+ end
218
+
211
219
  describe 'redefining system keys' do
212
220
  methods_and_keys = {
213
221
  exit_key: :exit,
@@ -245,6 +253,6 @@ module Vedeu
245
253
 
246
254
  end # API
247
255
 
248
- end # Configuration
256
+ end # Config
249
257
 
250
258
  end # Vedeu
@@ -2,89 +2,99 @@ require 'test_helper'
2
2
 
3
3
  module Vedeu
4
4
 
5
- module Configuration
5
+ module Config
6
6
 
7
7
  describe CLI do
8
8
 
9
- # describe '#colour_mode' do
10
- # it '--colour-mode' do
11
- # Configuration.configure(['--colour-mode', '16777216'])
12
- # Configuration.colour_mode.must_equal(16777216)
13
- # end
14
-
15
- # it '--colour-mode' do
16
- # Configuration.configure(['--colour-mode', '256'])
17
- # Configuration.colour_mode.must_equal(256)
18
- # end
19
-
20
- # it '--colour-mode' do
21
- # Configuration.configure(['--colour-mode', '16'])
22
- # Configuration.colour_mode.must_equal(16)
23
- # end
24
-
25
- # it '--colour-mode' do
26
- # Configuration.configure(['--colour-mode', '348'])
27
- # Configuration.colour_mode.must_equal(8)
28
- # end
29
- # end
30
-
31
- # describe '#debug?' do
32
- # it '--debug' do
33
- # Configuration.configure(['--debug'])
34
- # Configuration.debug?.must_equal(true)
35
- # end
36
- # end
37
-
38
- # describe '#interactive?' do
39
- # it '--interactive' do
40
- # Configuration.configure(['--interactive'])
41
- # Configuration.interactive?.must_equal(true)
42
- # end
43
-
44
- # it '--noninteractive' do
45
- # Configuration.configure(['--noninteractive'])
46
- # Configuration.interactive?.must_equal(false)
47
- # end
48
-
49
- # it '--standalone' do
50
- # Configuration.configure(['--standalone'])
51
- # Configuration.interactive?.must_equal(false)
52
- # end
53
- # end
54
-
55
- # describe '#once?' do
56
- # it '--run-once' do
57
- # Configuration.configure(['--run-once'])
58
- # Configuration.once?.must_equal(true)
59
- # end
60
-
61
- # it '--run-many' do
62
- # Configuration.configure(['--run-many'])
63
- # Configuration.once?.must_equal(false)
64
- # end
65
- # end
66
-
67
- # describe '#terminal_mode' do
68
- # it '--cooked' do
69
- # Configuration.configure(['--cooked'])
70
- # Configuration.terminal_mode.must_equal(:cooked)
71
- # end
72
-
73
- # it '--raw' do
74
- # Configuration.configure(['--raw'])
75
- # Configuration.terminal_mode.must_equal(:raw)
76
- # end
77
- # end
78
-
79
- # describe '#trace?' do
80
- # it '--trace' do
81
- # Configuration.configure(['--trace'])
82
- # Configuration.trace?.must_equal(true)
83
- # end
84
- # end
9
+ before { Configuration.reset! }
10
+ after { test_configuration }
11
+
12
+ describe '#colour_mode' do
13
+ it '--colour-mode' do
14
+ Configuration.configure(['--colour-mode', '16777216'])
15
+ Configuration.colour_mode.must_equal(16777216)
16
+ end
17
+
18
+ it '--colour-mode' do
19
+ Configuration.configure(['--colour-mode', '256'])
20
+ Configuration.colour_mode.must_equal(256)
21
+ end
22
+
23
+ it '--colour-mode' do
24
+ Configuration.configure(['--colour-mode', '16'])
25
+ Configuration.colour_mode.must_equal(16)
26
+ end
27
+
28
+ it '--colour-mode' do
29
+ Configuration.configure(['--colour-mode', '348'])
30
+ Configuration.colour_mode.must_equal(8)
31
+ end
32
+ end
33
+
34
+ describe '#debug?' do
35
+ it '--debug' do
36
+ Configuration.configure(['--debug'])
37
+ Configuration.debug?.must_equal(true)
38
+ end
39
+ end
40
+
41
+ describe '#interactive?' do
42
+ it '--interactive' do
43
+ Configuration.configure(['--interactive'])
44
+ Configuration.interactive?.must_equal(true)
45
+ end
46
+
47
+ it '--noninteractive' do
48
+ Configuration.configure(['--noninteractive'])
49
+ Configuration.interactive?.must_equal(false)
50
+ end
51
+
52
+ it '--standalone' do
53
+ Configuration.configure(['--standalone'])
54
+ Configuration.interactive?.must_equal(false)
55
+ end
56
+ end
57
+
58
+ describe '#log' do
59
+ it '--log' do
60
+ Configuration.configure(['--log', '/tmp/vedeu_cli_test.log'])
61
+ Configuration.log.must_equal('/tmp/vedeu_cli_test.log')
62
+ end
63
+ end
64
+
65
+ describe '#once?' do
66
+ it '--run-once' do
67
+ Configuration.configure(['--run-once'])
68
+ Configuration.once?.must_equal(true)
69
+ end
70
+
71
+ it '--run-many' do
72
+ Configuration.configure(['--run-many'])
73
+ Configuration.once?.must_equal(false)
74
+ end
75
+ end
76
+
77
+ describe '#terminal_mode' do
78
+ it '--cooked' do
79
+ Configuration.configure(['--cooked'])
80
+ Configuration.terminal_mode.must_equal(:cooked)
81
+ end
82
+
83
+ it '--raw' do
84
+ Configuration.configure(['--raw'])
85
+ Configuration.terminal_mode.must_equal(:raw)
86
+ end
87
+ end
88
+
89
+ describe '#trace?' do
90
+ it '--trace' do
91
+ Configuration.configure(['--trace'])
92
+ Configuration.trace?.must_equal(true)
93
+ end
94
+ end
85
95
 
86
96
  end # CLI
87
97
 
88
- end # Configuration
98
+ end # Config
89
99
 
90
100
  end # Vedeu