lib/io_streams/builder.rb in iostreams-1.2.1 vs lib/io_streams/builder.rb in iostreams-1.3.0
- old
+ new
@@ -18,11 +18,11 @@
raise(ArgumentError, "Invalid stream: #{stream.inspect}") unless IOStreams.extensions.include?(stream)
raise(ArgumentError, "Cannot call both #option and #stream on the same streams instance}") if @streams
raise(ArgumentError, "Cannot call #option unless the `file_name` was already set}") unless file_name
@options ||= {}
- if opts = @options[stream]
+ if (opts = @options[stream])
opts.merge!(options)
else
@options[stream] = options.dup
end
self
@@ -38,11 +38,11 @@
return self
end
raise(ArgumentError, "Invalid stream: #{stream.inspect}") unless IOStreams.extensions.include?(stream)
@streams ||= {}
- if opts = @streams[stream]
+ if (opts = @streams[stream])
opts.merge!(options)
else
@streams[stream] = options.dup
end
self
@@ -89,19 +89,20 @@
end
private
def class_for_stream(type, stream)
- ext = IOStreams.extensions[stream.nil? ? nil : stream.to_sym] || raise(ArgumentError, "Unknown Stream type: #{stream.inspect}")
+ ext = IOStreams.extensions[stream.nil? ? nil : stream.to_sym] ||
+ raise(ArgumentError, "Unknown Stream type: #{stream.inspect}")
ext.send("#{type}_class") || raise(ArgumentError, "No #{type} registered for Stream type: #{stream.inspect}")
end
# Returns the streams for the supplied file_name
def parse_extensions
parts = ::File.basename(file_name).split(".")
extensions = []
- while extension = parts.pop
+ while (extension = parts.pop)
sym = extension.downcase.to_sym
break unless IOStreams.extensions[sym]
extensions.unshift(sym)
end
@@ -114,13 +115,15 @@
if pipeline.empty?
block.call(io_stream)
elsif pipeline.size == 1
stream, opts = pipeline.first
- class_for_stream(type, stream).open(io_stream, opts, &block)
+ class_for_stream(type, stream).open(io_stream, **opts, &block)
else
# Daisy chain multiple streams together
- last = pipeline.keys.inject(block) { |inner, stream_sym| ->(io) { class_for_stream(type, stream_sym).open(io, pipeline[stream_sym], &inner) } }
+ last = pipeline.keys.inject(block) do |inner, stream_sym|
+ ->(io) { class_for_stream(type, stream_sym).open(io, **pipeline[stream_sym], &inner) }
+ end
last.call(io_stream)
end
end
end
end