ref: refs/heads/master
commit 7b3b317fcfc98252149afbd1e08a622216d90a79
Author: Josef Reidinger
Date: Tue Aug 4 17:55:26 2009 +0200
Use static methods where it is useful
---
.../time/app/controllers/systemtimes_controller.rb | 3 +-
plugins/time/app/models/systemtime.rb | 38 ++++++++++---------
plugins/time/test/unit/systemtime_test.rb | 4 +-
3 files changed, 23 insertions(+), 22 deletions(-)
diff --git a/plugins/time/app/controllers/systemtimes_controller.rb b/plugins/time/app/controllers/systemtimes_controller.rb
index 62204eb..6bd4d1b 100644
--- a/plugins/time/app/controllers/systemtimes_controller.rb
+++ b/plugins/time/app/controllers/systemtimes_controller.rb
@@ -43,8 +43,7 @@ class SystemtimesController < ApplicationController
render ErrorResult.error( 403, 1, "no permission" ) and return
end
- @systemtime = Systemtime.new
- @systemtime.find
+ @systemtime = Systemtime.find
end
diff --git a/plugins/time/app/models/systemtime.rb b/plugins/time/app/models/systemtime.rb
index e21c694..b402f30 100644
--- a/plugins/time/app/models/systemtime.rb
+++ b/plugins/time/app/models/systemtime.rb
@@ -17,6 +17,21 @@ class Systemtime
private
+ # Creates argument for dbus call which specify what data is requested.
+ # Available timezones is cached so request it only if it is necessary.
+ # return:: hash with requested keys
+ def Systemtime.create_read_question #:doc:
+ ret = {
+ "timezone" => "true",
+ "utcstatus" => "true",
+ "currenttime" => "true"
+ }
+ ret["zones"]= @@timezones.empty? ? "true" : "false"
+ return ret
+ end
+
+ public
+
# Parses response from dbus YaPI call
# response:: response from dbus
def parse_response(response) #:doc:
@@ -32,23 +47,8 @@ class Systemtime
end
end
- # Creates argument for dbus call which specify what data is requested.
- # Available timezones is cached so request it only if it is necessary.
- # return:: hash with requested keys
- def create_read_question #:doc:
- ret = {
- "timezone" => "true",
- "utcstatus" => "true",
- "currenttime" => "true"
- }
- ret["zones"]= @@timezones.empty? ? "true" : "false"
- return ret
- end
-
- public
-
#Getter for static timezones
- def timezones
+ def Systemtime.timezones
return @@timezones
end
@@ -58,8 +58,10 @@ class Systemtime
# fills time instance with data from YaPI.
#
# +warn+: Doesn't take any parameters.
- def find
- parse_response YastService.Call("YaPI::TIME::Read",create_read_question)
+ def Systemtime.find
+ ret = Systemtime.new()
+ ret.parse_response YastService.Call("YaPI::TIME::Read",create_read_question)
+ return ret
end
# Saves data from model to system via YaPI. Saves only setted data,
diff --git a/plugins/time/test/unit/systemtime_test.rb b/plugins/time/test/unit/systemtime_test.rb
index f0fd501..5dac14c 100644
--- a/plugins/time/test/unit/systemtime_test.rb
+++ b/plugins/time/test/unit/systemtime_test.rb
@@ -56,12 +56,12 @@ class LanguageTest < ActiveSupport::TestCase
result = read_response
YastService.stubs(:Call).with("YaPI::TIME::Read",read_arguments).returns(result)
- @model.find
+ @model = Systemtime.find
assert_equal("02/07/2009", @model.date)
assert_equal("12:18:00", @model.time)
assert_equal("Europe/Prague", @model.timezone)
assert_equal("true", @model.utcstatus)
- assert_equal(Test_timezones,@model.timezones)
+ assert_equal(Test_timezones,Systemtime.timezones)
end
def test_setter
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org