app/models/aranha/address.rb in aranha-0.3.0 vs app/models/aranha/address.rb in aranha-0.4.0
- old
+ new
@@ -10,17 +10,18 @@
def set_start_point(url, processor)
start_points[url] = processor
end
def add_start_points
+ ::Rails.logger.info("Start points: #{start_points.count}")
start_points.each do |url, processor|
add(url, processor)
end
end
def add(url, processor, extra_data = nil)
- a = find_or_initialize_by(url: url)
+ a = find_or_initialize_by(url: sanitize_url(url))
a.processor = processor
a.extra_data = extra_data.to_yaml
a.save!
end
@@ -30,10 +31,18 @@
q.destroy_all
end
private
+ def sanitize_url(url)
+ if url.is_a?(Hash)
+ url.to_yaml
+ else
+ url.to_s
+ end
+ end
+
def start_points
@start_points ||= {}
end
end
@@ -58,15 +67,19 @@
private
def instanciate_processor
if processor_instancier_arity == 2 || processor_instancier_arity < 0
- processor_instancier.call(url, YAML.load(extra_data))
+ processor_instancier.call(url_to_process, YAML.load(extra_data))
elsif processor_instancier_arity == 1
- processor_instancier.call(url)
+ processor_instancier.call(url_to_process)
else
raise("#{processor}.initialize should has 1 or 2 or * arguments")
end
+ end
+
+ def url_to_process
+ ::YAML.load(url)
end
def processor_instancier
processor.constantize.method(:new)
end