hensei-api/app/blueprints/api/v1/conflict_blueprint.rb
Justin Edmund a15ba3c376 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
2022-12-21 20:40:27 -08:00

31 lines
1.1 KiB
Ruby

# frozen_string_literal: true
module Api
module V1
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, if: ->(_fn, _obj, options) { options.key?(:conflict_characters) } do |_, options|
GridCharacterBlueprint.render_as_hash(options[:conflict_characters], view: :nested)
end
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, if: ->(_fn, _obj, options) { options.key?(:conflict_weapons) } do |_, options|
GridWeaponBlueprint.render_as_hash(options[:conflict_weapons], view: :nested)
end
field :incoming, if: ->(_fn, _obj, options) { options.key?(:incoming_weapon) } do |_, options|
WeaponBlueprint.render_as_hash(options[:incoming_weapon])
end
end
end
end
end