Class: Pvectl::Presenters::Base Abstract
- Inherits:
-
Object
- Object
- Pvectl::Presenters::Base
- Defined in:
- lib/pvectl/presenters/base.rb
Overview
Direct Known Subclasses
AptPackage, Backup, Capability, Config::Context, Container, Disk, DnsConfig, HostsFile, JournalEntry, Node, OperationResult, Service, Snapshot, SnapshotOperationResult, Storage, Subscription, SyslogEntry, TaskEntry, TaskLogLine, Template, TimeConfig, Vm, Volume
Instance Method Summary collapse
-
#columns ⇒ Array<String>
Returns column headers for table format.
-
#extra_columns ⇒ Array<String>
Returns additional columns for wide format.
-
#extra_values(model, **context) ⇒ Array<String, nil>
Returns additional values for wide format.
-
#tags_array ⇒ Array<String>
Returns tags as array.
-
#tags_display ⇒ String
Returns tags as comma-separated string.
-
#template_display ⇒ String
Returns template display string.
-
#to_description(model) ⇒ Hash
Converts model to description format (kubectl-style vertical layout).
-
#to_hash(model) ⇒ Hash
Converts model to hash for JSON/YAML format.
-
#to_row(model, **context) ⇒ Array<String, nil>
Converts model to table row values.
-
#to_wide_row(model, **context) ⇒ Array<String, nil>
Converts model to wide table row values.
-
#uptime_human ⇒ String
Returns uptime in human-readable format.
-
#wide_columns ⇒ Array<String>
Returns extended column headers for wide format.
Instance Method Details
#columns ⇒ Array<String>
Returns column headers for table format.
42 43 44 |
# File 'lib/pvectl/presenters/base.rb', line 42 def columns raise NotImplementedError, "#{self.class}#columns must be implemented" end |
#extra_columns ⇒ Array<String>
Returns additional columns for wide format. Override in subclass to add extra columns.
58 59 60 |
# File 'lib/pvectl/presenters/base.rb', line 58 def extra_columns [] end |
#extra_values(model, **context) ⇒ Array<String, nil>
Returns additional values for wide format. Override in subclass to add extra values.
88 89 90 |
# File 'lib/pvectl/presenters/base.rb', line 88 def extra_values(model, **context) [] end |
#tags_array ⇒ Array<String>
Returns tags as array.
134 135 136 137 138 139 |
# File 'lib/pvectl/presenters/base.rb', line 134 def = resource. return [] if .nil? || .empty? .split(";").map(&:strip) end |
#tags_display ⇒ String
Returns tags as comma-separated string.
144 145 146 147 |
# File 'lib/pvectl/presenters/base.rb', line 144 def arr = arr.empty? ? "-" : arr.join(", ") end |
#template_display ⇒ String
Returns template display string.
152 153 154 |
# File 'lib/pvectl/presenters/base.rb', line 152 def template_display resource.template? ? "yes" : "-" end |
#to_description(model) ⇒ Hash
Converts model to description format (kubectl-style vertical layout). By default, delegates to to_hash. Override for custom describe output.
106 107 108 |
# File 'lib/pvectl/presenters/base.rb', line 106 def to_description(model) to_hash(model) end |
#to_hash(model) ⇒ Hash
Converts model to hash for JSON/YAML format.
97 98 99 |
# File 'lib/pvectl/presenters/base.rb', line 97 def to_hash(model) raise NotImplementedError, "#{self.class}#to_hash must be implemented" end |
#to_row(model, **context) ⇒ Array<String, nil>
Converts model to table row values.
68 69 70 |
# File 'lib/pvectl/presenters/base.rb', line 68 def to_row(model, **context) raise NotImplementedError, "#{self.class}#to_row must be implemented" end |
#to_wide_row(model, **context) ⇒ Array<String, nil>
Converts model to wide table row values. By default, appends extra_values to to_row.
78 79 80 |
# File 'lib/pvectl/presenters/base.rb', line 78 def to_wide_row(model, **context) to_row(model, **context) + extra_values(model, **context) end |
#uptime_human ⇒ String
Returns uptime in human-readable format. Delegates to resource.uptime. Override in subclasses with custom logic.
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/pvectl/presenters/base.rb', line 114 def uptime_human uptime = resource.uptime return "-" if uptime.nil? || uptime.zero? days = uptime / 86_400 hours = (uptime % 86_400) / 3600 minutes = (uptime % 3600) / 60 if days.positive? "#{days}d #{hours}h" elsif hours.positive? "#{hours}h #{minutes}m" else "#{minutes}m" end end |
#wide_columns ⇒ Array<String>
Returns extended column headers for wide format. By default, appends extra_columns to columns.
50 51 52 |
# File 'lib/pvectl/presenters/base.rb', line 50 def wide_columns columns + extra_columns end |