Sha256: 1b923561deb2b6e477a5deb72386d973c7ca0506a5e76190dcf6094fe325e7ab
Contents?: true
Size: 1.84 KB
Versions: 2
Compression:
Stored size: 1.84 KB
Contents
# frozen_string_literal: true require 'yaml' module Motoko class Config attr_accessor :columns, :sort_by, :columns_spec, :shortcuts def initialize @columns = %w[host customer role] @sort_by = %w[customer host] @shortcuts = Hash.new { {} } @columns_spec = Hash.new { {} }.merge(default_columns_spec) load_system_config load_user_config end def load_system_config [ '/usr/local/etc/motoko', '/etc/motoko', ].each do |d| if File.directory?(d) load_config(d) break end end end def load_user_config d = File.expand_path('~/.config/motoko') load_config(d) if File.directory?(d) end def load_config(directory) load_classes(directory) filename = File.join(directory, 'config.yaml') return unless File.readable?(filename) config = YAML.safe_load(File.read(filename)) @columns = config.delete('columns') if config.key?('columns') @sort_by = config.delete('sort_by') if config.key?('sort_by') @shortcuts.merge!(config.delete('shortcuts')) if config.key?('shortcuts') @columns_spec.merge!(config.delete('columns_spec')) if config.key?('columns_spec') end def load_classes(directory) Dir["#{directory}/formatters/*.rb", "#{directory}/resolvers/*.rb"].sort.each do |file| require file end end def default_columns_spec YAML.safe_load(<<~COLUMNS_SPEC) --- host: resolver: identity customer: formatter: ellipsis max_length: 20 cpu: resolver: cpu os: resolver: os human_name: Operating System reboot_required: resolver: reboot_required formatter: boolean human_name: R COLUMNS_SPEC end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
motoko-1.1.0 | lib/motoko/config.rb |
motoko-1.0.0 | lib/motoko/config.rb |