lib/smart_kv.rb in smart_kv-0.1.3 vs lib/smart_kv.rb in smart_kv-0.1.4

- old
+ new

@@ -1,25 +1,19 @@ require "smart_kv/version" require "smart_kv/register" -require "smart_kv/macro" SmartKvInitializationError = Class.new(StandardError) class SmartKv extend Register - extend Macro attr_reader :object_class def initialize(required_keys = [], optional_keys = [], object_class = nil, kv = {}) prevent_direct_instantiation @object_class = object_class || kv.class @kv = kv.dup - - if @object_class.respond_to?(:members) && @object_class.members != @kv.to_h.keys - raise ArgumentError, "#{ @object_class } struct size differs" - end hash = kv.to_h.dup missing_keys = required_keys - hash.keys unless missing_keys.empty? raise KeyError, "missing required key(s): #{missing_keys.map{|k| "`:#{k}'" }.join(', ')} in #{self.class}"