Another refactoring done has to do with 2 things:

1) use the stdlib or look around (active_support has quite a lot of stuff 
already)
2) Don't repeat yourself

# FIXME convert ruby's under_scored keys to YaST's camel-cased ones
    data["cn"]                  = [ "s", self.cn ]              unless 
self.cn.blank?
    data["userPassword"]        = [ "s", self.user_password ]   unless 
self.user_password.blank?
    data["homeDirectory"]       = [ "s", self.home_directory ]  unless 
self.home_directory.blank?
    data["loginShell"]          = [ "s", self.login_shell ]     unless 
self.login_shell.blank?
    data["uidNumber"]           = [ "s", self.uid_number ]      unless 
self.uid_number.blank?
    data["groupname"]           = [ "s", self.groupname ]       unless 
self.groupname.blank?


Googling, you can find that activesupport already includes this functionality:
http://refactormycode.com/codes/502-camelize

"hello_world".camelize(:lower)
=> helloWorld

Also consider using ActiveSupport attr_accessor_with_default ;-)

Then, if you see code like the assignment above, you can save lot of typing by 
extracting the code in methods. For example you can create an array with cn, 
userPassword, homeDirectory, etc and iterate it, and then assign to data on 
each iteration. Using camelize to adapt the name on the way. Then even better, 
you can extract that to a method that taking an object (self in this case) 
creates the data structure, (in the refactoring, this was retrieve_data )

Duncan
-- 
To unsubscribe, e-mail: yast-devel+unsubscr...@opensuse.org
For additional commands, e-mail: yast-devel+h...@opensuse.org

Reply via email to