Preparing Scalable Models

The word scalable gets thrown around a lot, usually in terms of databases or web back ends, but client-side code can easily become unscalable as well. For instance, if we wanted to add more attributes to our User, we’d have to make changes in three places: our class definition, our controller, and where we instantiate our objects. In a world where engineers move fast, having all this overhead can be a big time sink.

I wouldn’t bring this up if there weren’t a better way. We’re going to use a nice Ruby trick that lets our models become more flexible and readies them for a typical API. In user.rb, change our three attr_acessor lines into this:

 class​ User
  PROPERTIES = [​ ...

Get RubyMotion now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.