Class: Mxup::Config

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_profileObject (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_pathObject (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_namesObject (readonly)

Returns the value of attribute layout_names.



22
23
24
# File 'lib/mxup/config.rb', line 22

def layout_names
  @layout_names
end

#layoutsObject (readonly)

Returns the value of attribute layouts.



22
23
24
# File 'lib/mxup/config.rb', line 22

def layouts
  @layouts
end

#live_envObject (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_dirObject (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

#profileObject (readonly)

Returns the value of attribute profile.



22
23
24
# File 'lib/mxup/config.rb', line 22

def profile
  @profile
end

#profile_namesObject (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_envObject (readonly)

Returns the value of attribute required_env.



22
23
24
# File 'lib/mxup/config.rb', line 22

def required_env
  @required_env
end

#rootObject (readonly)

Returns the value of attribute root.



22
23
24
# File 'lib/mxup/config.rb', line 22

def root
  @root
end

#sessionObject (readonly)

Returns the value of attribute session.



22
23
24
# File 'lib/mxup/config.rb', line 22

def session
  @session
end

#setupObject (readonly)

Returns the value of attribute setup.



22
23
24
# File 'lib/mxup/config.rb', line 22

def setup
  @setup
end

#windowsObject (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_layoutObject



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