module HorsePower class UserGenerator < Rails::Generators::Base source_root File.expand_path('../templates', __FILE__) def sprint create_migration create_model create_controller create_authorization create_serializer create_admin create_tests create_routes create_facebook end private def create_facebook #run "mkdir app/facebook" template "facebook.rb", "lib/facebook.rb" end def create_migration run "rails g model user username:string:uniq email:string:uniq fb_user_id:string:uniq password_digest:string --no-fixture --skip" run "rm -rf app/models/user.rb" run "rm -rf spec/models/user_spec.rb" run "rm -rf spec/factories/users.rb" end def create_model template "model.rb.erb", "app/models/user.rb" end def create_controller template "controller.rb.erb", "app/controllers/api/v1/users_controller.rb" end def create_authorization template "authorization.rb.erb", "lib/authorization/v1/user.rb" #prepend_file 'gems/authorization/lib/authorization.rb', "require \'authorization/v1/user\'\n" end def create_serializer template "serializer.rb.erb", "app/serializers/v1/user_serializer.rb" end def create_admin template "admin.rb.erb", "app/admin/user.rb" end def create_tests template "specs/model.rb.erb", "spec/api/v1/models/user_spec.rb" template "specs/routing.rb.erb", "spec/api/v1/routing/user_spec.rb" template "specs/factory.rb.erb", "spec/factories/user_1_factory.rb" template "specs/requests.rb.erb", "spec/api/v1/requests/user_spec.rb" end def create_routes inject_into_file "config/routes.rb", after: "scope '1' do\n" do <<-'RUBY' resources :users, except: [:new, :edit, :create], controller: 'api/v1/users' do collection do post 'register', to: "api/v1/users#register" post 'login', to: "api/v1/users#login" post 'facebook_login', to: "api/v1/users#facebook_login" post 'logout', to: "api/v1/users#logout" end end RUBY end end end end