Mailinglist Archive: yast-commit (1771 mails)

< Previous Next >
[yast-commit] <rest-service> network : improved Service model (for easy stubbing in testcases)
  • From: Ladislav Slezak <lslezak@xxxxxxxxxx>
  • Date: Mon, 24 Aug 2009 14:10:09 +0200
  • Message-id: <E1MiTqJ-0006bA-ED@xxxxxxxxxxxxxxxx>
ref: refs/heads/network
commit cc5a31fe03ac8b57692e0ad65de45629545ffaee
Author: Ladislav Slezak <lslezak@xxxxxxxxxx>
Date: Mon Aug 24 14:03:02 2009 +0200

improved Service model (for easy stubbing in testcases)
---
plugins/services/app/models/service.rb | 20 ++++++++++++++++++--
1 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/plugins/services/app/models/service.rb
b/plugins/services/app/models/service.rb
index 1632c6a..d22321c 100644
--- a/plugins/services/app/models/service.rb
+++ b/plugins/services/app/models/service.rb
@@ -10,9 +10,25 @@ class Service
def initialize(name)
@name = name
end
+
+ private
+
+ # factored out because of testing
+ def self.run_runlevel
+ `runlevel`
+ end
+
+ public
+
+ def self.current_runlevel
+ rl = run_runlevel.split(" ").last
+ raise Exception.new('Non-number runlevel') if !/^[0-9]*$/.match rl
+ rl == "S" ? -1 : rl.to_i
+ end

# services = Service.find_all
def self.find_all(params)
+ params = {} if params.nil?

services = []
read_status = params.has_key?("read_status")
@@ -33,9 +49,9 @@ class Service
Rails.logger.error e
end
else
- rl = `runlevel`.split(" ").last
+ rl = current_runlevel
params = {
- "runlevel" => [ "i", rl == "S" ? -1 : rl.to_i ],
+ "runlevel" => [ "i", rl ],
"read_status" => [ "b", read_status]
}

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

< Previous Next >
This Thread
  • No further messages