Class: Ace::GitCommit::Models::StageResult

Inherits:
Object
  • Object
show all
Defined in:
lib/ace/git_commit/models/stage_result.rb

Overview

StageResult represents the outcome of staging a file or set of files

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file_path:, success:, error_message: nil, file_size: nil, status: nil) ⇒ StageResult



10
11
12
13
14
15
16
# File 'lib/ace/git_commit/models/stage_result.rb', line 10

def initialize(file_path:, success:, error_message: nil, file_size: nil, status: nil)
  @file_path = file_path
  @success = success
  @error_message = error_message
  @file_size = file_size
  @status = status # :modified, :new, :deleted, etc.
end

Instance Attribute Details

#error_messageObject (readonly)

Returns the value of attribute error_message.



8
9
10
# File 'lib/ace/git_commit/models/stage_result.rb', line 8

def error_message
  @error_message
end

#file_pathObject (readonly)

Returns the value of attribute file_path.



8
9
10
# File 'lib/ace/git_commit/models/stage_result.rb', line 8

def file_path
  @file_path
end

#file_sizeObject (readonly)

Returns the value of attribute file_size.



8
9
10
# File 'lib/ace/git_commit/models/stage_result.rb', line 8

def file_size
  @file_size
end

#statusObject (readonly)

Returns the value of attribute status.



8
9
10
# File 'lib/ace/git_commit/models/stage_result.rb', line 8

def status
  @status
end

#successObject (readonly)

Returns the value of attribute success.



8
9
10
# File 'lib/ace/git_commit/models/stage_result.rb', line 8

def success
  @success
end

Instance Method Details

#human_file_sizeString

Get a human-readable file size



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ace/git_commit/models/stage_result.rb', line 33

def human_file_size
  return nil unless @file_size

  if @file_size < 1024
    "#{@file_size} B"
  elsif @file_size < 1024 * 1024
    "#{(@file_size / 1024.0).round(1)} KB"
  elsif @file_size < 1024 * 1024 * 1024
    "#{(@file_size / (1024.0 * 1024.0)).round(2)} MB"
  else
    "#{(@file_size / (1024.0 * 1024.0 * 1024.0)).round(2)} GB"
  end
end

#large_file?Boolean

Check if this is a large file (>50MB)



26
27
28
29
# File 'lib/ace/git_commit/models/stage_result.rb', line 26

def large_file?
  return false unless @file_size
  @file_size > 50 * 1024 * 1024 # 50MB in bytes
end

#status_indicatorString

Get status indicator emoji



49
50
51
52
53
54
55
# File 'lib/ace/git_commit/models/stage_result.rb', line 49

def status_indicator
  if success?
    "✓"
  else
    "✗"
  end
end

#success?Boolean

Check if staging was successful



20
21
22
# File 'lib/ace/git_commit/models/stage_result.rb', line 20

def success?
  @success
end

#to_hHash

Convert to hash for debugging



59
60
61
62
63
64
65
66
67
# File 'lib/ace/git_commit/models/stage_result.rb', line 59

def to_h
  {
    file_path: @file_path,
    success: @success,
    error_message: @error_message,
    file_size: @file_size,
    status: @status
  }
end