Module: Shopkit::Traversal

Included in:
Client
Defined in:
lib/shopkit/traversal.rb

Instance Method Summary collapse

Instance Method Details

#traversal(options) ⇒ Object

遍历所有页面



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/shopkit/traversal.rb', line 4

def traversal(options) # 遍历所有页面
  options[:page] ||= 1
  options[:per_page] ||= per_page
  options[:per_page] = 100 if auto_traversal
  list = yield(options) || []
  if auto_traversal and !list.empty?
    options[:page] += 1
    list += traversal(options) do
      yield(options)
    end
  end
  list
end