Class: FormatStaged::Entry
- Inherits:
-
Object
- Object
- FormatStaged::Entry
- 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
-
#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.
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.(@src_path, root) @root = root end |
Instance Attribute Details
#dst_hash ⇒ Object (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_mode ⇒ Object (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_path ⇒ Object (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 |
#path ⇒ Object (readonly)
Returns the value of attribute path.
5 6 7 |
# File 'lib/format-staged/entry.rb', line 5 def path @path end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
5 6 7 |
# File 'lib/format-staged/entry.rb', line 5 def root @root end |
#score ⇒ Object (readonly)
Returns the value of attribute score.
5 6 7 |
# File 'lib/format-staged/entry.rb', line 5 def score @score end |
#src_hash ⇒ Object (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_mode ⇒ Object (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_path ⇒ Object (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 |
#status ⇒ Object (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
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
21 22 23 |
# File 'lib/format-staged/entry.rb', line 21 def symlink? @dst_mode == '120000' end |