Class: EacGit::Local::ChangedFile

Inherits:
Object
  • Object
show all
Defined in:
lib/eac_git/local/changed_file.rb

Constant Summary collapse

QUOTED_PATH_PATTERN =
/\A"(.+)"\z/.freeze
STATUS_LINE_PATTERN =
/\A(.)(.)\s(.+)\z/.freeze
TO_HASH_ATTRIBUTES =
%i[absolute_path index path worktree].freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.by_porcelain_v1_line(local_repo, line) ⇒ Object



11
12
13
14
15
# File 'lib/eac_git/local/changed_file.rb', line 11

def by_porcelain_v1_line(local_repo, line)
  STATUS_LINE_PATTERN.match(line.gsub(/\n\z/, '')).then do |m|
    new(local_repo, m[1], m[2], parse_status_line_path(m[3]).to_pathname)
  end
end

.parse_status_line_path(path) ⇒ String

Parameters:

  • path (String)

Returns:

  • (String)


19
20
21
22
# File 'lib/eac_git/local/changed_file.rb', line 19

def parse_status_line_path(path)
  m = QUOTED_PATH_PATTERN.match(path)
  m ? m[1] : path
end

Instance Method Details

#absolute_pathPathname

Returns:

  • (Pathname)


28
29
30
# File 'lib/eac_git/local/changed_file.rb', line 28

def absolute_path
  path.expand_path(local_repo.root_path)
end

#add?Boolean

Returns:

  • (Boolean)


33
34
35
# File 'lib/eac_git/local/changed_file.rb', line 33

def add?
  (index == '?' && worktree == '?') || (index == 'A' && worktree == ' ')
end

#delete?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/eac_git/local/changed_file.rb', line 38

def delete?
  [index, worktree].include?('D')
end

#modify?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/eac_git/local/changed_file.rb', line 43

def modify?
  [index, worktree].include?('M')
end

#to_hHash

Returns:

  • (Hash)


48
49
50
# File 'lib/eac_git/local/changed_file.rb', line 48

def to_h
  compact_to_h(*TO_HASH_ATTRIBUTES)
end