lib/dir_model/import/path.rb in dir_model-0.3.0 vs lib/dir_model/import/path.rb in dir_model-0.3.1

- old
+ new

@@ -3,24 +3,23 @@ class Path # Csv attr_reader :path attr_reader :index attr_reader :current_path - attr_reader :previous_path def initialize(path) - @path = path + @path, @index = path, -1 reset! end def size @size ||= ruby_path.size end def reset! @index = -1 - @current_path = @ruby_path = @previous_path = nil + @current_path = @ruby_path = nil end def start? index == -1 end @@ -28,48 +27,29 @@ def end? index.nil? end def next_path - @next_path ||= _read_path + ruby_path[index+1] end + def previous_path + return nil if index < 1 + ruby_path[index-1] + end + def read_path - @previous_path = @current_path - unless caching_value? - @current_path = _read_path { forward! } - end + return if end? + @index += 1 + @current_path = ruby_path[index] + set_end unless current_path current_path end protected - def caching_value? - if @next_path - @current_path = @next_path - @next_path = nil - forward! - true - else - false - end - end - def ruby_path - @ruby_path ||= Pathname.glob("#{path}/**/*").each - end - - def _read_path - path = ruby_path.next.to_path - yield if block_given? - path - rescue StopIteration - set_end - nil - end - - def forward! - @index += 1 + @ruby_path ||= ::Dir.glob("#{path}/**/*") end def set_end @current_path = @index = nil end