In short, I want to mass assign a PORO with no database with like 100 attr_accessors with the attributes of a Rails object. The point of this is to expose an object over the API that is not an ActiveRecord Object and this API is being used internally right now and is not separated over a service. What can be done?
Assume we have a database-backed
Database::Apple.new.attributes = API::Apple.first.attributes
Something along these lines could do it for you.
class API::Apple < SimpleDelegator # pass a `Database::Apple` instance to initializer def initialize(database_apple) @database_apple = database_apple super end end
A concrete implementation of
Delegator, this class provides the means to delegate all supported method calls to the object passed into the constructor.
So in other words any instance of your
API::Apple PORO will have access to all 100 attributes of the