ruby on rails - Store a list of .rb files inside model -


colleagues! have document model. document should processed 1 of parsers (in project called 'importers' , stored inside 'lib/importers' folder). question best way implement entity importer inside models layer? (for instance associate document importer).

  1. first idea create importers table, have 2 independent places importer names saved (database , file system). bad cases:

case 1: i've aded new importer, forgot add importers table = can't associate document impoter

case 2: importer renamed , forgot rename inside database = error

  1. i decided define

    def document.importers @importers ||= dir.entries("#{rails.root}/lib/importers/") .select { |name| !file.directory?(name) && name != 'base_importer.rb'} .map { |name| name.gsub(/\.rb$/, '') } end

for f.association inout , add importer string attribute document model. can importer class in following way -- 'importer.classify.constantize'. works, looks creepy

can advice better solution situation? appreciate hear ideas ;)

i model them in database, , have system in place update database if files change. happens time asset management systems: have physical files, , data, , yes, if go out of sync you've got problems. so, put systems in place try keep them in sync. can have rake task update database based on physical files example, protocol need run rake task after changing files, , if don't screwed , problems fault. developers should able work within these sorts of rules.

ultimately, rails object-relational data, work if want use rails. if try go down route of building load of instances on fly every time, based on contents of folder, end complicated , inefficient system.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -