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
- #hunk_index ⇒ Object readonly
- #line_count ⇒ Object (also: #count, #size) readonly
- #new_lines ⇒ Object readonly
- #new_start ⇒ Object readonly
- #old_lines ⇒ Object readonly
- #old_start ⇒ Object readonly
Instance Method Summary collapse
- #delta ⇒ Object
-
#each ⇒ Object
If given a block, yields each line that is part of the current hunk.
-
#each_line ⇒ Object
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)
#hunk_index ⇒ Object (readonly)
#line_count ⇒ Object (readonly) Also known as: count, size
#new_lines ⇒ Object (readonly)
#new_start ⇒ Object (readonly)
#old_lines ⇒ Object (readonly)
#old_start ⇒ Object (readonly)
Instance Method Details
#delta ⇒ Object
4 5 6 |
# File 'lib/rugged/diff/hunk.rb', line 4 def delta @owner end |
#each_line {|line| ... } ⇒ self #each_line ⇒ Enumerator
If given a block, yields each line that is part of the current hunk.
If no block is given, an enumerator is returned instead.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'ext/rugged/rugged_diff_hunk.c', line 57
static VALUE rb_git_diff_hunk_each_line(VALUE self)
{
git_patch *patch;
int error = 0, l, 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_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) {
const git_diff_line *line;
error = git_patch_get_line_in_hunk(&line, patch, hunk_idx, l);
if (error) break;
rb_yield(rugged_diff_line_new(line));
}
rugged_exception_check(error);
return self;
}
|
#each_line {|line| ... } ⇒ self #each_line ⇒ Enumerator
If given a block, yields each line that is part of the current hunk.
If no block is given, an enumerator is returned instead.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'ext/rugged/rugged_diff_hunk.c', line 57
static VALUE rb_git_diff_hunk_each_line(VALUE self)
{
git_patch *patch;
int error = 0, l, 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_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) {
const git_diff_line *line;
error = git_patch_get_line_in_hunk(&line, patch, hunk_idx, l);
if (error) break;
rb_yield(rugged_diff_line_new(line));
}
rugged_exception_check(error);
return self;
}
|
#inspect ⇒ Object
8 9 10 |
# File 'lib/rugged/diff/hunk.rb', line 8 def inspect "#<#{self.class.name}:#{object_id} {header: #{header.inspect}, count: #{count.inspect}}>" end |
#lines ⇒ Object
Returns an Array containing all lines of the hunk.
13 14 15 |
# File 'lib/rugged/diff/hunk.rb', line 13 def lines each_line.to_a end |