csv_import_magic 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (327) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/Rakefile +36 -0
  4. data/app/assets/javascripts/csv_import_magic/application.js +13 -0
  5. data/app/assets/stylesheets/csv_import_magic/_theme.scss +75 -0
  6. data/app/assets/stylesheets/csv_import_magic/application.scss +1 -0
  7. data/app/controllers/csv_import_magic/base_controller.rb +4 -0
  8. data/app/controllers/csv_import_magic/importers_controller.rb +64 -0
  9. data/app/models/importer.rb +77 -0
  10. data/app/services/csv_import_magic/failure.rb +54 -0
  11. data/app/services/csv_import_magic/importer.rb +53 -0
  12. data/app/views/csv_import_magic/importers/edit.html.erb +43 -0
  13. data/app/views/csv_import_magic/importers/show.html.erb +31 -0
  14. data/app/views/layouts/csv_import_magic.html.erb +31 -0
  15. data/app/workers/csv_import_magic/importer_worker.rb +13 -0
  16. data/config/initializers/initializer.rb +1 -0
  17. data/config/locales/en.yml +71 -0
  18. data/config/routes.rb +3 -0
  19. data/db/migrate/20170111145652_create_companies.rb +15 -0
  20. data/db/migrate/20170111145657_create_importers.rb +15 -0
  21. data/db/migrate/20170112125734_create_user.rb +8 -0
  22. data/lib/csv_import_magic/engine.rb +5 -0
  23. data/lib/csv_import_magic/models.rb +18 -0
  24. data/lib/csv_import_magic/orm/active_record.rb +5 -0
  25. data/lib/csv_import_magic/version.rb +3 -0
  26. data/lib/csv_import_magic.rb +12 -0
  27. data/lib/generators/active_record/csv_import_magic_generator.rb +35 -0
  28. data/lib/generators/active_record/templates/csv_parser.rb +19 -0
  29. data/lib/generators/csv_import_magic/controllers_generator.rb +14 -0
  30. data/lib/generators/csv_import_magic/csv_import_magic_generator.rb +17 -0
  31. data/lib/generators/csv_import_magic/install_generator.rb +58 -0
  32. data/lib/generators/csv_import_magic/orm_helpers.rb +19 -0
  33. data/lib/generators/csv_import_magic/views_generator.rb +65 -0
  34. data/lib/generators/templates/migration.rb +10 -0
  35. data/lib/generators/templates/views/shareds/_csv_importer.html.erb +19 -0
  36. data/spec/controllers/csv_import_magic/importers_controller_spec.rb +106 -0
  37. data/spec/dummy/README.rdoc +28 -0
  38. data/spec/dummy/Rakefile +6 -0
  39. data/spec/dummy/app/assets/javascripts/application.js +13 -0
  40. data/spec/dummy/app/assets/stylesheets/application.css +16 -0
  41. data/spec/dummy/app/controllers/application_controller.rb +7 -0
  42. data/spec/dummy/app/csv_parsers/company_parser.rb +15 -0
  43. data/spec/dummy/app/csv_parsers/foo_parser.rb +9 -0
  44. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  45. data/spec/dummy/app/models/company.rb +5 -0
  46. data/spec/dummy/app/models/user.rb +4 -0
  47. data/spec/dummy/app/views/application/index.html.erb +22 -0
  48. data/spec/dummy/app/views/layouts/application.html.erb +15 -0
  49. data/spec/dummy/bin/bundle +3 -0
  50. data/spec/dummy/bin/rails +4 -0
  51. data/spec/dummy/bin/rake +4 -0
  52. data/spec/dummy/bin/setup +29 -0
  53. data/spec/dummy/config/application.rb +26 -0
  54. data/spec/dummy/config/boot.rb +5 -0
  55. data/spec/dummy/config/database.yml +25 -0
  56. data/spec/dummy/config/environment.rb +5 -0
  57. data/spec/dummy/config/environments/development.rb +41 -0
  58. data/spec/dummy/config/environments/production.rb +79 -0
  59. data/spec/dummy/config/environments/test.rb +42 -0
  60. data/spec/dummy/config/initializers/assets.rb +11 -0
  61. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  62. data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
  63. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  64. data/spec/dummy/config/initializers/inflections.rb +16 -0
  65. data/spec/dummy/config/initializers/mime_types.rb +4 -0
  66. data/spec/dummy/config/initializers/session_store.rb +3 -0
  67. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  68. data/spec/dummy/config/locales/csv_import_magic.pt-BR.yml +71 -0
  69. data/spec/dummy/config/locales/pt-BR.yml +271 -0
  70. data/spec/dummy/config/routes.rb +5 -0
  71. data/spec/dummy/config/secrets.yml +22 -0
  72. data/spec/dummy/config.ru +4 -0
  73. data/spec/dummy/db/development.sqlite3 +0 -0
  74. data/spec/dummy/db/schema.rb +51 -0
  75. data/spec/dummy/db/test.sqlite3 +0 -0
  76. data/spec/dummy/log/development.log +5489 -0
  77. data/spec/dummy/log/test.log +87086 -0
  78. data/spec/dummy/public/404.html +67 -0
  79. data/spec/dummy/public/422.html +67 -0
  80. data/spec/dummy/public/500.html +66 -0
  81. data/spec/dummy/public/favicon.ico +0 -0
  82. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-37276-r4n40q.csv +2 -0
  83. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-38136-8h3q2p.csv +2 -0
  84. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-38466-1nr5kco.csv +2 -0
  85. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-39668-101mi6q.csv +2 -0
  86. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-40284-81g0ud.csv +2 -0
  87. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-40408-17a0uvl.csv +2 -0
  88. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-40523-pj6wl4.csv +2 -0
  89. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-42084-10luep0.csv +2 -0
  90. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-42191-11tldaf.csv +2 -0
  91. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-42321-baundn.csv +2 -0
  92. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-42420-1qm2isf.csv +2 -0
  93. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-42570-gywnhk.csv +2 -0
  94. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-42696-1pg04re.csv +2 -0
  95. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-42823-vekf7j.csv +2 -0
  96. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-42910-ewzmcp.csv +2 -0
  97. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-43235-1fa52ga.csv +2 -0
  98. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-43323-p159hh.csv +2 -0
  99. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-45345-1r8v081.csv +2 -0
  100. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-46182-1dx0tpn.csv +2 -0
  101. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-46278-fd4m8e.csv +2 -0
  102. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-46382-9y135a.csv +2 -0
  103. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-48570-1k4k7t0.csv +2 -0
  104. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-56058-b7otnp.csv +2 -0
  105. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-56173-187smu1.csv +2 -0
  106. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-56280-ax6el0.csv +2 -0
  107. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-56372-pyd0uc.csv +2 -0
  108. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-56475-16dw7ov.csv +2 -0
  109. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-56578-odd4y0.csv +2 -0
  110. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-56672-l11ojb.csv +2 -0
  111. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170117-56794-88h4nd.csv +2 -0
  112. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-10138-13br6m2.csv +2 -0
  113. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-19400-ra06q5.csv +2 -0
  114. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-19543-rfxxty.csv +2 -0
  115. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-19652-1neho6l.csv +2 -0
  116. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-19786-rxjv36.csv +2 -0
  117. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-21648-ssn05e.csv +2 -0
  118. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-23496-ddy2xt.csv +2 -0
  119. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-30892-1c27rs4.csv +2 -0
  120. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-30994-qfqs3h.csv +2 -0
  121. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-32470-1mk1udp.csv +2 -0
  122. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-32716-13g9myq.csv +2 -0
  123. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-32807-12b8cgg.csv +2 -0
  124. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-32901-1vp2axx.csv +2 -0
  125. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-32992-1jwfjfd.csv +2 -0
  126. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-33081-1j1d591.csv +2 -0
  127. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-33180-36l1t8.csv +2 -0
  128. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-33299-13p8l1x.csv +2 -0
  129. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-38626-sigf3m.csv +2 -0
  130. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-38797-1kqkwkw.csv +2 -0
  131. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-39057-1x8b2fn.csv +2 -0
  132. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-39157-1087rtq.csv +2 -0
  133. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-39268-168s29f.csv +2 -0
  134. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-39355-s8x1si.csv +2 -0
  135. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-39483-r08bs.csv +2 -0
  136. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-40181-vdjtbv.csv +2 -0
  137. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-42041-w1imo1.csv +2 -0
  138. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-42229-1e22hz4.csv +2 -0
  139. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-42996-9neptt.csv +2 -0
  140. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-43889-584l0q.csv +2 -0
  141. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-44738-ew2i2a.csv +2 -0
  142. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-7981-1uei1o4.csv +2 -0
  143. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-8075-15sar1.csv +2 -0
  144. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-8167-zc1h0z.csv +2 -0
  145. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-8265-bnndjd.csv +2 -0
  146. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170118-8364-4u0il1.csv +2 -0
  147. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170119-22243-b3wyrt.csv +2 -0
  148. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170119-22711-1uvny32.csv +2 -0
  149. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170119-56031-votbjp.csv +2 -0
  150. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170119-56135-j5mcgr.csv +2 -0
  151. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170119-56240-l2w835.csv +2 -0
  152. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170119-57815-i1ahvu.csv +2 -0
  153. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170119-58056-66wtac.csv +2 -0
  154. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170119-58268-1dty7ny.csv +2 -0
  155. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170119-63803-1mc7fo4.csv +2 -0
  156. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170119-74528-duefru.csv +2 -0
  157. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170119-82684-glhzzy.csv +2 -0
  158. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170119-82810-wamt7d.csv +2 -0
  159. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170119-82946-1vdlbhd.csv +2 -0
  160. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170119-83065-1u153xf.csv +2 -0
  161. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170119-83165-1c32fyg.csv +2 -0
  162. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170119-84188-1wch9sz.csv +2 -0
  163. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170119-86886-1erfhrx.csv +2 -0
  164. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170119-87029-1vof5gs.csv +2 -0
  165. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170120-12481-joulms.csv +2 -0
  166. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170120-12708-h8hiiu.csv +2 -0
  167. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170120-12804-h1kvkh.csv +2 -0
  168. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170120-12985-tjysyw.csv +2 -0
  169. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170120-13084-3zodzd.csv +2 -0
  170. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170120-13449-1bpmult.csv +2 -0
  171. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170120-13540-2g5zwb.csv +2 -0
  172. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170120-15095-wb4mk0.csv +2 -0
  173. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170120-15202-8ib7ha.csv +2 -0
  174. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170120-16523-1s896hk.csv +2 -0
  175. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170120-16637-eboq9e.csv +2 -0
  176. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170120-87818-1j4mz4q.csv +2 -0
  177. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-65471-17j2vti.csv +2 -0
  178. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-65694-1kptcuq.csv +2 -0
  179. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-66245-crezgc.csv +2 -0
  180. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-66415-1krzmy1.csv +2 -0
  181. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-66524-ndzegu.csv +2 -0
  182. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-66655-pjqteu.csv +2 -0
  183. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-66854-r2dyv2.csv +2 -0
  184. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-67000-1t9vfos.csv +2 -0
  185. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-67391-15d0sso.csv +2 -0
  186. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-67538-1gbudl.csv +2 -0
  187. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-67640-p8dmlm.csv +2 -0
  188. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-68349-ziyxe9.csv +2 -0
  189. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-68617-14k1fap.csv +2 -0
  190. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-68815-v1izav.csv +2 -0
  191. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-68984-wcittg.csv +2 -0
  192. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-69642-1hi7zb2.csv +2 -0
  193. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-69802-mq57e0.csv +2 -0
  194. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-73509-mbxhb6.csv +2 -0
  195. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-80682-oask81.csv +2 -0
  196. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-80872-1vkh6vb.csv +2 -0
  197. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-81056-63swkp.csv +2 -0
  198. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-81212-1k8weuv.csv +2 -0
  199. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-81379-6lpon9.csv +2 -0
  200. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-82575-1eioq1a.csv +2 -0
  201. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-84919-1qnjxhv.csv +2 -0
  202. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-85131-1g8jrl5.csv +2 -0
  203. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-85343-yezbz5.csv +2 -0
  204. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-85513-1l2pzgy.csv +2 -0
  205. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-86070-pwkn99.csv +2 -0
  206. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-86277-14ckax5.csv +2 -0
  207. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-86458-1u26pb1.csv +2 -0
  208. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-86599-q2d5io.csv +2 -0
  209. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-86739-hfrzzf.csv +2 -0
  210. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170125-87110-1ky9gnk.csv +2 -0
  211. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170126-27355-hl9693.csv +2 -0
  212. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170126-27618-1pqa3bs.csv +2 -0
  213. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170126-27755-1di5xra.csv +2 -0
  214. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170126-27974-cx2o7z.csv +2 -0
  215. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170126-28133-1q0tz4z.csv +2 -0
  216. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170126-28419-1ia3064.csv +2 -0
  217. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170126-28556-veg3ez.csv +2 -0
  218. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170126-28784-15yhmp3.csv +2 -0
  219. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170126-29002-igofgq.csv +2 -0
  220. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170126-29143-1v25x8a.csv +2 -0
  221. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170126-29291-1qs4kex.csv +2 -0
  222. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170126-29522-5i1a.csv +2 -0
  223. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170126-29660-165adk7.csv +2 -0
  224. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170126-29945-1lvmnay.csv +2 -0
  225. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170126-30103-9qqoc.csv +2 -0
  226. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170126-30381-1de3q2.csv +2 -0
  227. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170126-30864-1mthr0r.csv +2 -0
  228. data/spec/dummy/public/system/importers/attachment_errors/000/000/001/original/failures20170126-30993-wxw7ja.csv +2 -0
  229. data/spec/dummy/public/system/importers/attachment_errors/000/000/002/original/failures20170119-55532-1ujy7xh.csv +2 -0
  230. data/spec/dummy/public/system/importers/attachment_errors/000/000/003/original/failures20170119-87695-1j8psm5.csv +2 -0
  231. data/spec/dummy/public/system/importers/attachment_errors/000/000/003/original/failures20170125-84785-u7rdmo.csv +2 -0
  232. data/spec/dummy/public/system/importers/attachment_errors/000/000/006/original/failures20170118-40447-4jsf3l.csv +2 -0
  233. data/spec/dummy/public/system/importers/attachment_errors/000/000/007/original/failures20170118-44958-l51x0w.csv +2 -0
  234. data/spec/dummy/public/system/importers/attachments/000/000/001/original/companies.csv +3 -0
  235. data/spec/dummy/public/system/importers/attachments/000/000/001/original/companies_invalid.csv +3 -0
  236. data/spec/dummy/public/system/importers/attachments/000/000/002/original/companies.csv +3 -0
  237. data/spec/dummy/public/system/importers/attachments/000/000/002/original/companies_invalid.csv +3 -0
  238. data/spec/dummy/public/system/importers/attachments/000/000/003/original/companies.csv +3 -0
  239. data/spec/dummy/public/system/importers/attachments/000/000/003/original/companies_invalid.csv +3 -0
  240. data/spec/dummy/public/system/importers/attachments/000/000/004/original/companies.csv +3 -0
  241. data/spec/dummy/public/system/importers/attachments/000/000/005/original/companies.csv +3 -0
  242. data/spec/dummy/public/system/importers/attachments/000/000/006/original/companies_invalid.csv +3 -0
  243. data/spec/dummy/public/system/importers/attachments/000/000/007/original/companies_invalid.csv +3 -0
  244. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/-A/-AzUQ_sdncLrgXJW-mT29l7lXefApIPQNpdCv9ETYkI.cache +0 -0
  245. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/0f/0fmItA1G7uruwRE5HZE9TzG9K4A0NbbxGakdWz0cpDE.cache +0 -0
  246. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/2M/2MSWm1oJk8doLU2cxusKHCU78PUDwQ1lrIlu5gXMx_U.cache +1 -0
  247. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/2k/2kXdUd2P4uN67x_E2mUy-AtGn9Fn_h5rQ0PJZi9HzBU.cache +1 -0
  248. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/4b/4bvq3aQAVWrr_CUPXfVFCwfZMnmX-ecl9ZtwAisBlFI.cache +1 -0
  249. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/6-/6-dQ3OmAEd4QXytW4TS1xdUNozHlLKSCawN0oN1oEYw.cache +1 -0
  250. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/63/63b-SgBWtX-UDgRq-Bsol3W40ijIWiT7uxcHRoVXS-M.cache +1 -0
  251. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/7l/7lUIJIvW1FW_GFVqqnVsKSxpeMaZ3noc0g8Eca5eHhQ.cache +0 -0
  252. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/9S/9S1VAatjEVICqM1Cojv-CKBUvl0oELWaNfTyFr_S700.cache +0 -0
  253. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/A9/A9Vpp3VfKYpkCR6f1lAoM4J-w6QQ3fyn3x3TncKXf7U.cache +3 -0
  254. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Av/AvR3LtLvNoPexMzvvUDPuM1V-yuaMddpBdG1RVgQh9Y.cache +0 -0
  255. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Df/Dfad3HZGzx9mtzeig2tWlnuHQl9vAzoUutfVJwWKC5I.cache +0 -0
  256. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Dh/DhZ6bJZj4K7QCbNBTmMjFy3HDpC58SqfiPPoCCsAro4.cache +1 -0
  257. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Hw/HwRNsYmzR0cy4L_V_8SLZiZ9_G6_8E7XiaDV21i9sjA.cache +0 -0
  258. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/I9/I97QBZ0SyWLebPjfYrwCNlM-Omla1LKRTGiTgmMKi2Q.cache +0 -0
  259. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/J7/J7Ihmq6t6WbnmJaBScToEb-AR0U1NqHePsGdxAdJoLo.cache +0 -0
  260. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/KF/KFqlYW7ohx2fJX05v2au1k6Gw7wuzN7UWz2BN90RsAQ.cache +1 -0
  261. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/LL/LLb4gLbgLgFS-LgcrmKXC--d1IaGB8XM_Yrm48bkwdw.cache +0 -0
  262. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/LX/LXS-BomSubWXJSpkNXCH8m0l2y4sB66BaFb2UuAx14o.cache +1 -0
  263. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Lq/LqbLgHiwEzXq7mJX3Dtq5XicBULM8CtvDJdv4Ye45ZY.cache +1 -0
  264. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Nh/Nhtorvc2xM84CWBcqtMIxoqKR4NCkCksOUQ_3UiyegA.cache +1 -0
  265. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Oy/OyEUtus13InbtOxcvt5WdsbydEkrviBwJXD6z9GQaRA.cache +1 -0
  266. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/P6/P6-U-RxLXuRTDz8kHA2kBc3jUHSnNlbEHBOnUa97wyY.cache +1 -0
  267. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Po/Pos0iHsH-rUXDrrdalDi2H6yWVQTcz2ZPyRmQ_RnBPM.cache +1 -0
  268. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Q1/Q1xmk8Ni14zSYsTX_IvrbX1vbGANki_Udrwx7OBgh9w.cache +0 -0
  269. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Qo/QogFhnK16HrvDyiH323Z3xlwwofVibvzgZDmBjqh5VQ.cache +3 -0
  270. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/RI/RIagqSB7X-LbJU0ZwntNWf_KMkOm3kCkc7zR57rP1Bc.cache +1 -0
  271. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/T4/T4WcrrL47jCKFOb5Q1cmn1keh_w3X2OguI_ifzRpS3k.cache +1 -0
  272. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/TA/TAbsAe1o7EI19gckGhtzbtjqOoSVRRLQrc5n3mnCT28.cache +0 -0
  273. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/TG/TGe7XAuizvtm9LtzDo5fR7GrEnyWPL8nBr2eESxA0x0.cache +0 -0
  274. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/V8/V8kjWO7PZcVGI9mBNq17FYWc_muWwcDQF9xWGfnSOjM.cache +1 -0
  275. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/VV/VVtm8HzHyOByhegKNGl09Ak3sHcSr0e70iHSmy75T6A.cache +0 -0
  276. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Vb/VbBBjIpX-u1j_Fko8QfFQ61-bfDS8BaYgGATVKIfp3I.cache +0 -0
  277. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/WR/WRP18y_66NlZHU4W5qM0P1MN8oS5eAlN9UEZrXh3vd0.cache +1 -0
  278. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/Wd/WdUHknjRY-ueTBCEgU4-NzM_BFaTimaeFED6MbFfQLE.cache +0 -0
  279. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/bo/bopbSF0DLQEMLjRvN8Mn4xd-mGx46j9yvENVDA8R9jk.cache +0 -0
  280. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/e4/e4DrxyTxBlZlpP4PQ0zELpYhl4G2eiBksI0_HwQhrVY.cache +0 -0
  281. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/gZ/gZp3uXMHuYQC4hzCr7bQfetKNdJAtbQmg3so2KpW1Dw.cache +2 -0
  282. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/hZ/hZi1k6tpxxCGYxRe7zY74ItcOI8gZrREOpGuA8JSpGg.cache +2 -0
  283. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/iK/IKrFvYc5CMyfkKHP7JFW_bS4-tOG1rVwPFcC-OUpENU.cache +0 -0
  284. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/iK/IkTLxpKuWrwxrM98yl3Ddv4RjOLzyUS5QHQvZ0Cniv8.cache +1 -0
  285. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/iK/iKpMoxBcOmuavL2xUzgc7LQLnT7EKCaZirHx4KMbdw8.cache +1 -0
  286. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/je/jeA_WQ150_Af65U1CnVdHsqqZefOHl2ObGMLRQp--sc.cache +2 -0
  287. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/l1/l1LHMvhocUYdhOc0tOfdy4slQYK2SD4fj6x4mH4wkvI.cache +0 -0
  288. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/lo/loI7P5Fiwnq6YZdxqJFAErc6rV61HWRuL5tVaffS3JY.cache +1 -0
  289. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/m9/m95ShgmvfDO8RuwZpC7gUW0i-FO-k914CWkXd5-LO3I.cache +1 -0
  290. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/my/myHmSL0lcXz8Mgm5gNVoigImnF7acMaTlwl3z_g2lPM.cache +0 -0
  291. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/oo/oocXRRNDTZPTtm859sgr9TxpBrPby6ND88ROtiCfgSU.cache +0 -0
  292. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/p-/p-3_4sMWwoC1eQcdH2fmcIdmlxQBFx6evUCdgfgPyKM.cache +1 -0
  293. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/pE/pEhaat2KBd5SrT7szC_8R1_6hK17FTpvoRFkmCRSD3M.cache +2 -0
  294. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/rn/rnSEYPKQcSZ-D3R7o3aM_1AtiXyLciuL3S3Qa6k_EfI.cache +0 -0
  295. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/sV/sVzlvz069Fh5_GPu0TcrgDBWIHhnwEZ2Rg1AtpEqA9s.cache +0 -0
  296. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/uV/uVH7RdIENZh9BUaGeb6OUciC9H0hTIKsRpAxXMG5R28.cache +1 -0
  297. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/xQ/xQEI_TWc5k3ouSH2fSRrrWRpsLyeG7QQxmcgPjkwbc8.cache +0 -0
  298. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/xQ/xQUUINnLqsr-zxPaIIULgXPE5jh2QtmbdRSYCnhpER4.cache +0 -0
  299. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/xb/xblMCu_z727eCkuWjKJEyre92sVUkcGCpQqGThWe2bk.cache +2 -0
  300. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/yg/ygMyHfDIhhvlowOd5aTDhtXbZCLisqxhDWpdvXd8O5M.cache +0 -0
  301. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/yg/ygrgsR6-nQLxLaFwAquCXfjIZgUTEoYbI5EFH0KlfW0.cache +1 -0
  302. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/yh/yh3Aqjs6HjjQubE9-htvIwUg4cFhMRCl7JyBFYBt0xo.cache +1 -0
  303. data/spec/dummy/tmp/cache/assets/sprockets/v3.0/z0/z0QrtOYRAsWOTFYmpCJqXXyGlHxHUxxKBV3_LMxKV2Y.cache +0 -0
  304. data/spec/examples.txt +50 -0
  305. data/spec/factories/importer.rb +10 -0
  306. data/spec/factories/user.rb +6 -0
  307. data/spec/fixtures/companies.csv +3 -0
  308. data/spec/fixtures/companies_invalid.csv +3 -0
  309. data/spec/lib/csv_import_magic/models_spec.rb +51 -0
  310. data/spec/lib/generators/active_record/csv_import_magic_generator_spec.rb +74 -0
  311. data/spec/lib/generators/active_record/namespaced/csv_import_magic_generator_spec.rb +78 -0
  312. data/spec/lib/generators/csv_import_magic/controllers_generator_spec.rb +34 -0
  313. data/spec/lib/generators/csv_import_magic/install_generator_spec.rb +79 -0
  314. data/spec/lib/generators/csv_import_magic/rails_5/install_generator_spec.rb +62 -0
  315. data/spec/lib/generators/csv_import_magic/views_generator_spec.rb +204 -0
  316. data/spec/models/importer_spec.rb +82 -0
  317. data/spec/rails_helper.rb +61 -0
  318. data/spec/services/csv_import_magic/failure_spec.rb +23 -0
  319. data/spec/services/csv_import_magic/importer_spec.rb +57 -0
  320. data/spec/spec_helper.rb +70 -0
  321. data/spec/support/database_cleaner.rb +12 -0
  322. data/spec/support/factory_girl.rb +12 -0
  323. data/spec/support/paperclip.rb +3 -0
  324. data/spec/support/shoulda_matchers.rb +6 -0
  325. data/spec/support/simplecov.rb +12 -0
  326. data/spec/workers/csv_import_magic/importer_worker_spec.rb +31 -0
  327. metadata +758 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2ae480281a547b7efbd60c64d4b1e0e0e825bd37
4
+ data.tar.gz: a3536a24a78375f15846e17ebf5686363c515a60
5
+ SHA512:
6
+ metadata.gz: 30ed14a1f60c59fc07a17edfd39a959fc3605913eb38dbcea63687a8adf7cb674a5f80f82039237b062dfa42a95fb9a82d47556d236002a8257ff2c3cd13f21f
7
+ data.tar.gz: b4cdabaf4481a3f18199f8eb9eec4b530f9ac7c534237c68193ef361253275e2dee76ea22e84df4ec621b6cc55bd4f5baf7a56a65a4398eb719baac087f3cacc
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2017 Saulo Santiago
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,36 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ require 'rubygems/tasks'
10
+ Gem::Tasks.new
11
+
12
+ RDoc::Task.new(:rdoc) do |rdoc|
13
+ rdoc.rdoc_dir = 'rdoc'
14
+ rdoc.title = 'CsvImportMagic'
15
+ rdoc.options << '--line-numbers'
16
+ rdoc.rdoc_files.include('README.rdoc')
17
+ rdoc.rdoc_files.include('lib/**/*.rb')
18
+ end
19
+
20
+ APP_RAKEFILE = File.expand_path('../spec/dummy/Rakefile', __FILE__)
21
+ load 'rails/tasks/engine.rake'
22
+
23
+ load 'rails/tasks/statistics.rake'
24
+
25
+ Bundler::GemHelper.install_tasks
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'lib'
31
+ t.libs << 'spec'
32
+ t.pattern = 'spec/**/*_test.rb'
33
+ t.verbose = false
34
+ end
35
+
36
+ task default: :test
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,75 @@
1
+ .page-title {
2
+ text-align: center
3
+ }
4
+
5
+ .column {
6
+ float: left;
7
+ width: 25%;
8
+ }
9
+
10
+ .row {
11
+ margin-right: -15px;
12
+ margin-left: -15px;
13
+ }
14
+
15
+ .csv_import {
16
+ display: block;
17
+ overflow: hidden;
18
+ }
19
+
20
+ .portlet {
21
+ border-radius: 4px;
22
+ box-shadow: 0 2px 5px 2px rgba(0,0,0,0.1);
23
+ margin: 0 20px 25px;
24
+ padding: 0 10px 20px;
25
+ }
26
+
27
+ .portlet.bordered {
28
+ border: 1px solid #e1e1e1 !important;
29
+ }
30
+
31
+ .portlet.light {
32
+ background: #fff
33
+ }
34
+
35
+ .portlet-body {
36
+ header {
37
+ background: rgba(0, 0, 0, 0.05);
38
+ margin: 0 -10px 8px;
39
+ padding: .3em 10px;
40
+ white-space: nowrap;
41
+ overflow: hidden;
42
+ text-overflow: ellipsis;
43
+ }
44
+
45
+ select {
46
+ display: block;
47
+ width: 100%;
48
+ height: 34px;
49
+ padding: 6px 12px;
50
+ font-size: 14px;
51
+ line-height: 1.42857143;
52
+ color: #555;
53
+ background-color: #fff;
54
+ background-image: none;
55
+ border: 1px solid #ccc;
56
+ border-radius: 4px;
57
+ -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,0.075);
58
+ box-shadow: inset 0 1px 1px rgba(0,0,0,0.075);
59
+ -webkit-transition: border-color ease-in-out .15s,-webkit-box-shadow ease-in-out .15s;
60
+ -o-transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
61
+ transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s;
62
+ }
63
+
64
+ .hint {
65
+ color: #737373;
66
+ display: block;
67
+ font-size: 12px;
68
+ margin: 10px 0;
69
+ }
70
+
71
+ td.number {
72
+ width: 15px;
73
+ color: #c7c7c7;
74
+ }
75
+ }
@@ -0,0 +1 @@
1
+ @import "csv_import_magic/_theme";
@@ -0,0 +1,4 @@
1
+ module CsvImportMagic
2
+ class BaseController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,64 @@
1
+ module CsvImportMagic
2
+ class ImportersController < CsvImportMagic::BaseController
3
+ helper_method :import_file_csv
4
+ layout 'csv_import_magic'
5
+
6
+ def show
7
+ @importer = ::Importer.find(params[:id])
8
+ end
9
+
10
+ def create
11
+ @importer = ::Importer.new(importer_params)
12
+
13
+ if @importer.save! && import_file_csv
14
+ redirect_to edit_importer_path(@importer), alert: t('csv_import_magic.importers_controller.create.alert')
15
+ end
16
+ rescue ActiveRecord::RecordInvalid, CSV::MalformedCSVError => e
17
+ redirect_to request.referrer, flash: { error: e.message }
18
+ end
19
+
20
+ def edit
21
+ @importer = ::Importer.find(params[:id])
22
+ end
23
+
24
+ def update
25
+ @importer = ::Importer.find(params[:id])
26
+
27
+ if @importer.update(csv_importer_magic_update_params)
28
+ CsvImportMagic::ImporterWorker.perform_async(importer_id: @importer.id, resources: resources)
29
+ redirect_to importer_path(@importer), flash: { notice: t('csv_import_magic.importers_controller.update.notice') }
30
+ else
31
+ errors = @importer.errors.full_messages.to_sentence
32
+ flash[:alert] = errors.present? ? errors : t('csv_import_magic.importers_controller.update.alert')
33
+ render :edit
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ def resources
40
+ method_name = "#{@importer.source}_resources"
41
+ respond_to?(method_name) ? send(method_name) : nil
42
+ end
43
+
44
+ def import_file_csv
45
+ @csv ||= begin
46
+ content = Paperclip.io_adapters.for(@importer.attachment).read.force_encoding('UTF-8')
47
+ content = content.encode('UTF-8', content.encoding, invalid: :replace, undef: :replace)
48
+ ::CSV.parse(content, headers: true, col_sep: column_separator)
49
+ end
50
+ end
51
+
52
+ def column_separator
53
+ ::CsvImportMagic::Importer.new(@importer.id).column_separator
54
+ end
55
+
56
+ def importer_params
57
+ params.require(:importer).permit!
58
+ end
59
+
60
+ def csv_importer_magic_update_params
61
+ params.require(:importer).permit(columns: [])
62
+ end
63
+ end
64
+ end
@@ -0,0 +1,77 @@
1
+ class Importer < ActiveRecord::Base
2
+ include Paperclip::Glue
3
+
4
+ STATUS = %w(pending success error).freeze
5
+
6
+ serialize :columns, Array
7
+
8
+ has_attached_file :attachment
9
+ has_attached_file :attachment_error
10
+
11
+ validates_attachment_content_type :attachment, :attachment_error, content_type: ['text/plain', 'text/csv', 'application/vnd.ms-excel']
12
+ validates_inclusion_of :status, in: STATUS
13
+ validates :attachment, attachment_presence: true
14
+ validates :source, presence: true
15
+ validate :uniqueness_columns
16
+ validate :required_columns, on: :update
17
+
18
+ belongs_to :importable, polymorphic: true
19
+
20
+ before_validation :set_parser
21
+
22
+ def source_klass
23
+ return if source.blank?
24
+ source.classify.constantize
25
+ end
26
+
27
+ def parser_klass
28
+ parser.classify.constantize
29
+ end
30
+
31
+ def importable_columns(name_of_parser = parser)
32
+ source_klass.columns_names(name_of_parser.to_sym)
33
+ end
34
+
35
+ private
36
+
37
+ def set_parser
38
+ return if source_klass.blank? || parser.present?
39
+ self.parser = source_klass.csv_parser_default_name
40
+ end
41
+
42
+ def required_columns
43
+ required_columns = parser_klass.new(content: nil).config.column_definitions.map do |column|
44
+ next unless column.required
45
+ column.name.to_s
46
+ end.compact
47
+
48
+ sameness = (columns & required_columns)
49
+ return if sameness == required_columns
50
+
51
+ columns_to_translate = required_columns - sameness
52
+ return if columns_to_translate.blank?
53
+
54
+ transalated_name_of_columns = columns_to_translate.map do |column|
55
+ source_klass.human_attribute_name(column)
56
+ end.to_sentence
57
+
58
+ errors.add(:columns, I18n.t('errors.messages.missing', count: columns_to_translate.size, columns: transalated_name_of_columns))
59
+ end
60
+
61
+ def uniqueness_columns
62
+ return if columns.empty?
63
+
64
+ headers = columns.clone
65
+ headers.delete('ignore')
66
+ duplicate_headers = headers.find_all { |element| headers.count(element) > 1 }
67
+
68
+ return if duplicate_headers.blank?
69
+
70
+ headers_to_translate = duplicate_headers.uniq
71
+ headers_transalated = headers_to_translate.map do |header|
72
+ source_klass.human_attribute_name(header)
73
+ end.to_sentence
74
+
75
+ errors.add(:columns, I18n.t('errors.messages.uniq', count: headers_to_translate.size, columns: headers_transalated))
76
+ end
77
+ end
@@ -0,0 +1,54 @@
1
+ module CsvImportMagic
2
+ class Failure
3
+ attr_reader :rows, :report, :csv_parsed, :importer, :identifier
4
+
5
+ def initialize(csv_parsed, importer_id)
6
+ @importer = ::Importer.find(importer_id)
7
+ @csv_parsed = csv_parsed
8
+ @report = csv_parsed.report
9
+ @rows = report.invalid_rows
10
+ @identifier = csv_parsed.config.identifiers.first
11
+ end
12
+
13
+ def generate
14
+ set_message_to_success
15
+ set_attachement_error
16
+ end
17
+
18
+ private
19
+
20
+ def set_message_to_success
21
+ return if !csv_parsed.valid_header? || rows.present?
22
+
23
+ importer.update(status: 'success', message: I18n.t('csv_import_magic.services.success'))
24
+ end
25
+
26
+ def set_attachement_error
27
+ return if rows.blank?
28
+
29
+ CSV.open(tmp_failures_file.path, 'wb', col_sep: ';') do |csv|
30
+ append_header(csv)
31
+ append_records(csv)
32
+ end
33
+
34
+ importer.update(status: 'error', message: I18n.t('csv_import_magic.services.failure.records_error'), attachment_error: tmp_failures_file)
35
+ end
36
+
37
+ def tmp_failures_file
38
+ @file ||= Tempfile.new(['failures', '.csv'])
39
+ end
40
+
41
+ def append_header(csv)
42
+ csv << rows.first.header.column_names.map do |column_name|
43
+ importer.source_klass.human_attribute_name(column_name)
44
+ end + [I18n.t('csv_import_magic.services.error_label')]
45
+ end
46
+
47
+ def append_records(csv)
48
+ rows.each do |row|
49
+ record = row.model
50
+ csv << row.row_array + [record.errors.full_messages.to_sentence]
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,53 @@
1
+ module CsvImportMagic
2
+ class Importer
3
+ attr_reader :source_klass, :importer, :csv_parser_class, :resources
4
+
5
+ def initialize(importer_id, resources = nil)
6
+ @importer = ::Importer.find(importer_id)
7
+ @source_klass = importer.source_klass
8
+ @csv_parser_class = importer.parser_klass
9
+ @resources = resources.try(:symbolize_keys!)
10
+ @model = model_with_relation || @source_klass
11
+ end
12
+
13
+ def call
14
+ csv_parsed.run!
15
+ csv_parsed.report
16
+ csv_parsed
17
+ end
18
+
19
+ def column_separator
20
+ header = content.lines("\r")[0].gsub(/[^,;\t]/, '_')
21
+ header.scan(/[,;\t]/).first
22
+ end
23
+
24
+ private
25
+
26
+ def model_with_relation
27
+ return if resources.blank?
28
+ resources[:model].classify.constantize.find(resources[:id]).send(resources[:relation])
29
+ end
30
+
31
+ def csv_parsed
32
+ model = @model
33
+
34
+ @csv_parsed ||= csv_parser_class.new(content: content_with_new_header) do
35
+ model model
36
+ end
37
+ end
38
+
39
+ def content
40
+ @content ||= begin
41
+ content = Paperclip.io_adapters.for(@importer.attachment).read.force_encoding('UTF-8')
42
+ content.encode('UTF-8', content.encoding, invalid: :replace, undef: :replace, universal_newline: true)
43
+ end
44
+ end
45
+
46
+ def content_with_new_header
47
+ new_header = importer.columns.join(column_separator.to_s)
48
+
49
+ body = content.lines[1..-1].join
50
+ body.prepend(new_header + "\n")
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,43 @@
1
+ <% columns = @importer.importable_columns(@importer.parser).map { |column| [@importer.source_klass.human_attribute_name(column), column] }.unshift([t('csv_import_magic.views.importers.edit.ignore_column_label'), :ignore]) %>
2
+
3
+ <h3 class='page-title'>
4
+ <%= t('csv_import_magic.views.importers.edit.title') %>
5
+ </br>
6
+ <small><%= t('csv_import_magic.views.importers.edit.description') %></small>
7
+ </h3>
8
+
9
+ <%= simple_form_for @importer, url: importer_path(@importer) do |f| %>
10
+ <div class="row csv_import">
11
+ <% import_file_csv.headers.each_with_index do |header, i| %>
12
+ <div class="column">
13
+ <div class="portlet light bordered">
14
+ <div class="portlet-body form">
15
+ <header>
16
+ <%= t('csv_import_magic.views.importers.edit.column') %> <b><%= header %></b>
17
+ </header>
18
+
19
+ <% selected = columns.find { |c| c.join(' ').match(/#{header}/i) }.try(:last).presence || :ignore %>
20
+ <%= f.input "columns][", as: :select, collection: columns, label: false, hint: t('csv_import_magic.views.importers.edit.hint'), include_blank: false, selected: f.object.columns[i] || selected %>
21
+
22
+ <header class="examples"><%= t('csv_import_magic.views.importers.edit.example_of_values') %></header>
23
+ <table>
24
+ <tbody>
25
+ <% import_file_csv.first(5).each_with_index do |row, c| %>
26
+ <tr>
27
+ <td class="number"><%= c + 1 %></td>
28
+ <td><%= row[header] || t('csv_import_magic.views.importers.edit.empty_values') %></td>
29
+ </tr>
30
+ <% end %>
31
+ </tbody>
32
+ </table>
33
+ </div>
34
+ </div>
35
+ </div>
36
+ <% end %>
37
+ </div>
38
+
39
+ <div class="form-row actions">
40
+ <%= link_to t('csv_import_magic.views.importers.edit.buttons.cancel'), 'javascript:history.back()', class: 'button button--secondary' %>
41
+ <%= f.submit t('csv_import_magic.views.importers.edit.buttons.import', count: import_file_csv.count), class: 'button button--primary' %>
42
+ </div>
43
+ <% end %>
@@ -0,0 +1,31 @@
1
+ <h2 class='page-title'>
2
+ <%= t('csv_import_magic.views.importers.show.title', model_translated: t("activemodel.models.#{@importer.source}.other")) %>
3
+ </h2>
4
+
5
+ <form style='text-align: center'>
6
+ <div class='form-row' id="<%= @importer.status %>">
7
+ <% if @importer.status == 'pending' %>
8
+ <%= t('csv_import_magic.views.importers.show.waiting') %>
9
+ <% else %>
10
+ <%= @importer.message %>
11
+ <% end %>
12
+ </div>
13
+
14
+ <% if @importer.status == 'pending' %>
15
+ <span class='loading'></span>
16
+ <% end %>
17
+
18
+ <% if @importer.attachment_error.present? %>
19
+ <%= link_to t('csv_import_magic.views.importers.show.buttons.error_file'), @importer.attachment_error.url, class: 'button button--secondary' %>
20
+ <% end %>
21
+
22
+ <%= link_to t('csv_import_magic.views.importers.show.buttons.back'), '/', class: 'button button--primary' %>
23
+ </form>
24
+
25
+ <script>
26
+ if (document.getElementById('pending') != void 0) {
27
+ setInterval(function(){
28
+ location.reload();
29
+ }, 5000);
30
+ }
31
+ </script>
@@ -0,0 +1,31 @@
1
+ <!DOCTYPE html>
2
+ <html lang="pt">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title>Title</title>
6
+
7
+ <link href="/favicon.ico" rel="shortcut icon">
8
+
9
+ <%= stylesheet_link_tag "application", :media => "all" %>
10
+ <%= csrf_meta_tags %>
11
+ </head>
12
+
13
+ <body class="csv_import_magic">
14
+ <%- if flash %>
15
+ <% flash.each do |key, value| %>
16
+ <div class="flash-message <%= key %>"><%= value %></div>
17
+ <% end %>
18
+ <% end %>
19
+
20
+ <div class="wrapper">
21
+ <main>
22
+ <div class="container">
23
+ <%= yield %>
24
+ </div>
25
+ </main>
26
+ </div>
27
+
28
+ <%= javascript_include_tag "application" %>
29
+ <%= yield :javascript %>
30
+ </body>
31
+ </html>
@@ -0,0 +1,13 @@
1
+ module CsvImportMagic
2
+ class ImporterWorker
3
+ include ::Sidekiq::Worker
4
+
5
+ sidekiq_options retry: 1
6
+
7
+ def perform(options)
8
+ options.symbolize_keys!
9
+ csv_parsed = ::CsvImportMagic::Importer.new(options[:importer_id], options[:resources]).call
10
+ CsvImportMagic::Failure.new(csv_parsed, options[:importer_id]).generate
11
+ end
12
+ end
13
+ end
@@ -0,0 +1 @@
1
+ # Add initialization content here
@@ -0,0 +1,71 @@
1
+ en:
2
+ models_and_attributes: &models_and_attributes
3
+ models:
4
+ importer:
5
+ one: Importer
6
+ other: Importers
7
+ attributes:
8
+ importer:
9
+ attachment: CSV
10
+ attachment_error: CSV with errors
11
+ source: Source
12
+ columns: Columns
13
+ status: Status
14
+ message: Message
15
+
16
+ activerecord:
17
+ <<: *models_and_attributes
18
+ activemodel:
19
+ <<: *models_and_attributes
20
+
21
+ csv_import_magic:
22
+ importers_controller:
23
+ create:
24
+ alert: Please, tell us which columns we can find the information you want.
25
+ update:
26
+ notice: File uploaded for processing.
27
+ alert: Unable to send file for processing, please try again.
28
+ services:
29
+ error_label: Errors
30
+ success: Records has been imported!
31
+ failure:
32
+ columns_error:
33
+ one: 'This missing the following column: %{columns}'
34
+ other: 'This missing the following columns: %{columns}'
35
+ records_error: Some record were not imported because they have errors!
36
+ views:
37
+ importers:
38
+ new:
39
+ title: Importer of %{model_translated}
40
+ description: Import your records of %{model_translated} in the fast way
41
+ hint: 'Upload a file <b>CSV</b> with title and headers.'
42
+ buttons:
43
+ import: Import
44
+ show:
45
+ title: Importer of %{model_translated}
46
+ waiting: Processing your file...
47
+ buttons:
48
+ success: Success
49
+ back: Back
50
+ error_file: See error file
51
+ edit:
52
+ title: Adjustment of importater
53
+ description: Indicate which columns should care
54
+ ignore_column_label: Ignore column
55
+ empty_values: Empty
56
+ column: Column
57
+ hint: Choose what type of information this column contains.
58
+ example_of_values: Example of values
59
+ buttons:
60
+ import:
61
+ one: 'Import %{count} record'
62
+ other: 'Import %{count} records'
63
+ cancel: Cancel
64
+ errors:
65
+ messages:
66
+ uniq:
67
+ one: '%{columns} should be unique'
68
+ other: '%{columns} should be unique'
69
+ missing:
70
+ one: '%{columns} is missing'
71
+ other: '%{columns} are missing'
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ CsvImportMagic::Engine.routes.draw do
2
+ resources :importers, only: [:create, :edit, :update, :show]
3
+ end
@@ -0,0 +1,15 @@
1
+ class CreateCompanies < ActiveRecord::Migration
2
+ def change
3
+ create_table :companies do |t|
4
+ t.references :user
5
+ t.string :name
6
+ t.string :street
7
+ t.string :number
8
+ t.string :neighborhood
9
+ t.string :city
10
+ t.string :state
11
+ t.string :country
12
+ t.boolean :active
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,15 @@
1
+ class CreateImporters < ActiveRecord::Migration
2
+ def change
3
+ create_table :importers do |t|
4
+ t.attachment :attachment
5
+ t.attachment :attachment_error
6
+ t.string :source
7
+ t.string :parser
8
+ t.string :columns
9
+ t.string :message
10
+ t.string :status, default: 'pending'
11
+ t.references :importable, polymorphic: true
12
+ t.timestamps
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,8 @@
1
+ class CreateUser < ActiveRecord::Migration
2
+ def change
3
+ create_table :users do |t|
4
+ t.string :name
5
+ t.string :email
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ module CsvImportMagic
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace CsvImportMagic
4
+ end
5
+ end