Clean up #not_nil! uses #84

Merged
dergrimm merged 1 commit from clean-up-not-nil into main 2022-03-07 10:04:42 +00:00
4 changed files with 7 additions and 8 deletions

View file

@ -50,7 +50,7 @@ module Backend
if @user if @user
@admin = @user.not_nil!.admin @admin = @user.not_nil!.admin
@role = Schema::UserRole.parse(@user.not_nil!.role).not_nil! @role = Schema::UserRole.parse(@user.not_nil!.role)
@external = @external =
case @role.not_nil! case @role.not_nil!
when .teacher? when .teacher?

View file

@ -42,7 +42,7 @@ module Backend
end end
def initialize(id : Int32) def initialize(id : Int32)
@model = {{ type }}.find(id).not_nil! @model = {{ type }}.find!(id)
end end
{% space_name = type.names.last.underscore.gsub(/_/, " ").capitalize %} {% space_name = type.names.last.underscore.gsub(/_/, " ").capitalize %}
@ -50,7 +50,7 @@ module Backend
@[GraphQL::Field] @[GraphQL::Field]
# {{ space_name }}'s ID # {{ space_name }}'s ID
def id : Int32 def id : Int32
@model.id.not_nil!.to_i32 @model.id.not_nil!.to_i
end end
end end
end end

View file

@ -82,9 +82,9 @@ module Backend
@model.teacher @model.teacher
when .student? when .student?
@model.student @model.student
end.not_nil!.id.not_nil!.to_i end
rescue NilAssertionError .try(&.id)
nil .try(&.to_i)
end end
@[GraphQL::Field] @[GraphQL::Field]

View file

@ -25,8 +25,7 @@ module Mosquito::Serializers::Granite
end end
def deserialize_{{ method_suffix }}(raw : String) : {{ klass.id }} def deserialize_{{ method_suffix }}(raw : String) : {{ klass.id }}
id = raw.to_i {{ klass.id }}.find!(raw.to_i)
{{ klass.id }}.find(id).not_nil!
end end
end end
end end