Sha256: fa0049914df33deac5f09892677906c82b2a4d21d94c669b74ad9e15bb87021d
Contents?: true
Size: 1.17 KB
Versions: 10
Compression:
Stored size: 1.17 KB
Contents
require 'rails/generators/active_record' require 'generators/csv_import_magic/orm_helpers' module ActiveRecord module Generators class CsvImportMagicGenerator < ActiveRecord::Generators::Base source_root File.expand_path('../templates', __FILE__) class_option :columns, aliases: '-c', type: :array, required: true, desc: 'Select specific columns yout want parser' include CsvImportMagic::Generators::OrmHelpers def generate_model invoke 'active_record:model', [name], migration: false unless model_exists? && behavior == :invoke class_path = if name.match(/\:\:/).present? name.to_s.gsub('::', '/') else name end template 'csv_parser.rb', "app/csv_parsers/#{class_path}_parser.rb" end def inject_csv_import_magic_content content = model_contents(options) class_path = [class_name] indent_depth = class_path.size - 1 content = content.split("\n").map { |line| ' ' * indent_depth + line } .join("\n") << "\n" inject_into_class(model_path, class_path.last, content) if model_exists? end end end end
Version data entries
10 entries across 10 versions & 1 rubygems