Class: Mxup::Config
- Inherits:
-
Object
- Object
- Mxup::Config
- Defined in:
- lib/mxup/config.rb
Overview
Parsed mxup YAML config. Pure data; no tmux or filesystem side effects.
Profiles (optional): a config may declare a profiles: map where each
entry is a partial override on top of the base setup, windows, and
layouts. A single active profile is resolved at parse time and its
overrides are merged in before the rest of the Config is built — so the
rest of the system (Launcher, Reconciler, StatusView…) never has to know
about profiles.
Constant Summary collapse
- KNOWN_TOP_LEVEL_KEYS =
%w[session setup root live_env required_env windows layouts profiles default_profile].freeze
- KNOWN_WINDOW_KEYS =
%w[root command env wait_for live_env commands].freeze
- KNOWN_LAYOUT_GROUP_KEYS =
%w[panes split].freeze
- KNOWN_PROFILE_KEYS =
%w[setup root layouts live_env windows].freeze
Instance Attribute Summary collapse
-
#default_profile ⇒ Object
readonly
Returns the value of attribute default_profile.
-
#env_file_path ⇒ Object
readonly
Returns the value of attribute env_file_path.
-
#layout_names ⇒ Object
readonly
Returns the value of attribute layout_names.
-
#layouts ⇒ Object
readonly
Returns the value of attribute layouts.
-
#live_env ⇒ Object
readonly
Returns the value of attribute live_env.
-
#live_env_dir ⇒ Object
readonly
Returns the value of attribute live_env_dir.
-
#profile ⇒ Object
readonly
Returns the value of attribute profile.
-
#profile_names ⇒ Object
readonly
Returns the value of attribute profile_names.
-
#required_env ⇒ Object
readonly
Returns the value of attribute required_env.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
-
#session ⇒ Object
readonly
Returns the value of attribute session.
-
#setup ⇒ Object
readonly
Returns the value of attribute setup.
-
#windows ⇒ Object
readonly
Returns the value of attribute windows.
Instance Method Summary collapse
- #default_layout ⇒ Object
-
#effective_window_order(layout_name) ⇒ Object
Returns an ordered list of entries describing how windows should appear in tmux under the given layout.
-
#find_group_for_window(layout_name, window_name) ⇒ Object
Returns [group, index_within_group] or nil.
- #groups_for(layout_name) ⇒ Object
-
#initialize(path, profile: nil) ⇒ Config
constructor
A new instance of Config.
- #window_by_name(name) ⇒ Object
Constructor Details
#initialize(path, profile: nil) ⇒ Config
Returns a new instance of Config.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/mxup/config.rb', line 26 def initialize(path, profile: nil) raw = YAML.safe_load(File.read(path), permitted_classes: [Symbol]) validate_keys!(raw, KNOWN_TOP_LEVEL_KEYS, 'top level') resolve_profile!(raw, profile) @session = raw.fetch('session') @setup = raw['setup']&.strip @live_env_dir = config_base_dir(path) @live_env = parse_live_env(raw['live_env']) @required_env = parse_required_env(raw['required_env']) @env_file_path = env_file_path_for(path) load_env_file_into_env! @root = resolve_root(raw['root'], path) @windows = parse_windows(raw.fetch('windows')) validate_window_live_env! @layouts, @layout_names = parse_layouts(raw['layouts']) end |
Instance Attribute Details
#default_profile ⇒ Object (readonly)
Returns the value of attribute default_profile.
22 23 24 |
# File 'lib/mxup/config.rb', line 22 def default_profile @default_profile end |
#env_file_path ⇒ Object (readonly)
Returns the value of attribute env_file_path.
22 23 24 |
# File 'lib/mxup/config.rb', line 22 def env_file_path @env_file_path end |
#layout_names ⇒ Object (readonly)
Returns the value of attribute layout_names.
22 23 24 |
# File 'lib/mxup/config.rb', line 22 def layout_names @layout_names end |
#layouts ⇒ Object (readonly)
Returns the value of attribute layouts.
22 23 24 |
# File 'lib/mxup/config.rb', line 22 def layouts @layouts end |
#live_env ⇒ Object (readonly)
Returns the value of attribute live_env.
22 23 24 |
# File 'lib/mxup/config.rb', line 22 def live_env @live_env end |
#live_env_dir ⇒ Object (readonly)
Returns the value of attribute live_env_dir.
22 23 24 |
# File 'lib/mxup/config.rb', line 22 def live_env_dir @live_env_dir end |
#profile ⇒ Object (readonly)
Returns the value of attribute profile.
22 23 24 |
# File 'lib/mxup/config.rb', line 22 def profile @profile end |
#profile_names ⇒ Object (readonly)
Returns the value of attribute profile_names.
22 23 24 |
# File 'lib/mxup/config.rb', line 22 def profile_names @profile_names end |
#required_env ⇒ Object (readonly)
Returns the value of attribute required_env.
22 23 24 |
# File 'lib/mxup/config.rb', line 22 def required_env @required_env end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
22 23 24 |
# File 'lib/mxup/config.rb', line 22 def root @root end |
#session ⇒ Object (readonly)
Returns the value of attribute session.
22 23 24 |
# File 'lib/mxup/config.rb', line 22 def session @session end |
#setup ⇒ Object (readonly)
Returns the value of attribute setup.
22 23 24 |
# File 'lib/mxup/config.rb', line 22 def setup @setup end |
#windows ⇒ Object (readonly)
Returns the value of attribute windows.
22 23 24 |
# File 'lib/mxup/config.rb', line 22 def windows @windows end |
Instance Method Details
#default_layout ⇒ Object
43 44 45 |
# File 'lib/mxup/config.rb', line 43 def default_layout @layout_names.first end |
#effective_window_order(layout_name) ⇒ Object
Returns an ordered list of entries describing how windows should appear in tmux under the given layout. Each entry is one of:
{ type: :group, name: <group name>, group: PaneGroup }
{ type: :standalone, name: <window name> }
56 57 58 59 60 61 62 63 64 |
# File 'lib/mxup/config.rb', line 56 def effective_window_order(layout_name) groups = groups_for(layout_name) grouped = groups.flat_map(&:window_names).to_set entries = groups.map { |g| { type: :group, name: g.name, group: g } } @windows.each do |w| entries << { type: :standalone, name: w.name } unless grouped.include?(w.name) end entries end |
#find_group_for_window(layout_name, window_name) ⇒ Object
Returns [group, index_within_group] or nil.
71 72 73 74 75 76 77 |
# File 'lib/mxup/config.rb', line 71 def find_group_for_window(layout_name, window_name) groups_for(layout_name).each do |g| idx = g.window_names.index(window_name) return [g, idx] if idx end nil end |
#groups_for(layout_name) ⇒ Object
47 48 49 50 |
# File 'lib/mxup/config.rb', line 47 def groups_for(layout_name) return [] if layout_name.nil? @layouts.fetch(layout_name) end |
#window_by_name(name) ⇒ Object
66 67 68 |
# File 'lib/mxup/config.rb', line 66 def window_by_name(name) @windows.find { |w| w.name == name } end |