Class: OutputMode::Formatters::Show
Instance Method Summary
collapse
#ascii?, build, #callables, #color?, #default, #format, #humanize?, #no, #register, #register_all, #render, render, #time, #verbose?, #yes
Constructor Details
#initialize(object, **opts) ⇒ Show
Limit the policy to a single object
36
37
38
|
# File 'lib/output_mode/formatters/show.rb', line 36
def initialize(object, **opts)
super
end
|
Instance Method Details
#build_output ⇒ Object
54
55
56
57
58
59
60
61
|
# File 'lib/output_mode/formatters/show.rb', line 54
def build_output
opts = {
template: template,
colorize: color?,
bind: scope.instance_exec { binding }
}
OutputMode::Outputs::Templated.new(*callables, **opts)
end
|
#each(section = nil) {|value, field:, padding:, **config| ... } ⇒ Object
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/output_mode/formatters/show.rb', line 67
def each(section = nil, &block)
selected = if section == nil
callables
elsif section == :default
callables.config_select(:section, :default, nil)
else
callables.config_select(:section, section)
end
objs = selected.pad_each(object).map do |callable, opts|
field = opts[:field]
padding = opts[:padding]
value = callable.call(object)
[value, { field: field, padding: padding }]
end
objs.each do |model, opts|
block.call(model, **opts)
end
end
|
#object ⇒ Object
40
41
42
|
# File 'lib/output_mode/formatters/show.rb', line 40
def object
@objects.first
end
|
#pastel ⇒ Object
Library for colorizing the output. It is automatically disabled when the colorize flag is false
93
94
95
|
# File 'lib/output_mode/formatters/show.rb', line 93
def pastel
@pastel ||= Pastel.new(enabled: color?)
end
|
#scope(value = nil) ⇒ Object
49
50
51
52
|
# File 'lib/output_mode/formatters/show.rb', line 49
def scope(value = nil)
@scope = value unless value.nil?
@scope ? @scope : self
end
|
#template(value = nil) ⇒ Object
44
45
46
47
|
# File 'lib/output_mode/formatters/show.rb', line 44
def template(value = nil)
@template = value unless value.nil?
@template ? @template : (humanize? ? DEFAULT_ERB : NON_INTERACTIVE_ERB)
end
|