lib/jsonapionify/api/attribute.rb in jsonapionify-0.11.11 vs lib/jsonapionify/api/attribute.rb in jsonapionify-0.12.0

- old
+ new

@@ -5,10 +5,11 @@ extend JSONAPIonify::Autoload autoload_all include Documentation using UnstrictProc + using JSONAPIonify::DestructuredProc attr_reader :name, :type, :description, :read, :write, :required, :hidden, :block def initialize( name, type, @@ -27,11 +28,11 @@ @name = name.to_sym @type = type&.freeze @description = description&.freeze @example = example&.freeze @read = read&.freeze - @write = write&.freeze + @write = (!block && write)&.freeze @required = required&.freeze @block = block&.freeze @writeable_actions = write @readable_actions = read @hidden = !!hidden && (hidden == true || Array.wrap(hidden)) @@ -84,10 +85,10 @@ def resolve(instance, context, example_id: nil) if context.respond_to?(:_is_example_) && context._is_example_ == true return example(example_id) end block = self.block || proc { |attr, i| i.send attr } - type.dump block.unstrict.call(self.name, instance, context) + type.dump block.unstrict.destructure.call(self.name, instance, context) rescue JSONAPIonify::Types::DumpError => ex error_block = context.resource.class.error_definitions[:attribute_type_error] context.errors.evaluate( name,