Class: OmaGem::Config
- Inherits:
-
Object
- Object
- OmaGem::Config
- Includes:
- DSL::Bar, DSL::Misc, DSL::Package, DSL::Plugin, DSL::Service, DSL::Snapshot, DSL::System, DSL::Theme, DSL::Toggle
- Defined in:
- lib/omagem/config.rb
Overview
The DSL surface. A Config instance exposes all the management methods (theme, package, service, system, ...). The methods are defined in feature modules mixed in below, so the DSL is easy to extend and keep organized.
To build a reusable configuration without executing anything, pass a fake (recording) client to Config.new.
Constant Summary
Constants included from DSL::Bar
Constants included from DSL::Service
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#executed ⇒ Object
readonly
Every command that ran through #run, in order.
Instance Method Summary collapse
- #available_themes ⇒ Object
-
#current_theme ⇒ Object
Current theme name (from
omarchy theme current). -
#ensure_command! ⇒ Object
Raise CommandNotFound if the underlying
omarchybinary cannot be run. -
#initialize(client: OmaGem::Client.new, ignore_errors: false) ⇒ Config
constructor
A new instance of Config.
-
#package_installed?(*names) ⇒ Boolean
True when every named package is installed.
-
#package_present?(*names) ⇒ Boolean
True when at least one of the named packages is installed.
-
#run(*args) ⇒ Object
Run an Omarchy command and return the OmaGem::Client::Result.
- #valid_theme?(name) ⇒ Boolean
-
#validate_in!(value, allowed, label) ⇒ Object
Raise OmaGem::ArgumentError unless value is in the allowed list.
Methods included from DSL::Misc
#focus_app, #reminder, #screenrecord, #screenshot, #stop_screenrecord
Methods included from DSL::Snapshot
#create_snapshot, #restore_snapshot
Methods included from DSL::Toggle
#bar_visible, #idle, #nightlight, #notification_silencing, #toggle, #touchpad, #touchscreen
Methods included from DSL::Plugin
#add_plugin, #clone_plugin, #disable_plugin, #enable_plugin, #list_plugins, #remove_plugin
Methods included from DSL::Bar
#bar, #bar_move, #bar_position, #bar_put, #bar_set, #bar_transparent
Methods included from DSL::System
#channel, #current_font, #debug, #default_browser, #default_editor, #default_terminal, #font, #lock, #logout, #reboot, #shutdown, #update, #version
Methods included from DSL::Service
#install_app, #install_browser, #install_dev_env, #install_editor, #install_game, #install_service, #install_terminal, #remove_service
Methods included from DSL::Package
Methods included from DSL::Theme
#background, #background_next, #background_switcher, #install_theme, #refresh_theme, #remove_theme, #theme, #themes, #update_themes
Constructor Details
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
15 16 17 |
# File 'lib/omagem/config.rb', line 15 def client @client end |
#executed ⇒ Object (readonly)
Every command that ran through #run, in order. Each entry is the argument array.
25 26 27 |
# File 'lib/omagem/config.rb', line 25 def executed @executed end |
Instance Method Details
#available_themes ⇒ Object
66 67 68 |
# File 'lib/omagem/config.rb', line 66 def available_themes client.run('theme', 'list').stdout.lines.map(&:strip).reject(&:empty?) end |
#current_theme ⇒ Object
Current theme name (from omarchy theme current).
58 59 60 |
# File 'lib/omagem/config.rb', line 58 def current_theme client.run('theme', 'current').stdout end |
#ensure_command! ⇒ Object
Raise CommandNotFound if the underlying omarchy binary cannot be run.
38 39 40 41 42 43 |
# File 'lib/omagem/config.rb', line 38 def ensure_command! # A lightweight availability check: run "omarchy version". run('version') rescue Errno::ENOENT raise CommandNotFound, 'the `omarchy` CLI could not be found on PATH' end |
#package_installed?(*names) ⇒ Boolean
True when every named package is installed.
53 54 55 |
# File 'lib/omagem/config.rb', line 53 def package_installed?(*names) !client.run('pkg', 'missing', *names).success? end |
#package_present?(*names) ⇒ Boolean
True when at least one of the named packages is installed.
48 49 50 |
# File 'lib/omagem/config.rb', line 48 def package_present?(*names) client.run('pkg', 'present', *names).success? end |
#run(*args) ⇒ Object
Run an Omarchy command and return the OmaGem::Client::Result. Records the call and validates the exit status unless ignore_errors.
29 30 31 32 33 34 35 |
# File 'lib/omagem/config.rb', line 29 def run(*args) @executed << args result = client.run(*args) raise CommandFailed.new(args, result) unless result.success? result end |
#valid_theme?(name) ⇒ Boolean
62 63 64 |
# File 'lib/omagem/config.rb', line 62 def valid_theme?(name) available_themes.include?(name) end |
#validate_in!(value, allowed, label) ⇒ Object
Raise OmaGem::ArgumentError unless value is in the allowed list.
71 72 73 74 75 |
# File 'lib/omagem/config.rb', line 71 def validate_in!(value, allowed, label) return if allowed.include?(value.to_s) raise ArgumentError, "unknown #{label} #{value.inspect}; expected one of: #{allowed.join(', ')}" end |