Skip to content

Commit 7fbf7e5

Browse files
thechrisnixonbeauby
authored andcommitted
Use condition_type in case statement for included?.
1 parent 40ed7b5 commit 7fbf7e5

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

lib/active_model/serializer/field.rb

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def value(serializer)
2525
# @api private
2626
#
2727
def included?(serializer)
28-
case condition
28+
case condition_type
2929
when :if
3030
serializer.public_send(condition)
3131
when :unless
@@ -38,13 +38,14 @@ def included?(serializer)
3838
private
3939

4040
def condition_type
41-
if options.key?(:if)
42-
:if
43-
elsif options.key?(:unless)
44-
:unless
45-
else
46-
:none
47-
end
41+
@condition_type ||=
42+
if options.key?(:if)
43+
:if
44+
elsif options.key?(:unless)
45+
:unless
46+
else
47+
:none
48+
end
4849
end
4950

5051
def condition

0 commit comments

Comments
 (0)