class Upgrow::Generators::InstallGenerator
Public Instance Methods
create_app_files()
click to toggle source
# File lib/generators/upgrow/install/install_generator.rb, line 49 def create_app_files directory('app') end
move_existing_models()
click to toggle source
# File lib/generators/upgrow/install/install_generator.rb, line 10 def move_existing_models pattern = File.expand_path('app/models/**/*.rb', destination_root) files = Dir.glob(pattern) return if files.empty? unless yes?('Would you like to convert all models into Records?', :blue) say( 'Please convert your existing models into Records manually. You '\ 'may move them to the app/records folder, add the Record suffix '\ 'to their class names, and include Upgrow::Record.', :yellow ) return end files.each do |original| target = relative_to_original_destination_root(original) .sub(%r{\Aapp/models/}, 'app/records/') .sub(/^(.+(?<!_record))\.rb\z/, '\1_record.rb') move_file(original, target) inject_into_file( target, 'Record', after: /class (?!\w+Record\s)\w+/, force: true, verbose: false ) inject_into_class( target, 'ApplicationRecord', " include Upgrow::Record\n", verbose: false ) end end