Module: Regurgitator::ListKeys
- Includes:
- Domain
- Defined in:
- lib/regurgitator/list_keys.rb
Overview
:nodoc:
Constant Summary collapse
- LIST_KEYS_MAX =
1000
Instance Method Summary collapse
Methods included from Domain
#domain_init, #get_dmid, #refresh_domain, #refresh_domain_unlocked
Instance Method Details
#list_keys(domain, opts = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/regurgitator/list_keys.rb', line 10 def list_keys(domain, opts = {}) dmid = get_dmid(domain) or return after, limit, prefix = opts[:after], opts[:limit], opts[:prefix] limit ||= LIST_KEYS_MAX Integer === limit or raise ArgumentError, ":limit not an Integer=#{limit.inspect}" limit = LIST_KEYS_MAX if limit > LIST_KEYS_MAX sql = "SELECT fid,dkey,length,devcount,classid " \ "FROM file WHERE dmid = #{dmid}" prefix and sql << " AND dkey LIKE /*! BINARY */ #{@db.literal(prefix+'%'.freeze)}" sql << " AND dkey > #{@db.literal(after)}" if after sql << " ORDER BY dkey LIMIT #{limit}" # we don't enforce collation here, give DBAs some freedom... ds = @db[sql] block_given? ? ds.each { |row| yield(row) } : ds.to_a end |