Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicitly pass block to Proc.new #445

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/fog/azurerm/requests/storage/get_blob.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class AzureRM
class Real
BLOCK_SIZE = 32 * 1024 * 1024 # 32 MB

def get_blob_with_block_given(container_name, blob_name, options, &_block)
def get_blob_with_block_given(container_name, blob_name, options, &block)
options[:request_id] = SecureRandom.uuid
msg = "get_blob_with_block_given: blob #{blob_name} in the container #{container_name}. options: #{options}"
Fog::Logger.debug msg
Expand All @@ -19,7 +19,7 @@ def get_blob_with_block_given(container_name, blob_name, options, &_block)

content_length = blob.properties[:content_length]
if content_length.zero?
Proc.new.call('', 0, 0)
Proc.new(&block).call('', 0, 0)
return [blob, '']
end

Expand All @@ -30,7 +30,7 @@ def get_blob_with_block_given(container_name, blob_name, options, &_block)
raise ArgumentError.new(':end_range MUST be greater than :start_range') if start_range > end_range

if start_range == end_range
Proc.new.call('', 0, 0)
Proc.new(&block).call('', 0, 0)
return [blob, '']
end

Expand All @@ -55,7 +55,7 @@ def get_blob_with_block_given(container_name, blob_name, options, &_block)
raise_azure_exception(ex, msg)
end

Proc.new.call(content, end_range - buffer_end_range, total_bytes)
Proc.new(&block).call(content, end_range - buffer_end_range, total_bytes)
buffer_start_range += buffer_size
end
# No need to return content when block is given.
Expand Down Expand Up @@ -84,7 +84,7 @@ def get_blob(container_name, blob_name, options = {}, &block)

# This class provides the mock implementation for unit tests.
class Mock
def get_blob(_container_name, _blob_name, _options = {}, &_block)
def get_blob(_container_name, _blob_name, _options = {}, &block)
Fog::Logger.debug 'get_blob successfully.'
unless block_given?
return [
Expand Down Expand Up @@ -122,7 +122,7 @@ def get_blob(_container_name, _blob_name, _options = {}, &_block)
remaining = total_bytes = data.length
while remaining > 0
chunk = data.read([remaining, 2].min)
Proc.new.call(chunk, remaining, total_bytes)
Proc.new(&block).call(chunk, remaining, total_bytes)
remaining -= 2
end

Expand Down