I have two objects, a UserData object and a User object. At the moment they look like this:
user_data.rb
class UserData < ActiveRecord::Base
self.table = "users"
end
user.rb
class User
attr_accessor :first_name, :last_name, :email, :password
end
What I'm trying to do now is map the UserData object to the User object and the other way around. For the first scenario I have the following code:
module Mappers
module UserMapper
def map user
@user = UserData.new
@user.first_name = user.first_name
@user.last_name = user.last_name
@user.password = user.password
@user.email = user.email
end
end
end
However, the problem is that whenever I add a new column to the users table, I have to add the code in the mapper as well. And when I have tons of objects inside my code that need to be mapped, it's going to be really messy. My question is: Is there a better / dynamic way for doing this? The ideal situation would be when I don't have to touch the Mapper code anymore.