Skip to content

Commit

Permalink
Add Twitter::Utils#flat_pmap
Browse files Browse the repository at this point in the history
  • Loading branch information
sferik committed Mar 1, 2014
1 parent dfe7b1d commit ee40768
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -31,7 +31,7 @@ end

require 'yardstick/rake/verify'
Yardstick::Rake::Verify.new do |verify|
verify.threshold = 59.6
verify.threshold = 59.5
end

task :default => [:spec, :rubocop, :verify_measurements]
4 changes: 2 additions & 2 deletions lib/twitter/rest/users.rb
Expand Up @@ -227,9 +227,9 @@ def unblock(*args)
def users(*args)
arguments = Twitter::Arguments.new(args)
request_method = arguments.options.delete(:method) || :post
pmap(arguments.each_slice(MAX_USERS_PER_REQUEST)) do |users|
flat_pmap(arguments.each_slice(MAX_USERS_PER_REQUEST)) do |users|
perform_with_objects(request_method, '/1.1/users/lookup.json', merge_users(arguments.options, users), Twitter::User)
end.flatten
end
end

# @see https://dev.twitter.com/docs/api/1.1/get/users/show
Expand Down
11 changes: 11 additions & 0 deletions lib/twitter/utils.rb
Expand Up @@ -15,6 +15,17 @@ def deprecate_alias(new_name, old_name)
end
end

# Returns a new array with the concatenated results of running block once for every element in enumerable.
# If no block is given, an enumerator is returned instead.
#
# @param enumerable [Enumerable]
# @return [Array, Enumerator]
def flat_pmap(enumerable, &block)
return to_enum(:flat_pmap, enumerable) unless block_given?
pmap(enumerable, &block).flatten(1)
end
module_function :flat_pmap

# Returns a new array with the results of running block once for every element in enumerable.
# If no block is given, an enumerator is returned instead.
#
Expand Down
2 changes: 1 addition & 1 deletion spec/helper.rb
Expand Up @@ -8,7 +8,7 @@

SimpleCov.start do
add_filter '/spec/'
minimum_coverage(99.39)
minimum_coverage(99.4)
end

require 'twitter'
Expand Down

0 comments on commit ee40768

Please sign in to comment.