Class: FormatStaged::Entry

Inherits:
Object
  • Object
show all
Defined in:
lib/format-staged/entry.rb

Constant Summary collapse

PATTERN =
/^:(?<src_mode>\d+) (?<dst_mode>\d+) (?<src_hash>[a-f0-9]+) (?<dst_hash>[a-f0-9]+) (?<status>[A-Z])(?<score>\d+)?\t(?<src_path>[^\t]+)(?:\t(?<dst_path>[^\t]+))?$/

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(line, root:) ⇒ Entry

Returns a new instance of Entry.



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/format-staged/entry.rb', line 7

def initialize(line, root:)
  matches = line.match(PATTERN) or raise "Cannot parse output #{line}"
  @src_mode = matches[:src_mode]
  @dst_mode = matches[:dst_mode]
  @src_hash = matches[:src_hash]
  @dst_hash = matches[:dst_hash]
  @status = matches[:status]
  @score = matches[:score]&.to_i
  @src_path = matches[:src_path]
  @dst_path = matches[:dst_path]
  @path = File.expand_path(@src_path, root)
  @root = root
end

Instance Attribute Details

#dst_hashObject (readonly)

Returns the value of attribute dst_hash.



5
6
7
# File 'lib/format-staged/entry.rb', line 5

def dst_hash
  @dst_hash
end

#dst_modeObject (readonly)

Returns the value of attribute dst_mode.



5
6
7
# File 'lib/format-staged/entry.rb', line 5

def dst_mode
  @dst_mode
end

#dst_pathObject (readonly)

Returns the value of attribute dst_path.



5
6
7
# File 'lib/format-staged/entry.rb', line 5

def dst_path
  @dst_path
end

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/format-staged/entry.rb', line 5

def path
  @path
end

#rootObject (readonly)

Returns the value of attribute root.



5
6
7
# File 'lib/format-staged/entry.rb', line 5

def root
  @root
end

#scoreObject (readonly)

Returns the value of attribute score.



5
6
7
# File 'lib/format-staged/entry.rb', line 5

def score
  @score
end

#src_hashObject (readonly)

Returns the value of attribute src_hash.



5
6
7
# File 'lib/format-staged/entry.rb', line 5

def src_hash
  @src_hash
end

#src_modeObject (readonly)

Returns the value of attribute src_mode.



5
6
7
# File 'lib/format-staged/entry.rb', line 5

def src_mode
  @src_mode
end

#src_pathObject (readonly)

Returns the value of attribute src_path.



5
6
7
# File 'lib/format-staged/entry.rb', line 5

def src_path
  @src_path
end

#statusObject (readonly)

Returns the value of attribute status.



5
6
7
# File 'lib/format-staged/entry.rb', line 5

def status
  @status
end

Instance Method Details

#matches?(patterns) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
29
30
31
32
33
# File 'lib/format-staged/entry.rb', line 25

def matches?(patterns)
  result = false
  patterns.each do |pattern|
    if File.fnmatch? pattern, path, File::FNM_EXTGLOB
      result = true
    end
  end
  result
end

#symlink?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/format-staged/entry.rb', line 21

def symlink?
  @dst_mode == '120000'
end