Mailinglist Archive: yast-commit (2114 mails)

< Previous Next >
[yast-commit] <rest-service> master : remade resource xml again. For :all it works as before,
  • From: Martin Kudlvasr <mkudlvasr@xxxxxxx>
  • Date: Thu, 17 Sep 2009 12:35:58 +0200
  • Message-id: <E1MqjuC-0002uB-Rl@xxxxxxxxxxxxxxxx>
ref: refs/heads/master
commit d40352250ab1c1e8cc58fa71144d308f4d12fd34
Author: Martin Kudlvasr <mkudlvasr@xxxxxxx>
Date: Thu Sep 17 12:35:58 2009 +0200

remade resource xml again. For :all it works as before,
for single interface it returns single resource.
---
webservice/app/controllers/resources_controller.rb | 4 +-
webservice/app/models/resource.rb | 70 +++++++-------------
webservice/app/views/resources/index.html.erb | 4 +-
webservice/app/views/resources/show.html.erb | 4 +-
4 files changed, 31 insertions(+), 51 deletions(-)

diff --git a/webservice/app/controllers/resources_controller.rb
b/webservice/app/controllers/resources_controller.rb
index 8cdf227..f363f00 100644
--- a/webservice/app/controllers/resources_controller.rb
+++ b/webservice/app/controllers/resources_controller.rb
@@ -17,8 +17,10 @@ class ResourcesController < ApplicationController

def show
@resource = Resource.find(params[:id].tr('-','.'))
+ unless @resource then
+ render :file => "#{RAILS_ROOT}/public/404.html", :status => 404 and
return
+ end
@node = "Yast"
-
respond_to do |format|
format.html
format.xml { render :xml => @resource.to_xml }
diff --git a/webservice/app/models/resource.rb
b/webservice/app/models/resource.rb
index ae9f028..2c51a0c 100644
--- a/webservice/app/models/resource.rb
+++ b/webservice/app/models/resource.rb
@@ -6,56 +6,38 @@ class Resource
require 'resource_registration'
attr_accessor :implementations, :interface

- class Implementation
- attr_accessor :controller, :interface
-
- def initialize(interface, impl_hash)
- @interface = interface
- @policy = impl_hash[:policy]
- @singular = impl_hash[:singular]
- @controller= impl_hash[:controller]
- end
-
- def link_to
- "/#{@controller}"
- # url_for :only_path => :true,
- # :controller => @controller,
- # :action => (@singular ? :show : :index)
- end
-
- def action
- @singular ? :show : :index
- end
-
- def to_xml( options = {} )
- xml = options[:builder] ||= Builder::XmlMarkup.new(options)
- xml.instruct! unless options[:skip_instruct]
- xml.implementation do
- xml.interface(@interface)
- xml.policy(@policy)
- xml.singular(@singular, :type => :boolean)
- xml.href(link_to)
- end
- end
+ def initialize (interface, impl_hash)
+ @interface = interface
+ @policy = impl_hash[:policy]
+ @singular = impl_hash[:singular]
+ @controller= impl_hash[:controller]
+ end

- def to_json
- Hash.from_xml(to_xml).to_json
- end
+ def link_to
+ "/#{@controller}"
+ # url_for :only_path => :true,
+ # :controller => @controller,
+ # :action => (@singular ? :show : :index)
end

- def initialize (interface, implementations)
- @interface = interface
- @implementations = (implementations or []).collect {|impl|
Implementation.new(interface, impl)}
+ def action
+ @singular ? :show : :index
end

def self.all
- resources = ResourceRegistration.resources.sort.collect
{|interface,implementations| new(interface,implementations)}
+ resources = []
+ ResourceRegistration.resources.sort.each do |interface,implementations|
+ implementations.each do |impl|
+ resources << new(interface,impl)
+ end
+ end
Resources.new resources
end

def self.find(interface)
- implementations = ResourceRegistration.resources[interface] or []
- new(interface, implementations)
+ implementations = ResourceRegistration.resources[interface]
+ unless implementations then return nil end
+ new(interface, implementations.first)
end

def to_xml( options = {} )
@@ -63,11 +45,9 @@ class Resource
xml.instruct! unless options[:skip_instruct]
xml.resource do
xml.interface(@interface)
- xml.implementations(:type => :array) do
- @implementations.each do |implementation|
- implementation.to_xml(:builder => xml, :skip_instruct => true)
- end
- end
+ xml.policy(@policy)
+ xml.singular(@singular, :type => :boolean)
+ xml.href(link_to)
end
end

diff --git a/webservice/app/views/resources/index.html.erb
b/webservice/app/views/resources/index.html.erb
index 0c4328e..aab2371 100644
--- a/webservice/app/views/resources/index.html.erb
+++ b/webservice/app/views/resources/index.html.erb
@@ -1,4 +1,4 @@
<h1><%= @node -%> resources</h1>
-<% @resources.each do |rsrc| rsrc.implementations.each do |impl| -%>
- <%= link_to impl.interface, :only_path => :true, :controller =>
impl.controller, :action => impl.action -%><br/>
+<% @resources.each do |rsrc| -%>
+ <%= link_to rsrc.interface, :only_path => :true, :controller =>
rsrc.controller, :action => rsrc.action -%><br/>
<% end end -%>
diff --git a/webservice/app/views/resources/show.html.erb
b/webservice/app/views/resources/show.html.erb
index e38c18e..2e24064 100644
--- a/webservice/app/views/resources/show.html.erb
+++ b/webservice/app/views/resources/show.html.erb
@@ -1,4 +1,2 @@
<h1><%= @node -%> resources</h1>
-<% @resource.implementations.each do |impl| -%>
- <%= link_to impl.interface, :only_path => :true, :controller =>
impl.controller, :action => impl.action -%><br/>
-<% end -%>
+ <%= link_to @resource.interface, :only_path => :true, :controller =>
@resource.controller, :action => @resource.action -%><br/>
--
To unsubscribe, e-mail: yast-commit+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-commit+help@xxxxxxxxxxxx

< Previous Next >
This Thread
  • No further messages