output_mode 1.7.0 → 1.7.1

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
  SHA256:
3
- metadata.gz: 4beed6d9f51548ef131e475bb68aa9c6d6fe079e39672b4691566ff80ffb65c2
4
- data.tar.gz: df648ec5ee82875c189123dca55bfaabfa3bf4d5ba24e160be1d0f15bb1a624b
3
+ metadata.gz: 0e8e7233d045c7642d64d90ac04d0af8561ce06f1fb24125f4a849ce5cbf40c6
4
+ data.tar.gz: acba4cceeb3626e5350f637fa6d3422115622e1e5ef2cde3dbb5186b6df20173
5
5
  SHA512:
6
- metadata.gz: 4e19a13c9e5b0b6e3fa497aadd4d1ed59bb6297fd8063f88d7f6a01bd4dd84f801baae9be8efe46a0e42e63024824d227fa51c0f7b84ad283baec7f5960fb2f6
7
- data.tar.gz: b9ea560f3b42886ca8baaa04452cc5e4557c82ddf23068b095b544f2649b425b5b30a30212d6ef7955cd1fde41c624b4f9fbe73cfc32a3a2ddb1092f6d16fd54
6
+ metadata.gz: 8faf122204eb774c31e5feefdd68cab98f12817b04a904e5c1270dc9cd95496ef0585494a48f7a4ff93050ed41607dc0bb50aab9ba2c3513e8335bd426165df9
7
+ data.tar.gz: a460316ed1272d74ba1b8a398c9d8b197cdfa9d1682304648ad04534cb52437b0bbbe48d9eb308412e143898ff58ed4530201cac19bdba56a5dbbd9299bfb790
data/bin/demo CHANGED
@@ -30,7 +30,7 @@ require "output_mode"
30
30
  require 'erb'
31
31
 
32
32
  class DemoIndex < OutputMode::Formatters::Index
33
- constructor do
33
+ def register_all
34
34
  register(header: 'Integer', row_color: [:yellow, :bold]) { |i| i }
35
35
  register(header: 'Standard', header_color: [:strikethrough] ) { 'always visible' }
36
36
  if verbose?
@@ -38,10 +38,10 @@ class DemoIndex < OutputMode::Formatters::Index
38
38
  else
39
39
  register(header: 'Simplified') { 'simplified visible' }
40
40
  end
41
- if interactive?
42
- register(header: 'Interactive') { 'interactive visible' }
41
+ if humanize?
42
+ register(header: 'humanize') { 'humanize visible' }
43
43
  else
44
- register(header: 'Non Interactive') { 'non-interactive visible' }
44
+ register(header: 'Non humanize') { 'non-humanize visible' }
45
45
  end
46
46
  register(header: 'Yes/True') { true }
47
47
  register(header: 'No/False', row_color: [:clear]) { false }
@@ -50,7 +50,7 @@ class DemoIndex < OutputMode::Formatters::Index
50
50
  end
51
51
 
52
52
  class DemoShow < OutputMode::Formatters::Show
53
- constructor do
53
+ def register_all
54
54
  register(header: 'Integer') { |i| i }
55
55
  register(header: 'Standard') { 'always visible' }
56
56
  if verbose?
@@ -58,10 +58,10 @@ class DemoShow < OutputMode::Formatters::Show
58
58
  else
59
59
  register(header: 'Simplified') { 'simplified visible' }
60
60
  end
61
- if interactive?
62
- register(header: 'Interactive') { 'interactive visible' }
61
+ if humanize?
62
+ register(header: 'humanize') { 'humanize visible' }
63
63
  else
64
- register(header: 'Non Interactive') { 'non-interactive visible' }
64
+ register(header: 'Non humanize') { 'non-humanize visible' }
65
65
  end
66
66
  register(header: 'Yes/True', section: :boolean) { true }
67
67
  register(header: 'No/False', section: :boolean) { false }
@@ -82,7 +82,7 @@ puts <<~EOF
82
82
 
83
83
  #==============================================================================
84
84
  # Default Demo Index
85
- # Simplified in interactive shells, verbose in non-interactive
85
+ # Simplified in humanize shells, verbose in non-humanize
86
86
  #==============================================================================
87
87
  #{DemoIndex.render(*data)}
88
88
 
@@ -97,16 +97,16 @@ puts <<~EOF
97
97
  #{DemoIndex.render(*data, verbose: false)}
98
98
 
99
99
  #==============================================================================
100
- # Force Interactive
101
- # Always print as if the shell is interactive
100
+ # Force humanize
101
+ # Always print as if the shell is humanize
102
102
  #==============================================================================
103
- #{DemoIndex.render(*data, interactive: true)}
103
+ #{DemoIndex.render(*data, humanize: true)}
104
104
 
105
105
  #==============================================================================
106
- # Force Non-Interactive
107
- # Always print as if the shell is non-interactive
106
+ # Force Non-humanize
107
+ # Always print as if the shell is non-humanize
108
108
  #==============================================================================
109
- #{DemoIndex.render(*data, interactive: false)}
109
+ #{DemoIndex.render(*data, humanize: false)}
110
110
 
111
111
  #==============================================================================
112
112
  # Demo ASCII Index
@@ -121,7 +121,7 @@ puts <<~EOF
121
121
 
122
122
  #==============================================================================
123
123
  # Default Settings
124
- # Simplified in interactive shells, verbose in non-interactive
124
+ # Simplified in humanize shells, verbose in non-humanize
125
125
  #==============================================================================
126
126
  #{DemoShow.render(data.first)}
127
127
 
@@ -136,16 +136,16 @@ puts <<~EOF
136
136
  #{DemoShow.render(data.first, verbose: false)}
137
137
 
138
138
  #==============================================================================
139
- # Force Interactive
140
- # Always print as if the shell is interactive
139
+ # Force humanize
140
+ # Always print as if the shell is humanize
141
141
  #==============================================================================
142
- #{DemoShow.render(data.first, interactive: true)}
142
+ #{DemoShow.render(data.first, humanize: true)}
143
143
 
144
144
  #==============================================================================
145
- # Force Non-Interactive
146
- # Always print as if the shell is non-interactive
145
+ # Force Non-humanize
146
+ # Always print as if the shell is non-humanize
147
147
  #==============================================================================
148
- #{DemoShow.render(data.first, interactive: false)}
148
+ #{DemoShow.render(data.first, humanize: false)}
149
149
 
150
150
  #==============================================================================
151
151
  # Demo ASCII Index
@@ -28,25 +28,18 @@ require 'tty-color'
28
28
 
29
29
  module OutputMode
30
30
  class Formatter
31
- def self.constructor(&block)
32
- @constructor ||= block
33
- end
34
-
35
31
  def self.build(*objects, **opts)
36
- new(*objects, **opts).tap do |policy|
37
- next unless constructor
38
- policy.instance_exec(&constructor)
39
- end
32
+ new(*objects, **opts).tap(&:register_all)
40
33
  end
41
34
 
42
35
  def self.render(*objects, **opts)
43
36
  build(*objects, **opts).render
44
37
  end
45
38
 
46
- def initialize(*objects, verbose: nil, ascii: nil, interactive: nil, color: nil)
39
+ def initialize(*objects, verbose: nil, ascii: nil, humanize: nil, color: nil)
47
40
  @verbose = verbose
48
41
  @ascii = ascii
49
- @interactive = interactive
42
+ @humanize = humanize
50
43
  @color = color
51
44
 
52
45
  # NOTE: This is intentionally not exposed on the base class
@@ -54,6 +47,10 @@ module OutputMode
54
47
  @objects = objects
55
48
  end
56
49
 
50
+ # Override in sub-classes to define the attributes
51
+ def register_all
52
+ end
53
+
57
54
  def callables
58
55
  @callables ||= Callables.new
59
56
  end
@@ -89,16 +86,16 @@ module OutputMode
89
86
  build_output.render(*@objects)
90
87
  end
91
88
 
92
- def interactive?
93
- if @interactive.nil?
89
+ def humanize?
90
+ if @humanize.nil?
94
91
  $stdout.tty?
95
92
  else
96
- @interactive
93
+ @humanize
97
94
  end
98
95
  end
99
96
 
100
97
  def color?
101
- if @color.nil? && (ascii? || !interactive?)
98
+ if @color.nil? && (ascii? || !humanize?)
102
99
  false
103
100
  elsif @color.nil?
104
101
  TTY::Color.color?
@@ -109,7 +106,7 @@ module OutputMode
109
106
 
110
107
  def ascii?
111
108
  if @ascii.nil?
112
- !interactive?
109
+ !humanize?
113
110
  else
114
111
  @ascii
115
112
  end
@@ -117,7 +114,7 @@ module OutputMode
117
114
 
118
115
  def verbose?
119
116
  if @verbose.nil?
120
- !interactive?
117
+ !humanize?
121
118
  else
122
119
  @verbose
123
120
  end
@@ -135,7 +132,7 @@ module OutputMode
135
132
 
136
133
  def default(value = nil)
137
134
  @default = value unless value.nil?
138
- @default ? @default : (interactive? ? '(none)' : '')
135
+ @default ? @default : (humanize? ? '(none)' : '')
139
136
  end
140
137
 
141
138
  def time(value = nil)
@@ -40,7 +40,7 @@ module OutputMode
40
40
  end
41
41
 
42
42
  def build_output
43
- if interactive?
43
+ if humanize?
44
44
  opts = {
45
45
  renderer: ascii? ? :ascii : :unicode,
46
46
  header_color: header_color,
@@ -43,7 +43,7 @@ module OutputMode
43
43
 
44
44
  def template(value = nil)
45
45
  @template = value unless value.nil?
46
- @template ? @template : (interactive? ? DEFAULT_ERB : NON_INTERACTIVE_ERB)
46
+ @template ? @template : (humanize? ? DEFAULT_ERB : NON_INTERACTIVE_ERB)
47
47
  end
48
48
 
49
49
  def scope(value = nil)
@@ -25,5 +25,5 @@
25
25
  #==============================================================================
26
26
 
27
27
  module OutputMode
28
- VERSION = "1.7.0"
28
+ VERSION = "1.7.1"
29
29
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: output_mode
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.0
4
+ version: 1.7.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - William McCumsite
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-10-05 00:00:00.000000000 Z
11
+ date: 2021-10-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tty-table