diff --git a/Gemfile.lock b/Gemfile.lock index a2a5433..a0d7ac2 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,24 +1,24 @@ GIT remote: https://github.com/msgpack/msgpack-ruby.git - revision: 04ccbd8e11c894cbf235b497b2dbd93338a647b8 + revision: b69e6d6965ef46890885ddf73f02b820f3185d80 specs: msgpack (1.4.5) PATH remote: . specs: - paquito (0.3.1) + paquito (0.4.0) msgpack GEM remote: https://rubygems.org/ specs: - activemodel (7.0.1) - activesupport (= 7.0.1) - activerecord (7.0.1) - activemodel (= 7.0.1) - activesupport (= 7.0.1) - activesupport (7.0.1) + activemodel (7.0.2.3) + activesupport (= 7.0.2.3) + activerecord (7.0.2.3) + activemodel (= 7.0.2.3) + activesupport (= 7.0.2.3) + activesupport (7.0.2.3) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 1.6, < 2) minitest (>= 5.1) @@ -27,31 +27,31 @@ GEM benchmark-ips (2.10.0) byebug (11.1.3) concurrent-ruby (1.1.9) - i18n (1.9.1) + i18n (1.10.0) concurrent-ruby (~> 1.0) - minitest (5.14.4) + minitest (5.15.0) parallel (1.21.0) - parser (3.0.2.0) + parser (3.1.1.0) ast (~> 2.4.1) - rainbow (3.0.0) + rainbow (3.1.1) rake (13.0.6) - regexp_parser (2.1.1) + regexp_parser (2.2.1) rexml (3.2.5) - rubocop (1.22.1) + rubocop (1.25.1) parallel (~> 1.10) - parser (>= 3.0.0.0) + parser (>= 3.1.0.0) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml - rubocop-ast (>= 1.12.0, < 2.0) + rubocop-ast (>= 1.15.1, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.12.0) - parser (>= 3.0.1.1) - rubocop-shopify (2.3.0) - rubocop (~> 1.22) + rubocop-ast (1.16.0) + parser (>= 3.1.1.0) + rubocop-shopify (2.5.0) + rubocop (~> 1.25) ruby-progressbar (1.11.0) - sorbet-runtime (0.5.9209) + sorbet-runtime (0.5.9742) sqlite3 (1.4.2) tzinfo (2.0.4) concurrent-ruby (~> 1.0) diff --git a/lib/paquito/allow_nil.rb b/lib/paquito/allow_nil.rb index 74237ff..a0aaafa 100644 --- a/lib/paquito/allow_nil.rb +++ b/lib/paquito/allow_nil.rb @@ -8,11 +8,13 @@ def initialize(coder) def dump(object) return nil if object.nil? + @coder.dump(object) end def load(payload) return nil if payload.nil? + @coder.load(payload) end end diff --git a/lib/paquito/safe_yaml.rb b/lib/paquito/safe_yaml.rb index 148ccbc..decd0a4 100644 --- a/lib/paquito/safe_yaml.rb +++ b/lib/paquito/safe_yaml.rb @@ -68,6 +68,7 @@ def initialize(...) def dump_coder(target) return unless permitted_class?(target.class) + super end diff --git a/lib/paquito/typed_struct.rb b/lib/paquito/typed_struct.rb index 6822aac..2ba934e 100644 --- a/lib/paquito/typed_struct.rb +++ b/lib/paquito/typed_struct.rb @@ -41,6 +41,7 @@ def from_pack(packed) if pack_digest != digest raise(VersionMismatchError, "#{self} digests do not match") end + new(**props.keys.zip(values).to_h) end diff --git a/lib/paquito/types.rb b/lib/paquito/types.rb index 83653ff..a8ec4fa 100644 --- a/lib/paquito/types.rb +++ b/lib/paquito/types.rb @@ -37,10 +37,12 @@ def unpacker(klass) def register(klass, packer: nil, unpacker:) if packer raise ArgumentError, "packer for #{klass} already defined" if packers.key?(klass) + packers[klass] = packer end raise ArgumentError, "unpacker for #{klass} already defined" if unpackers.key?(klass) + unpackers[klass] = unpacker self @@ -155,6 +157,7 @@ def unpackers unless value.instance_of?(ActiveSupport::HashWithIndifferentAccess) raise PackError.new("cannot pack HashWithIndifferentClass subclass", value) end + factory.dump(value.to_h) end, unpacker: ->(factory, value) { HashWithIndifferentAccess.new(factory.load(value)) }, @@ -263,6 +266,7 @@ def recursive_callback?(callback) def curry_callback(callback, factory) return callback.to_proc if callback.is_a?(Symbol) return callback if callback.arity == 1 + callback.curry.call(factory) end end diff --git a/lib/paquito/version.rb b/lib/paquito/version.rb index 91601fe..9d8afaa 100644 --- a/lib/paquito/version.rb +++ b/lib/paquito/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Paquito - VERSION = "0.3.1" + VERSION = "0.4.0" end diff --git a/test/test_helper.rb b/test/test_helper.rb index 8718b86..39089a4 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -19,6 +19,7 @@ def test(name, &block) test_name = "test_#{name.gsub(/\s+/, "_")}".to_sym defined = method_defined?(test_name) raise "#{test_name} is already defined in #{self}" if defined + if block_given? define_method(test_name, &block) else