lib/aranha/fixtures/download.rb in aranha-0.4.0 vs lib/aranha/fixtures/download.rb in aranha-0.5.0

- old
+ new

@@ -1,14 +1,17 @@ # frozen_string_literal: true module Aranha module Fixtures class Download - def initialize(prefix, download) - @prefix = prefix + attr_reader :pending + + def initialize(options) + @prefix = options.fetch(:prefix) @prefix = '' if @prefix.blank? - @download = download + @download = options.fetch(:download) + @pending = options.fetch(:pending) end def run url_files.each do |f| Rails.logger.info(relative_path(f)) @@ -17,17 +20,18 @@ end private def url_files - files = [] - Dir["#{fixtures_root}/**/*.url"].map do |path| - files << path if match_pattern(path) - end - files + Dir["#{fixtures_root}/**/*.url"].select { |path| select_path?(path) } end - def match_pattern(path) + def select_path?(path) + return false unless match_prefix_pattern(path) + !pending || !::File.exist?(target(path)) + end + + def match_prefix_pattern(path) relative_path(path).start_with?(@prefix) end def fixtures_root Rails.root.to_s