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
This commit is contained in:
Justin Edmund 2022-12-21 20:40:27 -08:00
parent 747ffbc4ff
commit a15ba3c376

View file

@ -2,28 +2,28 @@
module Api module Api
module V1 module V1
class ConflictBlueprint < ApiBlueprint class ConflictBlueprint < Blueprinter::Base
field :position do field :position, if: ->(_fn, _obj, options) { options.key?(:incoming_position) } do |_, options|
options[:incoming_position] options[:incoming_position]
end end
view :characters do view :characters do
field :conflicts do field :conflicts, if: ->(_fn, _obj, options) { options.key?(:conflict_characters) } do |_, options|
GridCharacterBlueprint.render_as_hash(options[:conflict_characters]) GridCharacterBlueprint.render_as_hash(options[:conflict_characters], view: :nested)
end end
field :incoming do field :incoming, if: ->(_fn, _obj, options) { options.key?(:incoming_character) } do |_, options|
GridCharacterBlueprint.render_as_hash(options[:incoming_character]) CharacterBlueprint.render_as_hash(options[:incoming_character])
end end
end end
view :weapons do view :weapons do
field :conflicts do field :conflicts, if: ->(_fn, _obj, options) { options.key?(:conflict_weapons) } do |_, options|
GridWeaponBlueprint.render_as_hash(options[:conflict_weapons]) GridWeaponBlueprint.render_as_hash(options[:conflict_weapons], view: :nested)
end end
field :incoming do field :incoming, if: ->(_fn, _obj, options) { options.key?(:incoming_weapon) } do |_, options|
GridWeaponBlueprint.render_as_hash(options[:incoming_weapon]) WeaponBlueprint.render_as_hash(options[:incoming_weapon])
end end
end end
end end