Mailinglist Archive: yast-devel (246 mails)

< Previous Next >
[yast-devel] users controller refactoring, part II
  • From: "Duncan Mac-Vicar Prett" <dmacvicar@xxxxxxx>
  • Date: Wed, 5 Aug 2009 18:27:17 +0200
  • Message-id: <200908051827.17662.dmacvicar@xxxxxxx>
Another refactoring done has to do with 2 things:

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

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

Googling, you can find that activesupport already includes this functionality:

=> 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 )

To unsubscribe, e-mail: yast-devel+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: yast-devel+help@xxxxxxxxxxxx

< Previous Next >