ref: refs/heads/jr-yastmodel
commit d7a3c651c0435263913a70a8e9a33986a13265b5
Author: Josef Reidinger
Date: Mon Dec 21 13:53:32 2009 +0100
fix problem with settings variable in ancestor by using module instead of ancestor
---
webclient/lib/yast_model/base.rb | 32 +++++++++-----------------------
webclient/test/unit/yast_model_test.rb | 6 ++++--
2 files changed, 13 insertions(+), 25 deletions(-)
diff --git a/webclient/lib/yast_model/base.rb b/webclient/lib/yast_model/base.rb
index 1df29b3..c4db5c7 100644
--- a/webclient/lib/yast_model/base.rb
+++ b/webclient/lib/yast_model/base.rb
@@ -1,44 +1,31 @@
module YastModel
- class Base < ActiveResource::Base
- self.logger = Rails.logger #avoid problem with nil logger
+ module Base
- class << self
def model_interface(i)
- @@interface = i.to_sym
+ @interface = i.to_sym
end
- alias_method :site_orig, :site
def site
- ret = site_orig
+ ret = super
if ret.nil? || ret != URI.parse(YaST::ServiceResource::Session.site) ||
password != YaST::ServiceResource::Session.auth_token
set_site
end
- return site_orig
+ return super
end
def set_site
- site = YaST::ServiceResource::Session.site
- self.site = site
+ self.site = YaST::ServiceResource::Session.site
self.password = YaST::ServiceResource::Session.auth_token
YastModel::Resource.site = "#{site}/" #resource has constant prefix to allow introspect
#FIXME not thread save
- Rails.logger.debug "read interface to #{@@interface.to_s}"
- resource = YastModel::Resource.find(:all).find { |r| r.interface.to_sym == @@interface.to_sym }
+ Rails.logger.debug "read interface to #{@interface.to_s}"
+ resource = YastModel::Resource.find(:all).find { |r| r.interface.to_sym == @interface.to_sym }
#TODO throw exception if not find
- p, sep, @@collection_name = resource.href.rpartition('/')
+ p, sep, self.collection_name = resource.href.rpartition('/')
p += '/'
self.prefix = p
- @@element_name = @@collection_name
- end
-
-#redefine collection name as it is little broken see http://lists.opensuse.org/opensuse-ruby/2009-12/msg00008.html
- def collection_name
- @@collection_name
- end
-
- def element_name
- @@element_name
+ self.element_name = collection_name
end
#fix ARs broken singleton
@@ -54,7 +41,6 @@ module YastModel
path = self.collection_path(prefix_options, query_options)
instantiate_record( (connection.get(path, headers)), prefix_options )
end
- end
end
end
end
diff --git a/webclient/test/unit/yast_model_test.rb b/webclient/test/unit/yast_model_test.rb
index 0ec995b..d1976e8 100644
--- a/webclient/test/unit/yast_model_test.rb
+++ b/webclient/test/unit/yast_model_test.rb
@@ -58,10 +58,12 @@ def setup
YaST::ServiceResource::Session.auth_token = "1234"
end
-class TestModel < YastModel::Base
+class TestModel < ActiveResource::Base
+ extend YastModel::Base
model_interface :'org.opensuse.yast.modules.test'
end
-class Test2Model < YastModel::Base
+class Test2Model < ActiveResource::Base
+ extend YastModel::Base
model_interface :'org.opensuse.yast.modules.test2'
end
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org