On Wed, Oct 14, 2009 at 07:19:38PM +0200, J.Daniel Schmidt wrote:
ref: refs/heads/master commit 9e8e1a7d81cbdd2970a6264e456aed01331cb79d Author: J. Daniel Schmidt
Date: Wed Oct 14 19:19:38 2009 +0200 add json support, small fixes in controllers, cleanup
You can use "git add -i" to easily split unrelated changes to separate commits: http://book.git-scm.com/4_interactive_adding.html
--- .../app/controllers/configuration_controller.rb | 42 ++++++++++++++--- .../app/controllers/registration_controller.rb | 15 +++--- plugins/registration/app/models/registration.rb | 46 ++++++++++++++----- .../app/views/configuration/show.json.erb | 2 +- 4 files changed, 77 insertions(+), 28 deletions(-)
diff --git a/plugins/registration/app/controllers/registration_controller.rb b/plugins/registration/app/controllers/registration_controller.rb index bb80661..7ce1c05 100644 --- a/plugins/registration/app/controllers/registration_controller.rb +++ b/plugins/registration/app/controllers/registration_controller.rb @@ -9,20 +9,21 @@ class RegistrationController < ApplicationController # POST to registration => run registration @registration = Registration.new({})
- # TODO: parse post data and set context data + # TODO overwrite context data if defined #@registration.set_context( { } ) + + # TODO: parse post data and set the arguments + # @registration.set_arguments( { } ) + ret = @registration.register + headers["Status"] = "400 Bad Request" if ret == 3
Is the intent to report to the upper layers (UI) that the lower layer (YaPI) encountered invalid data? Then you are supposed to raise InvalidParameters.new :some_item => "Missing" http://lists.opensuse.org/yast-devel/2009-09/msg00117.html
--- a/plugins/registration/app/models/registration.rb +++ b/plugins/registration/app/models/registration.rb @@ -27,8 +29,8 @@ class Registration return if hash.nil?
# merge custom context data - if hash.class.to_s == 'Hash' - @context.merge hash + if hash.class == Hash + hash.each {|k, v| @context.merge!( { k => ['s', "#{v.to_s}"] } ) }
In '"#{v.to_s}"' you are doing the string conversion twice needlessly. Once is enough: $ irb irb(main):001:0> a = :A => :A irb(main):002:0> "#{a.to_s}" => "A" irb(main):003:0> "#{a}" => "A" irb(main):004:0> a.to_s => "A" Also, what is the point of merging a single keyed hash? @context[k] = ['s', v.to_s] seems enough. I see, it is influenced by the old deleted code. But then I'd recommend keeping '@context.merge! hash' (with "!") and doing the variant conversion in a separate step, because it will be unnecessary, eventually: https://bugzilla.novell.com/show_bug.cgi?id=538050
else raise "Invalid or missing registration initialization context data." end @@ -44,19 +46,26 @@ class Registration self.initialize hash end
- def set_arguments(hash) - @arguments = hash + def add_argument(key, value) + @arguments.merge!( { key => [ 'a{ss}',{ 'value' => "#{value.to_s}" } ] } ) end
def add_arguments(hash) - @arguments.merge hash + hash.each {|k, v| self.add_argument k, v } + end + + def set_arguments(hash) + @arguments = {} + self.add_arguments hash end
-- Martin Vidner, YaST developer http://en.opensuse.org/User:Mvidner Kuracke oddeleni v restauraci je jako fekalni oddeleni v bazenu -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org For additional commands, e-mail: yast-devel+help@opensuse.org