vedeu 0.8.14 → 0.8.15

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 34e3c347f479d6c178f4aacae2dd5cee4018d555
4
- data.tar.gz: 92cb71dfedee65fb74c2808c843bea8222802808
3
+ metadata.gz: 7873b236437abf97edd687af67588fd80c87b3e9
4
+ data.tar.gz: 4c2646bd4fb5366960fb0fef677d96aa929db230
5
5
  SHA512:
6
- metadata.gz: 338a4fd459b7f6d89e56e3247921aa215069b5bf30b947084fbd55c5aec2a42d44cecaf6d8a4a5ca7e38fd0084b5908239bffe9a760c444476ff336e1c51ef16
7
- data.tar.gz: a84a360d6c8f4153ca61aa89ea819178d866d9e9d4b306b23da5a9da57bba8146840155b24626a24108bd1a3a6addcdde33a93c0b8582379933a1462ab7f83a2
6
+ metadata.gz: 1538cf094b528f976340e281c7cab189cf42e5190a662dff3d2b0ce61aa8990f26b05c7059c4ea29a19fa7ef830d362008a448d78160d9fb3e4dce44ef46527f
7
+ data.tar.gz: 74dabd2d4fbd0aef2512601a521a105644d227d482be6a31ca3f0a6ef270e8ba6749f518141b54f35470c2c96313a36ba89b8395bb36ac1893e0cbed8a7b09e0
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source 'https://rubygems.org'
2
4
 
3
5
  gemspec
data/Guardfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  if ENV['RUBOCOP'].to_i == 1
2
4
  guard :rubocop do
3
5
  watch(/.+\.rb$/)
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'bundler/gem_tasks'
2
4
  require 'rake/testtask'
3
5
  require 'yard'
data/bin/vedeu CHANGED
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ # frozen_string_literal: true
4
+
3
5
  require 'rake'
4
6
  bundler_message = 'Bundler is required. Please install bundler with ' \
5
7
  "'gem install bundler'"
data/bin/vedeu_drb_client CHANGED
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ # frozen_string_literal: true
4
+
3
5
  lib_dir = File.dirname(__FILE__) + '/../lib'
4
6
  $LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir)
5
7
 
data/bin/vedeu_drb_server CHANGED
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ # frozen_string_literal: true
4
+
3
5
  lib_dir = '/Users/gavinlaking/Source/vedeu/lib/vedeu/distributed/../../../lib'
4
6
  $LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir)
5
7
 
data/bin/vedeu_test CHANGED
@@ -1,5 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ # frozen_string_literal: true
4
+
3
5
  lib_dir = File.dirname(__FILE__) + '/../lib'
4
6
  $LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir)
5
7
 
@@ -0,0 +1,9 @@
1
+ Configure the background colour for the client application.
2
+
3
+ # Set:
4
+ Vedeu.configure do
5
+ background '#330000'
6
+ end
7
+
8
+ # Get:
9
+ Vedeu.config.background
@@ -0,0 +1,9 @@
1
+ Configure the foreground colour for the client application.
2
+
3
+ # Set:
4
+ Vedeu.configure do
5
+ foreground '#00aa33'
6
+ end
7
+
8
+ # Get:
9
+ Vedeu.config.foreground
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'vedeu/application/controller'
2
4
  require 'vedeu/application/helper'
3
5
  require 'vedeu/application/view'
data/lib/vedeu/common.rb CHANGED
@@ -8,13 +8,14 @@ module Vedeu
8
8
  #
9
9
  module Common
10
10
 
11
- # Returns a boolean indicating whether a variable is nil or empty.
11
+ # Returns a boolean indicating whether a variable is nil, false or
12
+ # empty.
12
13
  #
13
14
  # @param variable [String|Symbol|Array|Fixnum] The variable to
14
15
  # check.
15
16
  # @return [Boolean]
16
17
  def absent?(variable)
17
- !present?(variable)
18
+ variable == false || !present?(variable)
18
19
  end
19
20
 
20
21
  # Returns a boolean indicating whether the value is an Array.
@@ -25,7 +26,7 @@ module Vedeu
25
26
  value.is_a?(Array)
26
27
  end
27
28
 
28
- # Returns a boolean indicating the value was a boolean.
29
+ # Returns a boolean indicating the value is a boolean.
29
30
  #
30
31
  # @param value [void]
31
32
  # @return [Boolean]
@@ -43,6 +44,17 @@ module Vedeu
43
44
  value.is_a?(TrueClass) || value.is_a?(FalseClass)
44
45
  end
45
46
 
47
+ # Returns a boolean indicating the value is empty.
48
+ #
49
+ # @param value [void]
50
+ # @return [Boolean]
51
+ def empty_value?(value)
52
+ return true if value.respond_to?(:empty?) && value.empty?
53
+ return true if value.nil?
54
+
55
+ false
56
+ end
57
+
46
58
  # Returns a boolean indicating whether the value is an escape
47
59
  # sequence object (e.g. {Vedeu::Cells::Escape}.)
48
60
  #
@@ -109,8 +121,8 @@ module Vedeu
109
121
  # @return [Boolean]
110
122
  def present?(variable)
111
123
  return true if numeric?(variable)
112
- return false if variable.nil?
113
- return false if variable.respond_to?(:empty?) && variable.empty?
124
+ return false if variable.nil? || variable == false
125
+ return false if empty_value?(variable)
114
126
 
115
127
  true
116
128
  end
@@ -4,22 +4,10 @@ module Vedeu
4
4
 
5
5
  # Namespace for configuration classes.
6
6
  #
7
+ # @api public
8
+ #
7
9
  module Config
8
10
 
9
- module_function
10
-
11
- # Custom log for configuration.
12
- #
13
- # @param from [String] Which configuration set the options.
14
- # @param options [Hash<Symbol => void>] The configuration options set.
15
- # @return [Hash<Symbol => void>] The options param.
16
- def log(from, options)
17
- options.each do |option, value|
18
- Vedeu.log(type: :config,
19
- message: "#{from} #{option}: #{value}")
20
- end
21
- end
22
-
23
11
  end # Config
24
12
 
25
13
  end # Vedeu
@@ -13,8 +13,8 @@ module Vedeu
13
13
  include Vedeu::Common
14
14
 
15
15
  # @param (see #initialize)
16
- def self.configure(&block)
17
- new(&block).configuration
16
+ def self.configure(default, &block)
17
+ new(default, &block).configuration
18
18
  end
19
19
 
20
20
  # Returns a new instance of Vedeu::Config::API.
@@ -27,9 +27,12 @@ module Vedeu
27
27
  # # ...
28
28
  # end
29
29
  #
30
+ # @param default [Hash]
30
31
  # @param block [Proc]
31
32
  # @return [Vedeu::Configuration::API]
32
- def initialize(&block)
33
+ def initialize(default, &block)
34
+ @default = default
35
+
33
36
  instance_eval(&block) if block_given?
34
37
  end
35
38
 
@@ -37,8 +40,22 @@ module Vedeu
37
40
  #
38
41
  # @return [Hash<Symbol => Boolean, Fixnum, String>]
39
42
  def configuration
40
- Vedeu::Config
41
- .log(Vedeu.esc.green { '[api]' }, options)
43
+ if options[:log].nil? ||
44
+ options[:log] == false ||
45
+ empty_value?(options[:log])
46
+ Vedeu.log(type: :config,
47
+ message: 'Logging has been disabled.')
48
+
49
+ return options
50
+ end
51
+
52
+ log_options!
53
+
54
+ if options[:log] != default[:log]
55
+ Vedeu.log(message: "Switching to '#{options[:log]}' for logging.\n")
56
+ end
57
+
58
+ options
42
59
  end
43
60
 
44
61
  # {include:file:docs/configuration/interactive.md}
@@ -228,17 +245,33 @@ module Vedeu
228
245
  end
229
246
  alias height= height
230
247
 
231
- # Sets the location of the log file.
248
+ # Sets the location of the log file, or disables the log.
249
+ # By default, the log file is set to '/tmp/vedeu_bootstrap.log'.
232
250
  #
251
+ # # Log messages will be sent to the path given.
233
252
  # Vedeu.configure do
234
253
  # log '/var/log/vedeu.log'
235
254
  # # ...
236
255
  # end
237
256
  #
238
- # @param filename [String]
239
- # @return [String]
240
- def log(filename = '')
241
- options[:log] = filename
257
+ # # Log messages will be silently dropped.
258
+ # Vedeu.configure do
259
+ # log false
260
+ # # ...
261
+ # end
262
+ #
263
+ # @param filename_or_false [FalseClass|String]
264
+ # @return [NilClass|String]
265
+ def log(filename_or_false = false)
266
+ options[:log] = if filename_or_false.nil? ||
267
+ filename_or_false == false ||
268
+ empty_value?(filename_or_false)
269
+ nil
270
+
271
+ else
272
+ filename_or_false
273
+
274
+ end
242
275
  end
243
276
 
244
277
  # Log specific message types except those given. A complete list
@@ -493,13 +526,7 @@ module Vedeu
493
526
  end
494
527
  alias width= width
495
528
 
496
- # Sets the background of the terminal.
497
- #
498
- # Vedeu.configure do
499
- # background '#ff0000'
500
- # # ...
501
- # end
502
- #
529
+ # {include:file:docs/configuration/background.md}
503
530
  # @param value [String]
504
531
  # @return [Vedeu::Colours::Background]
505
532
  def background(value = nil)
@@ -508,13 +535,7 @@ module Vedeu
508
535
  options[:background] = value
509
536
  end
510
537
 
511
- # Sets the foreground of the terminal.
512
- #
513
- # Vedeu.configure do
514
- # foreground '#ffff00'
515
- # # ...
516
- # end
517
- #
538
+ # {include:file:docs/configuration/foreground.md}
518
539
  # @param value [String]
519
540
  # @return [Vedeu::Colours::Foreground]
520
541
  def foreground(value = nil)
@@ -557,6 +578,12 @@ module Vedeu
557
578
  end
558
579
  alias mouse mouse!
559
580
 
581
+ protected
582
+
583
+ # @!attribute [r] default
584
+ # @return [Hash]
585
+ attr_reader :default
586
+
560
587
  private
561
588
 
562
589
  # @macro raise_invalid_syntax
@@ -565,6 +592,14 @@ module Vedeu
565
592
  'Terminal mode can be set to either :cooked, :fake or :raw'
566
593
  end
567
594
 
595
+ # @return [Hash]
596
+ def log_options!
597
+ options.each do |option, value|
598
+ Vedeu.log(type: :config,
599
+ message: "#{option}: #{value.inspect}")
600
+ end
601
+ end
602
+
568
603
  # Returns the options set via the configuration API DSL or an
569
604
  # empty Hash when none were set.
570
605
  #
@@ -18,9 +18,7 @@ module Vedeu
18
18
 
19
19
  include Vedeu::Common
20
20
 
21
- # Return the configured background colour for the client
22
- # application.
23
- #
21
+ # {include:file:docs/configuration/background.md}
24
22
  # @return [String|Symbol]
25
23
  def background
26
24
  instance.options[:background]
@@ -121,9 +119,7 @@ module Vedeu
121
119
  instance.options[:drb_width]
122
120
  end
123
121
 
124
- # Return the configured foreground colour for the client
125
- # application.
126
- #
122
+ # {include:file:docs/configuration/foreground.md}
127
123
  # @return [String|Symbol]
128
124
  def foreground
129
125
  instance.options[:foreground]
@@ -175,7 +171,9 @@ module Vedeu
175
171
  #
176
172
  # @return [Boolean]
177
173
  def log?
178
- present?(log)
174
+ return false if log == false || log.nil?
175
+
176
+ true
179
177
  end
180
178
 
181
179
  # @return [Array<Symbol>]
@@ -372,6 +370,8 @@ module Vedeu
372
370
 
373
371
  end # Eigenclass
374
372
 
373
+ include Vedeu::Common
374
+
375
375
  # @!attribute [r] options
376
376
  # @return [Hash<Symbol => void>]
377
377
  attr_reader :options
@@ -391,7 +391,7 @@ module Vedeu
391
391
  def configure(opts = {}, &block)
392
392
  @options.merge!(opts)
393
393
 
394
- @options.merge!(Config::API.configure(&block)) if block_given?
394
+ @options.merge!(Config::API.configure(defaults, &block)) if block_given?
395
395
 
396
396
  Vedeu::Configuration
397
397
  end
@@ -421,7 +421,7 @@ module Vedeu
421
421
  foreground: :default,
422
422
  height: nil,
423
423
  interactive: true,
424
- log: nil,
424
+ log: '/tmp/vedeu_bootstrap.log',
425
425
  log_except: [],
426
426
  log_only: [],
427
427
  mouse: true,
@@ -23,16 +23,13 @@ module Vedeu
23
23
  # message: 'A useful debugging message: Error!')
24
24
  #
25
25
  # @macro vedeu_logging_log_param_message
26
- # @param force [Boolean] When evaluates to true will attempt
27
- # to write to the log file regardless of the Configuration
28
- # setting.
29
26
  # @param type [Symbol] Colour code messages in the log file
30
27
  # depending on their source. See
31
28
  # {Vedeu::Configuration.log_types}
32
29
  #
33
30
  # @return [String]
34
- def log(message:, force: false, type: :info)
35
- if (Vedeu.config.log? || force) && Vedeu.config.loggable?(type)
31
+ def log(message:, type: :info)
32
+ if Vedeu.config.log? && Vedeu.config.loggable?(type)
36
33
  output = log_entry(type, message)
37
34
  logger.debug(output)
38
35
  output
@@ -1,2 +1,4 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'vedeu/plugins/plugins'
2
4
  require 'vedeu/plugins/plugin'
@@ -109,7 +109,7 @@ module Vedeu
109
109
  #
110
110
  # @return [void]
111
111
  def terminate!
112
- Vedeu.log(message: 'Exiting gracefully.')
112
+ Vedeu.log(message: "Exiting gracefully.\n")
113
113
 
114
114
  $stdin = STDIN
115
115
  $stdout = STDOUT
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.14'
6
+ VERSION = '0.8.15'
7
7
 
8
8
  end
@@ -1,8 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'vedeu/dsl/all'
2
4
  require 'vedeu/cells/all'
3
5
 
4
- # frozen_string_literal: true
5
-
6
6
  module Vedeu
7
7
 
8
8
  module Views
@@ -43,6 +43,12 @@ module Vedeu
43
43
  it { subject.must_equal(false) }
44
44
  end
45
45
 
46
+ context 'when the variable is false' do
47
+ let(:_value) { false }
48
+
49
+ it { subject.must_equal(true) }
50
+ end
51
+
46
52
  context 'when the variable is not nil or empty' do
47
53
  let(:_value) { 'not empty' }
48
54
 
@@ -107,6 +113,38 @@ module Vedeu
107
113
  end
108
114
  end
109
115
 
116
+ describe '#empty_value?' do
117
+ let(:_value) {}
118
+
119
+ subject { instance.empty_value?(_value) }
120
+
121
+ context 'when the value does not respond to :empty?' do
122
+ context 'when the value is nil' do
123
+ it { subject.must_equal(true) }
124
+ end
125
+
126
+ context 'whent the value is not nil' do
127
+ let(:_value) { :some_value }
128
+
129
+ it { subject.must_equal(false) }
130
+ end
131
+ end
132
+
133
+ context 'when the value responds to :empty?' do
134
+ context 'when the value is not empty' do
135
+ let(:_value) { [:some_value] }
136
+
137
+ it { subject.must_equal(false) }
138
+ end
139
+
140
+ context 'when the value is empty' do
141
+ let(:_value) { [] }
142
+
143
+ it { subject.must_equal(true) }
144
+ end
145
+ end
146
+ end
147
+
110
148
  describe '#boolean?' do
111
149
  subject { instance.boolean?(_value) }
112
150
 
@@ -277,6 +315,12 @@ module Vedeu
277
315
  it { subject.must_equal(true) }
278
316
  end
279
317
 
318
+ context 'when the variable is false' do
319
+ let(:_value) { false }
320
+
321
+ it { subject.must_equal(false) }
322
+ end
323
+
280
324
  context 'when the variable is not nil or empty' do
281
325
  let(:_value) { 'not empty' }
282
326
 
@@ -23,7 +23,8 @@ module Vedeu
23
23
  describe API do
24
24
 
25
25
  let(:described) { Vedeu::Config::API }
26
- let(:instance) { described.new }
26
+ let(:instance) { described.new(default) }
27
+ let(:default) { {} }
27
28
 
28
29
  after { test_configuration }
29
30
 
@@ -65,10 +65,12 @@ module Vedeu
65
65
 
66
66
  describe '.log' do
67
67
  context 'when the log is not configured' do
68
- it { described.log.must_equal(nil) }
68
+ it 'sends messages to the default log' do
69
+ described.log.must_equal('/tmp/vedeu_bootstrap.log')
70
+ end
69
71
  end
70
72
 
71
- context 'when the log is configured' do
73
+ context 'when the log is configured with a filename' do
72
74
  before do
73
75
  Vedeu.configure do
74
76
  log '/tmp/vedeu.log'
@@ -77,21 +79,31 @@ module Vedeu
77
79
 
78
80
  it { described.log.must_equal('/tmp/vedeu.log') }
79
81
  end
82
+
83
+ context 'when the log is configured with false' do
84
+ before do
85
+ Vedeu.configure do
86
+ log false
87
+ end
88
+ end
89
+
90
+ it { described.log.must_equal(nil) }
91
+ end
80
92
  end
81
93
 
82
94
  describe '.log?' do
83
- context 'when the log is not configured' do
84
- it { described.log?.must_equal(false) }
95
+ context 'when the log is enabled' do
96
+ it { described.log?.must_equal(true) }
85
97
  end
86
98
 
87
- context 'when the log is configured' do
99
+ context 'when the log is disabled' do
88
100
  before do
89
101
  Vedeu.configure do
90
- log '/tmp/vedeu.log'
102
+ log false
91
103
  end
92
104
  end
93
105
 
94
- it { described.log?.must_equal(true) }
106
+ it { described.log?.must_equal(false) }
95
107
  end
96
108
  end
97
109
 
@@ -14,14 +14,15 @@ module Vedeu
14
14
 
15
15
  let(:described) { Vedeu::Logging::Log }
16
16
  let(:_message) { 'Some message...' }
17
- let(:force) { false }
18
17
  let(:type) { :info }
19
18
 
20
19
  describe '.log' do
21
- subject { described.log(message: _message, force: force, type: type) }
20
+ before { Vedeu.config.stubs(:log?).returns(enabled) }
22
21
 
23
- context 'when :force is true' do
24
- let(:force) { true }
22
+ subject { described.log(message: _message, type: type) }
23
+
24
+ context 'when the log is enabled' do
25
+ let(:enabled) { true }
25
26
  let(:expected) {
26
27
  "\e[97m[info] \e[39m\e[37mSome message...\e[39m"
27
28
  }
@@ -29,8 +30,8 @@ module Vedeu
29
30
  it { subject.must_equal(expected) }
30
31
  end
31
32
 
32
- context 'when :force is false' do
33
- let(:force) { false }
33
+ context 'when the log is disabled' do
34
+ let(:enabled) { false }
34
35
 
35
36
  it { subject.must_equal(nil) }
36
37
  end
data/test/test_helper.rb CHANGED
@@ -118,14 +118,13 @@ def test_configuration
118
118
 
119
119
  Vedeu.configure do
120
120
  colour_mode 16_777_216
121
- # adds ~40ms to test run speed
122
- # debug!
123
- # profile!
124
121
 
125
- # if debug! above is commented out, then only
126
- # `Vedeu.log(type: <any type>, message: '...', force: true)`
127
- # will be logged, otherwise every `Vedeu.log` will be logged.
122
+ # debug! # adds ~40ms to test run speed
123
+
128
124
  # log '/tmp/vedeu_test_helper.log'
125
+ log false
126
+
127
+ # profile!
129
128
  end
130
129
 
131
130
  # Vedeu::Repositories.reset!
data/vedeu.gemspec CHANGED
@@ -1,4 +1,5 @@
1
1
  # coding: utf-8
2
+ # frozen_string_literal: true
2
3
  lib = File.expand_path('../lib', __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
 
@@ -26,7 +27,7 @@ Gem::Specification.new do |spec|
26
27
  spec.add_development_dependency 'minitest', '5.8.4'
27
28
  spec.add_development_dependency 'minitest-reporters', '1.1.7'
28
29
  spec.add_development_dependency 'mocha', '1.1.0'
29
- spec.add_development_dependency 'rubocop', '0.37.0'
30
+ spec.add_development_dependency 'rubocop', '0.37.1'
30
31
  spec.add_development_dependency 'simplecov', '0.11.2'
31
32
  spec.add_development_dependency 'simplecov-console', '0.3.0'
32
33
  spec.add_development_dependency 'yard', '0.8.7.6'
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vedeu
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.14
4
+ version: 0.8.15
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gavin Laking
@@ -100,14 +100,14 @@ dependencies:
100
100
  requirements:
101
101
  - - '='
102
102
  - !ruby/object:Gem::Version
103
- version: 0.37.0
103
+ version: 0.37.1
104
104
  type: :development
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
108
  - - '='
109
109
  - !ruby/object:Gem::Version
110
- version: 0.37.0
110
+ version: 0.37.1
111
111
  - !ruby/object:Gem::Dependency
112
112
  name: simplecov
113
113
  requirement: !ruby/object:Gem::Requirement
@@ -243,9 +243,11 @@ files:
243
243
  - docs/chars.md
244
244
  - docs/colours_styles.md
245
245
  - docs/configuration.md
246
+ - docs/configuration/background.md
246
247
  - docs/configuration/drb.md
247
248
  - docs/configuration/drb_host.md
248
249
  - docs/configuration/drb_port.md
250
+ - docs/configuration/foreground.md
249
251
  - docs/configuration/interactive.md
250
252
  - docs/configuration/run_once.md
251
253
  - docs/configuration/standalone.md