Class: Ace::Tmux::Models::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/tmux/models/session.rb

Overview

Represents a tmux session configuration

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, root: nil, windows: [], pre_window: nil, startup_window: nil, on_project_start: [], on_project_exit: [], attach: true, tmux_options: nil) ⇒ Session

Returns a new instance of Session.

Parameters:

  • name (String)

    Session name

  • root (String, nil) (defaults to: nil)

    Base working directory

  • windows (Array<Window>) (defaults to: [])

    Window configurations

  • pre_window (String, nil) (defaults to: nil)

    Command to run before each window/pane

  • startup_window (String, nil) (defaults to: nil)

    Window to select after creation

  • on_project_start (Array<String>) (defaults to: [])

    Commands to run before session creation

  • on_project_exit (Array<String>) (defaults to: [])

    Commands to run on session exit

  • attach (Boolean) (defaults to: true)

    Whether to attach after creation

  • tmux_options (String, nil) (defaults to: nil)

    Additional tmux options



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ace/tmux/models/session.rb', line 21

def initialize(
  name:,
  root: nil,
  windows: [],
  pre_window: nil,
  startup_window: nil,
  on_project_start: [],
  on_project_exit: [],
  attach: true,
  tmux_options: nil
)
  @name = name
  @root = root
  @windows = windows
  @pre_window = pre_window
  @startup_window = startup_window
  @on_project_start = Array(on_project_start)
  @on_project_exit = Array(on_project_exit)
  @attach = attach
  @tmux_options = tmux_options
end

Instance Attribute Details

#attachObject (readonly)

Returns the value of attribute attach.



8
9
10
# File 'lib/ace/tmux/models/session.rb', line 8

def attach
  @attach
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/ace/tmux/models/session.rb', line 8

def name
  @name
end

#on_project_exitObject (readonly)

Returns the value of attribute on_project_exit.



8
9
10
# File 'lib/ace/tmux/models/session.rb', line 8

def on_project_exit
  @on_project_exit
end

#on_project_startObject (readonly)

Returns the value of attribute on_project_start.



8
9
10
# File 'lib/ace/tmux/models/session.rb', line 8

def on_project_start
  @on_project_start
end

#pre_windowObject (readonly)

Returns the value of attribute pre_window.



8
9
10
# File 'lib/ace/tmux/models/session.rb', line 8

def pre_window
  @pre_window
end

#rootObject

Returns the value of attribute root.



8
9
10
# File 'lib/ace/tmux/models/session.rb', line 8

def root
  @root
end

#startup_windowObject (readonly)

Returns the value of attribute startup_window.



8
9
10
# File 'lib/ace/tmux/models/session.rb', line 8

def startup_window
  @startup_window
end

#tmux_optionsObject (readonly)

Returns the value of attribute tmux_options.



8
9
10
# File 'lib/ace/tmux/models/session.rb', line 8

def tmux_options
  @tmux_options
end

#windowsObject (readonly)

Returns the value of attribute windows.



8
9
10
# File 'lib/ace/tmux/models/session.rb', line 8

def windows
  @windows
end

Instance Method Details

#attach?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/ace/tmux/models/session.rb', line 43

def attach?
  @attach != false
end

#to_hObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/ace/tmux/models/session.rb', line 47

def to_h
  hash = {
    "name" => @name,
    "windows" => @windows.map(&:to_h),
    "attach" => @attach
  }
  hash["root"] = @root if @root
  hash["pre_window"] = @pre_window if @pre_window
  hash["startup_window"] = @startup_window if @startup_window
  hash["on_project_start"] = @on_project_start unless @on_project_start.empty?
  hash["on_project_exit"] = @on_project_exit unless @on_project_exit.empty?
  hash["tmux_options"] = @tmux_options if @tmux_options
  hash
end