Skip to content

Commit a85c65f

Browse files
committed
Extract private methods re: password fields
1 parent 2b1f7e7 commit a85c65f

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

.rubocop_todo.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Lint/SendWithMixinArgument:
2626

2727
# Offense count: 3
2828
Metrics/AbcSize:
29-
Max: 16.28
29+
Max: 16.03
3030

3131
# Offense count: 5
3232
Style/ClassVars:

lib/authlogic/session/base.rb

+20-6
Original file line numberDiff line numberDiff line change
@@ -1617,15 +1617,23 @@ def define_login_field_methods
16171617
self.class.send(:attr_reader, login_field) unless respond_to?(login_field)
16181618
end
16191619

1620+
# @api private
16201621
def define_password_field_methods
16211622
return unless password_field
1622-
self.class.send(:attr_writer, password_field) unless respond_to?("#{password_field}=")
1623-
self.class.send(:define_method, password_field) {} unless respond_to?(password_field)
1623+
define_password_field_writer_method
1624+
define_password_field_reader_methods
1625+
end
16241626

1625-
# The password should not be accessible publicly. This way forms
1626-
# using form_for don't fill the password with the attempted
1627-
# password. To prevent this we just create this method that is
1628-
# private.
1627+
# The password should not be accessible publicly. This way forms using
1628+
# form_for don't fill the password with the attempted password. To prevent
1629+
# this we just create this method that is private.
1630+
#
1631+
# @api private
1632+
def define_password_field_reader_methods
1633+
unless respond_to?(password_field)
1634+
# Deliberate no-op method, see rationale above.
1635+
self.class.send(:define_method, password_field) {}
1636+
end
16291637
self.class.class_eval(
16301638
<<-EOS, __FILE__, __LINE__ + 1
16311639
private
@@ -1636,6 +1644,12 @@ def protected_#{password_field}
16361644
)
16371645
end
16381646

1647+
def define_password_field_writer_method
1648+
unless respond_to?("#{password_field}=")
1649+
self.class.send(:attr_writer, password_field)
1650+
end
1651+
end
1652+
16391653
# Creating an alias method for the "record" method based on the klass
16401654
# name, so that we can do:
16411655
#

0 commit comments

Comments
 (0)