Class: Archive_r::Traverser

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/archive_r.rb,
ext/archive_r/archive_r_ext.cc

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Object

Traverser.new(paths, passphrases: [], formats: [], metadata_keys: []) -> Traverser



980
981
982
# File 'ext/archive_r/archive_r_ext.cc', line 980

def initialize(paths, opts = nil)
  __archive_r_c_initialize(paths, Archive_r.normalize_options(opts))
end

Class Method Details

.__archive_r_c_openObject



85
# File 'lib/archive_r.rb', line 85

alias_method :__archive_r_c_open, :open

.open(*args) ⇒ Object

Traverser.open(path, opts = {}) { |traverser| … } -> result of block



1032
1033
1034
# File 'ext/archive_r/archive_r_ext.cc', line 1032

def open(paths, opts = nil, &block)
  __archive_r_c_open(paths, Archive_r.normalize_options(opts), &block)
end

.open_hierarchy(hierarchy, opts = nil, &block) ⇒ Object



91
92
93
# File 'lib/archive_r.rb', line 91

def open_hierarchy(hierarchy, opts = nil, &block)
  open([hierarchy], opts, &block)
end

Instance Method Details

#__archive_r_c_initializeObject



96
# File 'lib/archive_r.rb', line 96

alias_method :__archive_r_c_initialize, :initialize

#countObject

Count entries



103
104
105
106
107
# File 'lib/archive_r.rb', line 103

def count
  n = 0
  each { |entry| n += 1 }
  n
end

#eachObject



1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
# File 'ext/archive_r/archive_r_ext.cc', line 1004

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;
}