ref: refs/heads/master
commit 69c36f2b82f6b6bb5585ccef59a873fc06192c3e
Author: Josef Reidinger
Date: Tue Jul 14 12:20:23 2009 +0200
refactor proxy loader from application controller to separated lib
---
.../app/controllers/system_time_controller.rb | 1 +
.../app/controllers/application_controller.rb | 31 ------------
webclient/lib/exception_logger.rb | 18 +++++++
webclient/lib/proxy_loader.rb | 49 ++++++++++++++++++++
4 files changed, 68 insertions(+), 31 deletions(-)
diff --git a/plugins/systemtime/app/controllers/system_time_controller.rb b/plugins/systemtime/app/controllers/system_time_controller.rb
index dbdda44..a2fe83e 100644
--- a/plugins/systemtime/app/controllers/system_time_controller.rb
+++ b/plugins/systemtime/app/controllers/system_time_controller.rb
@@ -4,6 +4,7 @@ require 'systemtime'
class SystemTimeController < ApplicationController
before_filter :login_required
layout 'main'
+ include ProxyLoader
#helpers
private
diff --git a/webclient/app/controllers/application_controller.rb b/webclient/app/controllers/application_controller.rb
index c81d192..b561be1 100644
--- a/webclient/app/controllers/application_controller.rb
+++ b/webclient/app/controllers/application_controller.rb
@@ -68,35 +68,4 @@ class ApplicationController < ActionController::Base
# Uncomment this to filter the contents of submitted sensitive data parameters
# from your application log (in this case, all fields with names like "password").
filter_parameter_logging :password
-
- def load_proxy (name)
- proxy = YaST::ServiceResource.proxy_for(name)
-
- unless proxy
- logger.warn "Couldn't find proxy for #{name}"
- flash[:error] = "Cannot find service on target machine for #{name}."
- @permissions = nil
- return nil
- end
-
- @permissions = proxy.permissions
-
- ret = nil
- begin
- ret = proxy.find
- rescue ActiveResource::ClientError => e
- flash[:error] = YaST::ServiceResource.error(e)
- log_exception e
- rescue Exception => e
- flash[:error] = e.message
- log_exception e
- end
-
- return ret
- end
-
- def log_exception
- logger.warn e.message
- logger.info e.backtrace.join("\n")
- end
end
diff --git a/webclient/lib/exception_logger.rb b/webclient/lib/exception_logger.rb
new file mode 100644
index 0000000..cd318e7
--- /dev/null
+++ b/webclient/lib/exception_logger.rb
@@ -0,0 +1,18 @@
+# = ExceptionLogger module
+# Provides unified way to log exception in controller.
+# == requirements
+# Should be used only in controller. (TODO make it more universal)
+# == Usage
+# Just add log_exception method with Exception as argument and it write informations
+# to log
+#
+# rescue Exception => e
+# log_exception e
+
+
+module ExceptionLogger
+ def log_exception e
+ logger.warn e.message
+ logger.info e.backtrace.join("\n")
+ end
+end
diff --git a/webclient/lib/proxy_loader.rb b/webclient/lib/proxy_loader.rb
new file mode 100644
index 0000000..5449901
--- /dev/null
+++ b/webclient/lib/proxy_loader.rb
@@ -0,0 +1,49 @@
+# = ProxyLoader module
+# Modules handles finding and loading proxy. It take care about pottential problems
+# == requirements
+# Use ExceptionLogger module to it run. Intended to be used in Controller.
+# == Usage
+# Include module in controller and use method load_proxy.
+#
+# include ProxyLoader
+# def index
+# @systemtime = load_proxy 'org.opensuse.yast.modules.yapi.time'
+#
+# unless @systemtime
+# return false
+# end
+# ...
+#
+
+module ProxyLoader
+ include ExceptionLogger
+ #Finds proxy and find its result.
+ #_fields_:: set @+permissions+ field to permissions of proxy
+ #name:: Name of proxy
+ #+returns+:: Returns result of proxy.find or nil if something goes bad
+ def load_proxy (name)
+ proxy = YaST::ServiceResource.proxy_for(name)
+
+ unless proxy
+ logger.warn "Couldn't find proxy for #{name}"
+ flash[:error] = "Cannot find service on target machine for #{name}."
+ @permissions = nil
+ return nil
+ end
+
+ @permissions = proxy.permissions
+
+ ret = nil
+ begin
+ ret = proxy.find
+ rescue ActiveResource::ClientError => e
+ flash[:error] = YaST::ServiceResource.error(e)
+ log_exception e
+ rescue Exception => e
+ flash[:error] = e.message
+ log_exception e
+ end
+
+ return ret
+ end
+end
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org