micro_spider 0.1.21 → 0.1.22

Sign up to get free protection for your applications and to get access to all the features.
data/lib/micro_spider.rb CHANGED
@@ -277,14 +277,21 @@ class MicroSpider
277
277
  }
278
278
  end
279
279
 
280
- def spawn
281
- spider = self.clone
282
- spider.instance_variable_set(:@paths, [])
283
- spider.instance_variable_set(:@actions, [])
284
- spider.instance_variable_set(:@visited_paths, Set.new)
285
- spider.instance_variable_set(:@broken_paths, Set.new)
286
- spider.instance_variable_set(:@excretion, { status: 'inprogress', results: [] })
287
- spider.skip_set_entrance = false
280
+ # @example
281
+ # spider = MicroSpider.new
282
+ # kid = spider.spawn
283
+ #
284
+ # or
285
+ #
286
+ # kid = spider.spawn do
287
+ # ...
288
+ # ...
289
+ # end
290
+ def spawn(&block)
291
+ spider = self.class.new
292
+ spider.logger = logger
293
+ spider.timeout = timeout
294
+ spider.learn(&block) if block_given?
288
295
  spider
289
296
  end
290
297
 
@@ -300,6 +307,12 @@ class MicroSpider
300
307
  class << self; self; end
301
308
  end
302
309
 
310
+ # The default page is Capybara.current_session.
311
+ # Share one page may cause difficult issue, so here i separate it.
312
+ def page
313
+ @page ||= Capybara::Session.new(Capybara.mode, Capybara.app)
314
+ end
315
+
303
316
  protected
304
317
  def sleep_or_not
305
318
  if delay && delay > 0
@@ -1,3 +1,3 @@
1
1
  module SpiderCore
2
- VERSION = "0.1.21"
2
+ VERSION = "0.1.22"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: micro_spider
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.21
4
+ version: 0.1.22
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-02-10 00:00:00.000000000 Z
12
+ date: 2014-03-06 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: capybara