Module: Carson::Runtime::Session

Included in:
Carson::Runtime
Defined in:
lib/carson/runtime/session.rb

Instance Method Summary collapse

Instance Method Details

#session!(task: nil, json_output: false) ⇒ Object

Reads and displays current session state for this repository.



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/carson/runtime/session.rb', line 11

def session!( task: nil, json_output: false )
	if task
		update_session( worktree: nil, pr: nil, task: task )
		state = read_session
		return session_finish(
			result: state.merge( command: "session", status: "ok" ),
			exit_code: EXIT_OK, json_output: json_output
		)
	end

	state = read_session
	session_finish(
		result: state.merge( command: "session", status: "ok" ),
		exit_code: EXIT_OK, json_output: json_output
	)
end

#session_clear!(json_output: false) ⇒ Object

Clears session state for this repository.



29
30
31
32
33
34
35
36
# File 'lib/carson/runtime/session.rb', line 29

def session_clear!( json_output: false )
	path = session_file_path
	File.delete( path ) if File.exist?( path )
	session_finish(
		result: { command: "session clear", status: "ok", repo: repo_root },
		exit_code: EXIT_OK, json_output: json_output
	)
end

#update_session(worktree: nil, pr: nil, task: nil) ⇒ Object

Records session state — called as a side effect from other commands. Only non-nil values are updated; nil values preserve existing state.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/carson/runtime/session.rb', line 40

def update_session( worktree: nil, pr: nil, task: nil )
	state = read_session

	if worktree == :clear
		state.delete( :worktree )
	elsif worktree
		state[ :worktree ] = worktree
	end

	if pr == :clear
		state.delete( :pr )
	elsif pr
		state[ :pr ] = pr
	end

	state[ :task ] = task if task
	state[ :repo ] = repo_root
	state[ :updated_at ] = Time.now.utc.iso8601

	write_session( state )
end