Class: PasswordChanger::Actions::ChangePassword
- Inherits:
-
Object
- Object
- PasswordChanger::Actions::ChangePassword
- Defined in:
- lib/password_changer/actions/change_password.rb
Instance Method Summary collapse
-
#initialize(printers, changer) ⇒ ChangePassword
constructor
A new instance of ChangePassword.
- #run(*data) ⇒ Object
Constructor Details
#initialize(printers, changer) ⇒ ChangePassword
Returns a new instance of ChangePassword.
10 11 12 13 |
# File 'lib/password_changer/actions/change_password.rb', line 10 def initialize(printers, changer) @changer = changer @printers = printers end |
Instance Method Details
#run(*data) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/password_changer/actions/change_password.rb', line 15 def run(*data) users = data.flatten.map do |d| raise ArgumentError, 'Attribute "user_name" or "old_password" is missing!' if d[:name].blank? || d[:old_password].blank? new_password = PasswordChanger::PasswordGenerator.new.generate(old_password: d[:old_password]) d[:new_password] = new_password if d[:new_password].blank? User.new(**d) end users.each do |u| PasswordChanger.logger.info "Changing user \"#{u.name}\"." changer.change(u) end printers.each { |p| p.output users } end |