Class: FormatStaged::Entry
- Inherits:
-
Object
- Object
- FormatStaged::Entry
- Defined in:
- lib/format-staged/entry.rb
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.
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/format-staged/entry.rb', line 17 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.
15 16 17 |
# File 'lib/format-staged/entry.rb', line 15 def dst_hash @dst_hash end |
#dst_mode ⇒ Object (readonly)
Returns the value of attribute dst_mode.
15 16 17 |
# File 'lib/format-staged/entry.rb', line 15 def dst_mode @dst_mode end |
#dst_path ⇒ Object (readonly)
Returns the value of attribute dst_path.
15 16 17 |
# File 'lib/format-staged/entry.rb', line 15 def dst_path @dst_path end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
15 16 17 |
# File 'lib/format-staged/entry.rb', line 15 def path @path end |
#root ⇒ Object (readonly)
Returns the value of attribute root.
15 16 17 |
# File 'lib/format-staged/entry.rb', line 15 def root @root end |
#score ⇒ Object (readonly)
Returns the value of attribute score.
15 16 17 |
# File 'lib/format-staged/entry.rb', line 15 def score @score end |
#src_hash ⇒ Object (readonly)
Returns the value of attribute src_hash.
15 16 17 |
# File 'lib/format-staged/entry.rb', line 15 def src_hash @src_hash end |
#src_mode ⇒ Object (readonly)
Returns the value of attribute src_mode.
15 16 17 |
# File 'lib/format-staged/entry.rb', line 15 def src_mode @src_mode end |
#src_path ⇒ Object (readonly)
Returns the value of attribute src_path.
15 16 17 |
# File 'lib/format-staged/entry.rb', line 15 def src_path @src_path end |
#status ⇒ Object (readonly)
Returns the value of attribute status.
15 16 17 |
# File 'lib/format-staged/entry.rb', line 15 def status @status end |
Instance Method Details
#matches?(patterns) ⇒ Boolean
35 36 37 38 39 40 41 |
# File 'lib/format-staged/entry.rb', line 35 def matches?(patterns) result = false patterns.each do |pattern| result = true if File.fnmatch? pattern, path, File::FNM_EXTGLOB end result end |
#symlink? ⇒ Boolean
31 32 33 |
# File 'lib/format-staged/entry.rb', line 31 def symlink? @dst_mode == '120000' end |