Class: Rugged::Diff::Hunk
- Inherits:
-
Object
- Object
- Rugged::Diff::Hunk
- Includes:
- Enumerable
- Defined in:
- lib/rugged/diff/hunk.rb,
ext/rugged/rugged_diff_hunk.c
Instance Attribute Summary collapse
-
#header ⇒ Object
readonly
Returns the value of attribute header.
-
#line_count ⇒ Object
(also: #size, #count)
readonly
Returns the value of attribute line_count.
-
#owner ⇒ Object
(also: #delta)
readonly
Returns the value of attribute owner.
-
#range ⇒ Object
readonly
Returns the value of attribute range.
Instance Method Summary collapse
-
#each_line ⇒ Object
(also: #each)
If given a block, yields each line that is part of the current hunk.
- #inspect ⇒ Object
-
#lines ⇒ Object
Returns an Array containing all lines of the hunk.
Instance Attribute Details
#header ⇒ Object (readonly)
Returns the value of attribute header.
7 8 9 |
# File 'lib/rugged/diff/hunk.rb', line 7 def header @header end |
#line_count ⇒ Object (readonly) Also known as: size, count
Returns the value of attribute line_count.
7 8 9 |
# File 'lib/rugged/diff/hunk.rb', line 7 def line_count @line_count end |
#owner ⇒ Object (readonly) Also known as: delta
Returns the value of attribute owner.
7 8 9 |
# File 'lib/rugged/diff/hunk.rb', line 7 def owner @owner end |
#range ⇒ Object (readonly)
Returns the value of attribute range.
7 8 9 |
# File 'lib/rugged/diff/hunk.rb', line 7 def range @range end |
Instance Method Details
#each_line {|line| ... } ⇒ self #each_line ⇒ Enumerator Also known as: each
If given a block, yields each line that is part of the current hunk.
If no block is given, an enumerator is returned instead.
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'ext/rugged/rugged_diff_hunk.c', line 66
static VALUE rb_git_diff_hunk_each_line(VALUE self)
{
git_diff_patch *patch;
char line_origin;
const char *content;
size_t content_len = 0;
int error = 0, l, old_lineno, new_lineno, lines_count, hunk_idx;
if (!rb_block_given_p()) {
return rb_funcall(self, rb_intern("to_enum"), 1, CSTR2SYM("each_line"), self);
}
Data_Get_Struct(rugged_owner(self), git_diff_patch, patch);
lines_count = FIX2INT(rb_iv_get(self, "@line_count"));
hunk_idx = FIX2INT(rb_iv_get(self, "@hunk_index"));
for (l = 0; l < lines_count; ++l) {
error = git_diff_patch_get_line_in_hunk(
&line_origin, &content, &content_len, &old_lineno, &new_lineno, patch, hunk_idx, l);
if (error) break;
rb_yield(rugged_diff_line_new(self, line_origin, content, content_len, old_lineno, new_lineno));
}
rugged_exception_check(error);
return self;
}
|
#inspect ⇒ Object
13 14 15 |
# File 'lib/rugged/diff/hunk.rb', line 13 def inspect "#<#{self.class.name}:#{object_id} {header: #{header.inspect}, range: #{range.inspect}>" end |
#lines ⇒ Object
Returns an Array containing all lines of the hunk.
18 19 20 |
# File 'lib/rugged/diff/hunk.rb', line 18 def lines each_line.to_a end |