Ruby on Rails – Organizing MVC App with Virtual Model Using External API

mvcruby-on-rails

I am creating a rails app with following constraints

  • It has no database
  • It uses a web API to store and retrieve the data
  • The connection to the web API is via a custom gem.
  • The Gem has a basic functionality to make a web API call based on the parameters given.
  • I have 2-3 different kinds of object that I can think of ( or may be more precisely virtual model )

How should the structure of my program be ?

  • Should I incorporate all the method calls within the gem ?
  • Should I create models and put the api related calls in there (then through the gem's basic method)
  • Should I just ignore the model and put everything in the controller . ?

The second method seems most appropriate , but then all the methods from model would be static and I would be calling all methods in essence without any objects.

Best Answer

My gut tells me that you're correct to want to put some code into the Model. The fact of the matter is that while those are the functional/nonfunctional requirements on your application today - that could change. You could be required to implement a database on the next iteration of this project, or even worse the entire way you're storing data could get overhauled.

The fact of the matter is stuff changes. The better you modularize and abstract your code, the quicker you'll be able to adapt to change down the road. You'll also set yourself up for easier unit and integration testing, too. That's an important factor, because detecting problems before they become problems saves time and reputation.

Related Topic