From a15ba3c376a976f358b3dc231d07074e8d81148e Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Wed, 21 Dec 2022 20:40:27 -0800 Subject: [PATCH] Correct ConflictBlueprint ConflictBlueprint uses `options` to display arbitrary values, but I think those are only available behind conditional statements. This adds those statements and checks if the key that will be used exists on the hash. ConflictBlueprint was also inheriting from ApiBlueprint which requires a real object (with an ID), so instead we inherit from Blueprinter::Base --- app/blueprints/api/v1/conflict_blueprint.rb | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/app/blueprints/api/v1/conflict_blueprint.rb b/app/blueprints/api/v1/conflict_blueprint.rb index d35a1c2..eccfab1 100644 --- a/app/blueprints/api/v1/conflict_blueprint.rb +++ b/app/blueprints/api/v1/conflict_blueprint.rb @@ -2,28 +2,28 @@ module Api module V1 - class ConflictBlueprint < ApiBlueprint - field :position do + class ConflictBlueprint < Blueprinter::Base + field :position, if: ->(_fn, _obj, options) { options.key?(:incoming_position) } do |_, options| options[:incoming_position] end view :characters do - field :conflicts do - GridCharacterBlueprint.render_as_hash(options[:conflict_characters]) + field :conflicts, if: ->(_fn, _obj, options) { options.key?(:conflict_characters) } do |_, options| + GridCharacterBlueprint.render_as_hash(options[:conflict_characters], view: :nested) end - field :incoming do - GridCharacterBlueprint.render_as_hash(options[:incoming_character]) + field :incoming, if: ->(_fn, _obj, options) { options.key?(:incoming_character) } do |_, options| + CharacterBlueprint.render_as_hash(options[:incoming_character]) end end view :weapons do - field :conflicts do - GridWeaponBlueprint.render_as_hash(options[:conflict_weapons]) + field :conflicts, if: ->(_fn, _obj, options) { options.key?(:conflict_weapons) } do |_, options| + GridWeaponBlueprint.render_as_hash(options[:conflict_weapons], view: :nested) end - field :incoming do - GridWeaponBlueprint.render_as_hash(options[:incoming_weapon]) + field :incoming, if: ->(_fn, _obj, options) { options.key?(:incoming_weapon) } do |_, options| + WeaponBlueprint.render_as_hash(options[:incoming_weapon]) end end end