Method: Wgit::Database#urls

Defined in:
lib/wgit/database/database.rb

#urls(crawled: nil, limit: 0, skip: 0) {|url| ... } ⇒ Array<Wgit::Url>

Returns Url records from the DB.

All Urls are sorted by date_added ascending, in other words the first url returned is the first one that was inserted into the DB.

Parameters:

  • crawled (Boolean) (defaults to: nil)

    Filter by Url#crawled value. nil returns all.

  • limit (Integer) (defaults to: 0)

    The max number of Url's to return. 0 returns all.

  • skip (Integer) (defaults to: 0)

    Skip n amount of Url's.

Yields:

  • (url)

    Given each Url object (Wgit::Url) returned from the DB.

Returns:

  • (Array<Wgit::Url>)

    The Urls obtained from the DB.



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/wgit/database/database.rb', line 100

def urls(crawled: nil, limit: 0, skip: 0)
  query = crawled.nil? ? {} : { crawled: crawled }
  sort = { date_added: 1 }

  results = retrieve(:urls, query,
                     sort: sort, projection: {},
                     limit: limit, skip: skip)
  return [] if results.count < 1 # results#empty? doesn't exist.

  # results.respond_to? :map! is false so we use map and overwrite the var.
  results = results.map { |url_doc| Wgit::Url.new(url_doc) }
  results.each { |url| yield(url) } if block_given?

  results
end