ref: refs/heads/resource-restful commit b698621ce5ff6074229fc66e71d4e79f78bbdc20 Author: Josef Reidinger <jreidinger@suse.cz> Date: Tue Sep 22 10:29:12 2009 +0200 Change calling conventions for Invalid parameters to follow DRY --- .../app/controllers/language_controller.rb | 2 +- .../app/controllers/network/dns_controller.rb | 2 +- .../app/controllers/network/hostname_controller.rb | 2 +- .../controllers/network/interfaces_controller.rb | 2 +- .../app/controllers/network/routes_controller.rb | 2 +- plugins/ntp/app/controllers/ntp_controller.rb | 2 +- .../time/app/controllers/systemtimes_controller.rb | 2 +- webservice/lib/exceptions.rb | 16 ++++++++-------- 8 files changed, 15 insertions(+), 15 deletions(-) diff --git a/plugins/language/app/controllers/language_controller.rb b/plugins/language/app/controllers/language_controller.rb index a6c6878..cc47f32 100644 --- a/plugins/language/app/controllers/language_controller.rb +++ b/plugins/language/app/controllers/language_controller.rb @@ -23,7 +23,7 @@ class LanguageController < ApplicationController else logger.warn("No argument to update") - raise InvalidParameters.new [{:name => "language", :error => "Missing"}] + raise InvalidParameters.new :language => "Missing" end render :show end diff --git a/plugins/network/app/controllers/network/dns_controller.rb b/plugins/network/app/controllers/network/dns_controller.rb index bcfe961..1b06221 100644 --- a/plugins/network/app/controllers/network/dns_controller.rb +++ b/plugins/network/app/controllers/network/dns_controller.rb @@ -11,7 +11,7 @@ class Network::DnsController < ApplicationController def update root = params[:dns] if root == nil - raise InvalidParameters.new [{:name => "Dns", :error => "Missing"}] + raise InvalidParameters.new :dns => "Missing" end root["searches"]=root["searches"].split diff --git a/plugins/network/app/controllers/network/hostname_controller.rb b/plugins/network/app/controllers/network/hostname_controller.rb index 86c51d3..243d030 100644 --- a/plugins/network/app/controllers/network/hostname_controller.rb +++ b/plugins/network/app/controllers/network/hostname_controller.rb @@ -12,7 +12,7 @@ class Network::HostnameController < ApplicationController def update root = params[:hostname] if root == nil - raise InvalidParameters.new [{:name => "Hostname", :error => "Missing"}] + raise InvalidParameters.new :hostname => "Missing" end @hostname = Hostname.new(root) diff --git a/plugins/network/app/controllers/network/interfaces_controller.rb b/plugins/network/app/controllers/network/interfaces_controller.rb index a377a09..fcad0de 100644 --- a/plugins/network/app/controllers/network/interfaces_controller.rb +++ b/plugins/network/app/controllers/network/interfaces_controller.rb @@ -11,7 +11,7 @@ class Network::InterfacesController < ApplicationController def update root = params[:interfaces] if root == nil - raise InvalidParameters.new [{:name => "Interfaces", :error => "Missing"}] + raise InvalidParameters.new :interfaces => "Missing" end @iface = Interface.new(root) diff --git a/plugins/network/app/controllers/network/routes_controller.rb b/plugins/network/app/controllers/network/routes_controller.rb index 011620a..4f7d1aa 100644 --- a/plugins/network/app/controllers/network/routes_controller.rb +++ b/plugins/network/app/controllers/network/routes_controller.rb @@ -11,7 +11,7 @@ class Network::RoutesController < ApplicationController def update root = params[:routes] if root == nil - raise InvalidParameters.new [{:name => "Routes", :error => "Missing"}] + raise InvalidParameters.new :routes => "Missing" end @route = Route.find(root[:id]) @route.via = root[:via] diff --git a/plugins/ntp/app/controllers/ntp_controller.rb b/plugins/ntp/app/controllers/ntp_controller.rb index 10cdc4a..99c5b8e 100644 --- a/plugins/ntp/app/controllers/ntp_controller.rb +++ b/plugins/ntp/app/controllers/ntp_controller.rb @@ -16,7 +16,7 @@ class NtpController < ApplicationController def update root = params["ntp"] if root == nil || root == {} #FIXME exception for this - raise InvalidParameters [{:name => "ntp",:error => "Missing"}] + raise InvalidParameters :ntp => "Missing" end @ntp = Ntp.find diff --git a/plugins/time/app/controllers/systemtimes_controller.rb b/plugins/time/app/controllers/systemtimes_controller.rb index e669bbd..0637b9c 100644 --- a/plugins/time/app/controllers/systemtimes_controller.rb +++ b/plugins/time/app/controllers/systemtimes_controller.rb @@ -19,7 +19,7 @@ class SystemtimesController < ApplicationController root = params[:time] if root == nil - raise InvalidParameters.new [{:name => "Timezone", :error => "Missing"}] + raise InvalidParameters.new :timezone => "Missing" end systemtime = Systemtime.create_from_xml(root) diff --git a/webservice/lib/exceptions.rb b/webservice/lib/exceptions.rb index 6dca0f4..6af4e32 100644 --- a/webservice/lib/exceptions.rb +++ b/webservice/lib/exceptions.rb @@ -26,16 +26,16 @@ end # initialized by constrains which is broken # If uncatched then response 422 and cause fail of ActiveResouce#save class InvalidParameters < ArgumentError - # Takes as argument constrains. Constrains is array of hash with keys name - # and error. Name is name of parameter and error is broken constrain + # Takes as argument constrains. Constrains is hash where key is parameter + # and value is broken constrain # (it is not translated so should be some symbol, which is then on frontend # readed and reported translated message) # # example:: - # raise InvalidParameters.new [ - # { :name => "id", :error => "MISSING"}, - # { :name => "email", :error => "NO@"} - # ] + # raise InvalidParameters.new { + # :id => "MISSING" + # :email => "NO@" + # } def initialize (constrains) @constrains = constrains super("Invalid arguments: #{@constrains.inspect}") @@ -49,8 +49,8 @@ class InvalidParameters < ArgumentError xml.errors(:type => "array") do @constrains.each { - |c| - xml.error "#{c[:name].humanize} --- #{c[:error]}" + |k,v| + xml.error "#{k.to_s.humanize} --- #{v}" } end end -- To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org For additional commands, e-mail: yast-commit+help@opensuse.org