ref: refs/heads/use-activeresource
commit f9db173d0ca6b64009d2e4ef12d7ad841f15bf43
Author: Martin Kudlvasr
Date: Wed Sep 16 16:35:33 2009 +0200
add initialize_from_interface - this sets collection name and
prefix and policy according to interface
---
.../network/app/controllers/network_controller.rb | 1 +
plugins/network/app/models/hostname.rb | 4 +---
plugins/network/app/models/yast_resource.rb | 13 +++++++------
3 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/plugins/network/app/controllers/network_controller.rb b/plugins/network/app/controllers/network_controller.rb
index f05fc63..fce13a0 100644
--- a/plugins/network/app/controllers/network_controller.rb
+++ b/plugins/network/app/controllers/network_controller.rb
@@ -54,6 +54,7 @@ class NetworkController < ApplicationController
return false unless ifc
# TODO use rescue_from "AR::Base not found..."
+ Hostname.initialize_from_interface
hn = Hostname.find :one
RAILS_DEFAULT_LOGGER.debug YastPermission.check_for("martin", "org.opensuse.yast.modules.yapi.network").inspect
RAILS_DEFAULT_LOGGER.debug hn.permissions.inspect
diff --git a/plugins/network/app/models/hostname.rb b/plugins/network/app/models/hostname.rb
index 21a32dc..ffa6739 100644
--- a/plugins/network/app/models/hostname.rb
+++ b/plugins/network/app/models/hostname.rb
@@ -1,6 +1,4 @@
class Hostname < YastResource
# TODO maybe unnecessary now that find :one is fixed
- is_singular_resource
- has_prefix "network"
- has_policy "org.opensuse.yast.modules.yapi.network"
+ uses_interface "org.opensuse.yast.modules.yapi.network.hostname"
end
diff --git a/plugins/network/app/models/yast_resource.rb b/plugins/network/app/models/yast_resource.rb
index 1d1c7f6..1b00f9d 100644
--- a/plugins/network/app/models/yast_resource.rb
+++ b/plugins/network/app/models/yast_resource.rb
@@ -22,20 +22,21 @@ class YastResource < ActiveResource::Base
@polkit_prefix = polkit_prefix
end
- def self.use_interface(interface)
- @interface = interface.tr('.','-')
+ def self.uses_interface(interface)
+ @interface = interface
end
def self.initialize_from_interface
- resources = InterfaceResource.find(@interface.tr('.','-'))
- if resources.empty? then raise "Cannot find resource for interface #{@interface}" end
- resource = resources.first
+ begin
+ resource = InterfaceResource.find(@interface.tr('.','-'))
+ rescue ActiveResource::ResourceNotFound => e
+ raise "Cannot find resource for interface #{@interface}"
+ end
self.prefix, self.collection_name = resource.controller.rsplit("/",2)
self.has_policy resource.policy
if resource.singular then self.is_singular_resource end
end
-
# TODO push this upstream: "else" added
# Find a single resource from a one-off URL
def self.find_one(options)
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org