Class: Pvectl::Commands::Get::Handlers::Time
- Inherits:
-
Object
- Object
- Pvectl::Commands::Get::Handlers::Time
- Includes:
- ResourceHandler
- Defined in:
- lib/pvectl/commands/get/handlers/time.rb,
sig/pvectl/commands/get/handlers/time.rbs
Overview
Handler for listing node time and timezone settings.
Implements ResourceHandler interface for the "time" resource type.
When --node is supplied, returns the time config for that single node.
Otherwise, iterates over all online nodes and aggregates their time configs.
Unreachable nodes (those that raise during fetch) are silently skipped so
one bad node does not abort the whole listing.
Instance Method Summary collapse
-
#connection ⇒ Pvectl::Connection
Builds API connection from current config.
-
#fetch_for(node_name) ⇒ Models::TimeConfig
Fetches the time config for a specific node, raising ResourceNotFoundError if the node itself does not exist in the cluster.
-
#initialize(repository: nil, node_repository: nil) ⇒ Time
constructor
Creates handler with optional repositories for dependency injection.
-
#list(node: nil, name: nil, args: [], storage: nil, **_options) ⇒ Array<Models::TimeConfig>
Lists time/timezone configs.
-
#node_repository ⇒ Repositories::Node
Node repository, lazily built.
-
#online_node_names ⇒ Array<String>
Names of online nodes (offline nodes are skipped because querying them is guaranteed to fail).
-
#presenter ⇒ Presenters::TimeConfig
Returns presenter for time configs.
-
#repository ⇒ Repositories::TimeConfig
Time repository, lazily built.
Methods included from ResourceHandler
Constructor Details
#initialize(repository: nil, node_repository: nil) ⇒ Time
Creates handler with optional repositories for dependency injection.
30 31 32 33 |
# File 'lib/pvectl/commands/get/handlers/time.rb', line 30 def initialize(repository: nil, node_repository: nil) @repository = repository @node_repository = node_repository end |
Instance Method Details
#connection ⇒ Pvectl::Connection
Builds API connection from current config.
101 102 103 104 105 106 107 |
# File 'lib/pvectl/commands/get/handlers/time.rb', line 101 def connection @connection ||= begin config_service = Pvectl::Config::Service.new config_service.load Pvectl::Connection.new(config_service.current_config) end end |
#fetch_for(node_name) ⇒ Models::TimeConfig
Fetches the time config for a specific node, raising ResourceNotFoundError if the node itself does not exist in the cluster.
72 73 74 75 76 77 78 |
# File 'lib/pvectl/commands/get/handlers/time.rb', line 72 def fetch_for(node_name) unless node_repository.get(node_name) raise Pvectl::ResourceNotFoundError, "Node not found: #{node_name}" end repository.fetch(node_name) end |
#list(node: nil, name: nil, args: [], storage: nil, **_options) ⇒ Array<Models::TimeConfig>
Lists time/timezone configs.
44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/pvectl/commands/get/handlers/time.rb', line 44 def list(node: nil, name: nil, args: [], storage: nil, **) return [fetch_for(node)] if node online_node_names.filter_map do |node_name| begin repository.fetch(node_name) rescue StandardError # Skip unreachable nodes - one bad node should not abort the listing. nil end end end |
#node_repository ⇒ Repositories::Node
Returns node repository, lazily built.
94 95 96 |
# File 'lib/pvectl/commands/get/handlers/time.rb', line 94 def node_repository @node_repository ||= Pvectl::Repositories::Node.new(connection) end |
#online_node_names ⇒ Array<String>
Names of online nodes (offline nodes are skipped because querying them is guaranteed to fail).
84 85 86 |
# File 'lib/pvectl/commands/get/handlers/time.rb', line 84 def online_node_names node_repository.list.select { |n| n.status == "online" }.map(&:name) end |
#presenter ⇒ Presenters::TimeConfig
Returns presenter for time configs.
60 61 62 |
# File 'lib/pvectl/commands/get/handlers/time.rb', line 60 def presenter Pvectl::Presenters::TimeConfig.new end |
#repository ⇒ Repositories::TimeConfig
Returns time repository, lazily built.
89 90 91 |
# File 'lib/pvectl/commands/get/handlers/time.rb', line 89 def repository @repository ||= Pvectl::Repositories::TimeConfig.new(connection) end |