Class: Archive_r::Traverser
- Inherits:
-
Object
- Object
- Archive_r::Traverser
- Includes:
- Enumerable
- Defined in:
- lib/archive_r.rb,
ext/archive_r/archive_r_ext.cc
Class Method Summary collapse
- .__archive_r_c_open ⇒ Object
-
.open(*args) ⇒ Object
Traverser.open(path, opts = {}) { |traverser| … } -> result of block.
- .open_hierarchy(hierarchy, opts = nil, &block) ⇒ Object
Instance Method Summary collapse
- #__archive_r_c_initialize ⇒ Object
-
#count ⇒ Object
Count entries.
- #each ⇒ Object
-
#initialize(*args) ⇒ Object
constructor
Traverser.new(paths, passphrases: [], formats: [], metadata_keys: []) -> Traverser.
Constructor Details
#initialize(*args) ⇒ Object
Traverser.new(paths, passphrases: [], formats: [], metadata_keys: []) -> Traverser
978 979 980 |
# File 'ext/archive_r/archive_r_ext.cc', line 978 def initialize(paths, opts = nil) __archive_r_c_initialize(paths, Archive_r.(opts)) end |
Class Method Details
.__archive_r_c_open ⇒ Object
96 |
# File 'lib/archive_r.rb', line 96 alias_method :__archive_r_c_open, :open |
.open(*args) ⇒ Object
Traverser.open(path, opts = {}) { |traverser| … } -> result of block
1030 1031 1032 |
# File 'ext/archive_r/archive_r_ext.cc', line 1030 def open(paths, opts = nil, &block) __archive_r_c_open(paths, Archive_r.(opts), &block) end |
.open_hierarchy(hierarchy, opts = nil, &block) ⇒ Object
102 103 104 |
# File 'lib/archive_r.rb', line 102 def open_hierarchy(hierarchy, opts = nil, &block) open([hierarchy], opts, &block) end |
Instance Method Details
#__archive_r_c_initialize ⇒ Object
107 |
# File 'lib/archive_r.rb', line 107 alias_method :__archive_r_c_initialize, :initialize |
#count ⇒ Object
Count entries
114 115 116 117 118 |
# File 'lib/archive_r.rb', line 114 def count n = 0 each { |entry| n += 1 } n end |
#each ⇒ Object
1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 |
# File 'ext/archive_r/archive_r_ext.cc', line 1002
static VALUE traverser_each(VALUE self) {
Traverser *traverser = traverser_unwrap(self);
// If no block given, return Enumerator
if (!rb_block_given_p()) {
return rb_funcall(self, rb_intern("to_enum"), 1, ID2SYM(rb_intern("each")));
}
try {
for (auto it = traverser->begin(); it != traverser->end(); ++it) {
Entry &entry = *it;
VALUE rb_entry = entry_wrap(entry);
rb_ensure(yield_entry, rb_entry, entry_invalidate, rb_entry);
}
} catch (const std::exception &e) {
rb_raise(rb_eRuntimeError, "Error during traversal: %s", e.what());
}
return self;
}
|