@@ -109,7 +109,7 @@ def allow_phi!(user_id = nil, reason = nil)
109109 #
110110 def allow_phi ( user_id = nil , reason = nil , allow_only : nil , &block )
111111 get_phi ( user_id , reason , allow_only : allow_only , &block )
112- return
112+ nil
113113 end
114114
115115 # Enable PHI access for any instance of this class in the block given only
@@ -149,7 +149,7 @@ def get_phi(user_id = nil, reason = nil, allow_only: nil)
149149 allow_only . each { |t | t . allow_phi! ( user_id , reason ) }
150150 end
151151
152- return yield
152+ yield
153153 ensure
154154 __instances_with_extended_phi . each do |obj |
155155 if frozen_instances . include? ( obj )
@@ -362,7 +362,7 @@ def allow_phi!(user_id = nil, reason = nil)
362362 #
363363 def allow_phi ( user_id = nil , reason = nil , &block )
364364 get_phi ( user_id , reason , &block )
365- return
365+ nil
366366 end
367367
368368 # Enable PHI access for a single instance of this class inside the block.
@@ -388,7 +388,7 @@ def get_phi(user_id = nil, reason = nil)
388388 begin
389389 allow_phi! ( user_id , reason )
390390
391- return yield
391+ yield
392392 ensure
393393 new_extensions = @__phi_relations_extended - extended_instances
394394 disallow_last_phi! ( preserve_extensions : true )
@@ -487,7 +487,7 @@ def phi_access_reason
487487 # @return [Boolean] whether PHI access is allowed for this instance
488488 #
489489 def phi_allowed?
490- !phi_context . nil? && phi_context [ :phi_access_allowed ]
490+ new_record? || ( !phi_context . nil? && phi_context [ :phi_access_allowed ] )
491491 end
492492
493493 # Require phi access. Raises an error pre-emptively if it has not been granted.
@@ -672,7 +672,7 @@ def phi_wrap_extension(method_name)
672672 self . class . send ( :define_method , wrapped_method ) do |*args , **kwargs , &block |
673673 relation = send ( unwrapped_method , *args , **kwargs , &block )
674674
675- if phi_allowed? && ( relation . present? && relation_klass ( relation ) . included_modules . include? ( PhiRecord ) )
675+ if phi_allowed? && relation . present? && relation_klass ( relation ) . included_modules . include? ( PhiRecord )
676676 relations = relation . is_a? ( Enumerable ) ? relation : [ relation ]
677677 relations . each do |r |
678678 r . allow_phi! ( phi_allowed_by , phi_access_reason ) unless @__phi_relations_extended . include? ( r )
@@ -720,7 +720,7 @@ def relation_klass(rel)
720720 return rel . klass if rel . is_a? ( ActiveRecord ::Relation )
721721 return rel . first . class if rel . is_a? ( Enumerable )
722722
723- return rel . class
723+ rel . class
724724 end
725725
726726 def wrapped_extended_name ( method_name )
0 commit comments