Class: Motoko::Config
- Inherits:
-
Object
- Object
- Motoko::Config
- Defined in:
- lib/motoko/config.rb
Instance Attribute Summary collapse
-
#columns ⇒ Object
Returns the value of attribute columns.
-
#columns_spec ⇒ Object
Returns the value of attribute columns_spec.
-
#shortcuts ⇒ Object
Returns the value of attribute shortcuts.
-
#sort_by ⇒ Object
Returns the value of attribute sort_by.
Instance Method Summary collapse
- #default_columns_spec ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #load_classes(directory) ⇒ Object
- #load_config(directory) ⇒ Object
- #load_only_config(filename) ⇒ Object
- #load_project_config ⇒ Object
- #load_system_config ⇒ Object
- #load_user_config ⇒ Object
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
9 10 11 12 13 14 15 16 17 18 |
# File 'lib/motoko/config.rb', line 9 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 load_project_config end |
Instance Attribute Details
#columns ⇒ Object
Returns the value of attribute columns.
7 8 9 |
# File 'lib/motoko/config.rb', line 7 def columns @columns end |
#columns_spec ⇒ Object
Returns the value of attribute columns_spec.
7 8 9 |
# File 'lib/motoko/config.rb', line 7 def columns_spec @columns_spec end |
#shortcuts ⇒ Object
Returns the value of attribute shortcuts.
7 8 9 |
# File 'lib/motoko/config.rb', line 7 def shortcuts @shortcuts end |
#sort_by ⇒ Object
Returns the value of attribute sort_by.
7 8 9 |
# File 'lib/motoko/config.rb', line 7 def sort_by @sort_by end |
Instance Method Details
#default_columns_spec ⇒ Object
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/motoko/config.rb', line 64 def default_columns_spec YAML.safe_load(" ---\n host:\n resolver: identity\n customer:\n formatter: ellipsis\n max_length: 20\n cpu:\n resolver: cpu\n os:\n resolver: os\n human_name: Operating System\n reboot_required:\n resolver: reboot_required\n formatter: boolean\n human_name: R\n COLUMNS_SPEC\nend\n") |
#load_classes(directory) ⇒ Object
58 59 60 61 62 |
# File 'lib/motoko/config.rb', line 58 def load_classes(directory) Dir["#{directory}/formatters/*.rb", "#{directory}/resolvers/*.rb"].sort.each do |file| require file end end |
#load_config(directory) ⇒ Object
41 42 43 44 |
# File 'lib/motoko/config.rb', line 41 def load_config(directory) load_classes(directory) load_only_config(File.join(directory, 'config.yaml')) end |
#load_only_config(filename) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/motoko/config.rb', line 46 def load_only_config(filename) 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 |
#load_project_config ⇒ Object
37 38 39 |
# File 'lib/motoko/config.rb', line 37 def load_project_config load_only_config('.motoko.yaml') end |
#load_system_config ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/motoko/config.rb', line 20 def load_system_config [ '/usr/local/etc/motoko', '/etc/motoko', ].each do |d| if File.directory?(d) load_config(d) break end end end |
#load_user_config ⇒ Object
32 33 34 35 |
# File 'lib/motoko/config.rb', line 32 def load_user_config d = File.('~/.config/motoko') load_config(d) if File.directory?(d) end |