samedi 26 mars 2016

Instance Methods vs. Class methods For a Helper Class - Ruby, Rails

I am working on a rake task which creates new records in local db based on a query submitted to an external db (MS SQL). Connection, querying and record creating happens in a helper I created called ExternalDatabaseConnector. Rake tasks simply calls methods and operates as controller of sort.

My question is whether the helper class methods (I have establish_connection, execute_query, create_hash and store_records) should be called on self (i.e. be class methods) or each be called on an instance of my helper?

I am thinking that there will only be one connection and the rake task will only fire once per its schedule, and there is no need to create separate instances of my helper class?

Aucun commentaire:

Enregistrer un commentaire