module JsonVoorhees class AppMakeUserGenerator < Rails::Generators::Base source_root File.expand_path('../templates', __FILE__) class_option :arcadex, :type => :boolean, :default => true, :description => "Include arcadex tokens" class_option :active_admin, :type => :boolean, :default => true, :description => "Include admin scoping in routes file" def sprint people if options.active_admin? run "rails g active_admin:resource people::user" end end private def people run "rails plugin new engines/people --mountable" inside('engines/people') do #This needs to run the generator for setting up engines run "rails g json_voorhees:setup_engine people" add_generator #Now it needs to create the user class run "rails g scaffold user username:string:uniq email:string:uniq password_digest:string" #Add this to the routes and gemfile end #Need to add the engine to the main_apps gemfile route "mount People::Engine, at: \'/\'" if options.arcadex? copy_user_files_over route "mount Arcadex::Engine, at: \'/\'" end insert_people_engine end def add_generator inject_into_file "people.gemspec", after: "s.test_files = Dir[\"test/**/*\"]\n" do <<-'RUBY' s.add_development_dependency "json_voorhees" RUBY end end def insert_people_engine inject_into_file 'Gemfile', after: "source \'https://rubygems.org\'\n" do <<-'RUBY' gem 'people', :path => "engines/people" RUBY end end def copy_user_files_over template "user/user_authorizations.rb", "gems/authorization/lib/authorization/people/v1/user.rb" run "rm -f gems/authorization/lib/authorization.rb" template "user/include_authorization.rb", "gems/authorization/lib/authorization.rb" template "user/user_controller.rb", "engines/people/app/controllers/people/api/v1/users_controller.rb" #run "rm -f engines/people/app/models/people/user.rb" template "user/user_model.rb", "engines/people/app/models/people/v1/user.rb" run "rm -f engines/people/config/routes.rb" template "user/user_routes.rb", "engines/people/config/routes.rb" template "user/user_serializer.rb", "engines/people/app/serializers/people/v1/user_serializer.rb" template "user/specs/factory_girl.rb", "spec/factories/people_user_1_factory.rb" template "user/specs/model_specs.rb", "spec/engines/people/api/v1/models/user_spec.rb" template "user/specs/request_specs.rb", "spec/engines/people/api/v1/requests/user_spec.rb" template "user/specs/route_specs.rb", "spec/engines/people/api/v1/routing/user_spec.rb" end end end