Mailinglist Archive: yast-devel (246 mails)

< Previous Next >
[yast-devel] Re: [yast-commit] <rest-service> master : system - do reboot/shutdown only in 'production' mode
  • From: Klaus Kaempf <kkaempf@xxxxxxx>
  • Date: Thu, 13 Aug 2009 21:31:29 +0200
  • Message-id: <20090813193129.GA28501@xxxxxxxxxxxxx>
Some remarks inline

* Ladislav Slezak <lslezak@xxxxxxxxxx> [Aug 13. 2009 19:04]:
--- a/plugins/system/app/models/system.rb
+++ b/plugins/system/app/models/system.rb
@@ -46,11 +46,21 @@ class System
case action

when :reboot
- Rails.logger.debug 'Rebooting the computer...'
- return computer.Reboot == 0
+ if ENV['RAILS_ENV'] == 'production'
+ Rails.logger.debug 'Rebooting the computer...'
+ return computer.Reboot == 0

'Reboot' seems to be a function. However according to Ruby naming
conventions 'Reboot' is a class (first letter upper case).


+ else
+ Rails.logger.debug "Skipping reboot in
#{ENV['RAILS_ENV']} mode"
+ return true
+ end

The result of the "when :reboot" case is of boolean type. Let the
'reboot' function also return a boolean and drop the comparison with 0

when :shutdown
- Rails.logger.debug 'Shutting down the computer...'
- return computer.Shutdown == 0
+ if ENV['RAILS_ENV'] == 'production'
+ Rails.logger.debug 'Shutting down the computer...'
+ return computer.Shutdown == 0
+ else
+ Rails.logger.debug "Skipping shutdown in
#{ENV['RAILS_ENV']} mode"
+ return true
+ end

The duplication of the production check is not DRY (don't repeat
yourself). Also think about moving the check into the 'reboot' resp.
'shutdown' functions, because this is "where the action is".


Klaus

---
SUSE LINUX Products GmbH, GF: Markus Rex, HRB 16746 (AG N├╝rnberg)

--
To unsubscribe, e-mail: yast-devel+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-devel+help@xxxxxxxxxxxx

< Previous Next >