Class: FormatStaged::Entry
- Inherits:
-
Object
- Object
- FormatStaged::Entry
- Defined in:
- lib/format-staged/entry.rb
Overview
Entry in the git index.
Data as produced by ‘git diff-index`
Constant Summary collapse
- PATTERN =
/^ :(?<src_mode>\d+)\s (?<dst_mode>\d+)\s (?<src_hash>[a-f0-9]+)\s (?<dst_hash>[a-f0-9]+)\s (?<status>[A-Z])(?<score>\d+)?\t (?<src_path>[^\t]+) (?:\t(?<dst_path>[^\t]+))? $/x.freeze
Instance Attribute Summary collapse
-
#dst_hash ⇒ Object
readonly
Returns the value of attribute dst_hash.
-
#dst_mode ⇒ Object
readonly
Returns the value of attribute dst_mode.
-
#dst_path ⇒ Object
readonly
Returns the value of attribute dst_path.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#root ⇒ Object
readonly
Returns the value of attribute root.
-
#score ⇒ Object
readonly
Returns the value of attribute score.
-
#src_hash ⇒ Object
readonly
Returns the value of attribute src_hash.
-
#src_mode ⇒ Object
readonly
Returns the value of attribute src_mode.
-
#src_path ⇒ Object
readonly
Returns the value of attribute src_path.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#initialize(line, root:) ⇒ Entry
constructor
A new instance of Entry.
- #matches?(patterns) ⇒ Boolean
- #symlink? ⇒ Boolean
Constructor Details
#initialize(line, root:) ⇒ Entry
Returns a new instance of Entry.
21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/format-staged/entry.rb', line 21 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.(@src_path, root) @root = root end |
Instance Attribute Details
#dst_hash ⇒ Object (readonly)
Returns the value of attribute dst_hash.
19 20 21 |
# File 'lib/format-staged/entry.rb', line 19 def dst_hash @dst_hash end |
#dst_mode ⇒ Object (readonly)
Returns the value of attribute dst_mode.
19 20 21 |
# File 'lib/format-staged/entry.rb', line 19 def dst_mode @dst_mode end |
#dst_path ⇒ Object (readonly)
Returns the value of attribute dst_path.
19 20 21 |
# File 'lib/format-staged/entry.rb', line 19 def dst_path @dst_path end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
19 20 21 |
# File 'lib/format-staged/entry.rb', line 19 def path @path end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
19 20 21 |
# File 'lib/format-staged/entry.rb', line 19 def root @root end |
#score ⇒ Object (readonly)
Returns the value of attribute score.
19 20 21 |
# File 'lib/format-staged/entry.rb', line 19 def score @score end |
#src_hash ⇒ Object (readonly)
Returns the value of attribute src_hash.
19 20 21 |
# File 'lib/format-staged/entry.rb', line 19 def src_hash @src_hash end |
#src_mode ⇒ Object (readonly)
Returns the value of attribute src_mode.
19 20 21 |
# File 'lib/format-staged/entry.rb', line 19 def src_mode @src_mode end |
#src_path ⇒ Object (readonly)
Returns the value of attribute src_path.
19 20 21 |
# File 'lib/format-staged/entry.rb', line 19 def src_path @src_path end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
19 20 21 |
# File 'lib/format-staged/entry.rb', line 19 def status @status end |
Instance Method Details
#matches?(patterns) ⇒ Boolean
39 40 41 42 43 44 45 |
# File 'lib/format-staged/entry.rb', line 39 def matches?(patterns) result = false patterns.each do |pattern| result = true if File.fnmatch? pattern, path, File::FNM_EXTGLOB end result end |
#symlink? ⇒ Boolean
35 36 37 |
# File 'lib/format-staged/entry.rb', line 35 def symlink? @dst_mode == '120000' end |