Module: Carson::Runtime::Session
- Included in:
- Carson::Runtime
- Defined in:
- lib/carson/runtime/session.rb
Instance Method Summary collapse
-
#session!(task: nil, json_output: false) ⇒ Object
Reads and displays current session state for this repository.
-
#session_clear!(json_output: false) ⇒ Object
Clears session state for the current session.
-
#session_list ⇒ Object
Returns all active sessions for this repository.
-
#update_session(worktree: nil, pr: nil, task: nil) ⇒ Object
Records session state — called as a side effect from other commands.
Instance Method Details
#session!(task: nil, json_output: false) ⇒ Object
Reads and displays current session state for this repository.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/carson/runtime/session.rb', line 12 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 the current session.
30 31 32 33 34 35 36 37 |
# File 'lib/carson/runtime/session.rb', line 30 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 |
#session_list ⇒ Object
Returns all active sessions for this repository. Each entry is a parsed session state hash with staleness annotation.
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/carson/runtime/session.rb', line 67 def session_list dir = session_repo_dir return [] unless Dir.exist?( dir ) Dir.glob( File.join( dir, "*.json" ) ).filter_map do |path| data = JSON.parse( File.read( path ), symbolize_names: true ) rescue next data[ :stale ] = session_stale?( data ) data end 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.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/carson/runtime/session.rb', line 41 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[ :session_id ] = session_id state[ :pid ] = Process.pid state[ :updated_at ] = Time.now.utc.iso8601 write_session( state ) end |