ref: refs/heads/use-activeresource
commit abf73a93f613e091c9b16e9a6eadbd033aeedaea
Author: Martin Kudlvasr
Date: Wed Sep 16 13:34:53 2009 +0200
adding lookup of resources
---
plugins/network/app/models/yast_resource.rb | 21 +++++++++++++++++++++
1 files changed, 21 insertions(+), 0 deletions(-)
diff --git a/plugins/network/app/models/yast_resource.rb b/plugins/network/app/models/yast_resource.rb
index ce44882..be45496 100644
--- a/plugins/network/app/models/yast_resource.rb
+++ b/plugins/network/app/models/yast_resource.rb
@@ -1,6 +1,17 @@
# Replacement for YaST::ServiceResource
# FIXME capitalize properly "YaSTResource"
+require 'interface_resource'
+
+class String
+ def rsplit(*args)
+ splited = self.reverse.split(*args)
+ splited.reverse!
+ splited.collect {|s| s.reverse }
+ end
+end
+
class YastResource < ActiveResource::Base
+
def self.is_singular_resource
self.collection_name = self.collection_name.singularize
end
@@ -13,6 +24,16 @@ class YastResource < ActiveResource::Base
@polkit_prefix = polkit_prefix
end
+ def self.use_interface(interface)
+ @interface = interface.tr('.','-')
+ end
+
+ def self.find_interface
+ resource = InterfaceResource.find(@interface.tr('.','-'))
+ if resource.implementations.empty? raise "Cannot find resource for interface #{@interface}"
+ self.prefix, self.collection_name = resource.implementations.first.rsplit("/",2)
+ end
+
# TODO push this upstream: "else" added
# Find a single resource from a one-off URL
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org