diff options
| author | Ryan Winograd <[email protected]> | 2020-08-29 09:42:47 -0500 |
|---|---|---|
| committer | Ryan Winograd <[email protected]> | 2020-08-29 09:42:47 -0500 |
| commit | 216996bd076f4f3549155774dbccab4b3c634cd0 (patch) | |
| tree | 460bed7aab51d69c88b8d6487c259bb92d6997aa | |
| parent | c2ac23536dd73ae631f65a45145be170a1186e70 (diff) | |
| download | caxlsx-216996bd076f4f3549155774dbccab4b3c634cd0.tar.gz caxlsx-216996bd076f4f3549155774dbccab4b3c634cd0.zip | |
Update #serialize to accept 3 arguments
| -rw-r--r-- | lib/axlsx/package.rb | 13 | ||||
| -rw-r--r-- | test/tc_package.rb | 12 |
2 files changed, 21 insertions, 4 deletions
diff --git a/lib/axlsx/package.rb b/lib/axlsx/package.rb index 6b55091b..d9865a48 100644 --- a/lib/axlsx/package.rb +++ b/lib/axlsx/package.rb @@ -100,8 +100,8 @@ module Axlsx # # Serialize to a stream # s = p.to_stream() # File.open('example_streamed.xlsx', 'w') { |f| f.write(s.read) } - def serialize(output, options = {}) - confirm_valid, zip_command = parse_serialize_options(options) + def serialize(output, options = {}, secondary_options = nil) + confirm_valid, zip_command = parse_serialize_options(options, secondary_options) return false unless !confirm_valid || self.validate.empty? zip_provider = if zip_command ZipCommand.new(zip_command) @@ -366,8 +366,13 @@ module Axlsx # @return [Boolean, (String or nil)] Returns an array where the first value is # `confirm_valid` and the second is the `zip_command`. # @private - def parse_serialize_options(options) + def parse_serialize_options(options, secondary_options) + if secondary_options + warn "[DEPRECATION] Axlsx::Package#serialize with 3 arguments is deprecated. " + + "Use keyword args instead e.g., package.serialize(output, confirm_valid: false, zip_command: 'zip')" + end if options.is_a?(Hash) + options.merge!(secondary_options || {}) invalid_keys = options.keys - [:confirm_valid, :zip_command] if invalid_keys.any? raise ArgumentError.new("Invalid keyword arguments: #{invalid_keys}") @@ -376,7 +381,7 @@ module Axlsx else warn "[DEPRECATION] Axlsx::Package#serialize with confirm_valid as a boolean is deprecated. " + "Use keyword args instead e.g., package.serialize(output, confirm_valid: false)" - [options, nil] + parse_serialize_options((secondary_options || {}).merge(confirm_valid: options), nil) end end end diff --git a/test/tc_package.rb b/test/tc_package.rb index fc48a9eb..b151d06f 100644 --- a/test/tc_package.rb +++ b/test/tc_package.rb @@ -180,6 +180,18 @@ class TestPackage < Test::Unit::TestCase end assert_equal 1, warnings.size assert_includes warnings.first, "confirm_valid as a boolean is deprecated" + File.delete(@fname) + end + + def test_serialization_with_deprecated_three_arguments + warnings = capture_warnings do + @package.serialize(@fname, true, zip_command: "zip") + end + assert_zip_file_matches_package(@fname, @package) + assert_created_with_zip_command(@fname, @package) + assert_equal 2, warnings.size + assert_includes warnings.first, "with 3 arguments is deprecated" + File.delete(@fname) end def capture_warnings(&block) |
