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" custom_active_admin end end private def custom_active_admin template "active_admin_register.rb.erb", "app/admin/people_user.rb" end 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 add_ordering end #Need to add the engine to the main_apps gemfile route "mount People::Engine, at: \'/\'" copy_user_files_over if options.arcadex? route "mount Arcadex::Engine, at: \'/\'" end insert_people_engine end def add_ordering #app/models/people/user.rb inject_into_file "app/models/people/user.rb", after: "class User < ActiveRecord::Base\n" do <<-'RUBY' def self.recent(num) ::People::User.order("created_at DESC").limit(num) end RUBY end 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" if options.arcadex? template "user/specs/request_specs.rb", "spec/engines/people/api/v1/requests/user_spec.rb" else template "user/specs/no_arcadex_request_specs.rb", "spec/engines/people/api/v1/requests/user_spec.rb" end template "user/specs/route_specs.rb", "spec/engines/people/api/v1/routing/user_spec.rb" end end end