Class: PetergateApi::Generators::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- PetergateApi::Generators::InstallGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/generators/petergate_api/install_generator.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_to_gemfile ⇒ Object
- #copy_app ⇒ Object
- #copy_initializers ⇒ Object
- #create_migrations ⇒ Object
- #insert_into_user_model ⇒ Object
Class Method Details
.next_migration_number(path) ⇒ Object
11 12 13 14 |
# File 'lib/generators/petergate_api/install_generator.rb', line 11 def self.next_migration_number(path) sleep 1 Time.now.utc.strftime("%Y%m%d%H%M%S") end |
Instance Method Details
#add_to_gemfile ⇒ Object
16 17 18 |
# File 'lib/generators/petergate_api/install_generator.rb', line 16 def add_to_gemfile gem "apipie" end |
#copy_app ⇒ Object
38 39 40 |
# File 'lib/generators/petergate_api/install_generator.rb', line 38 def copy_app run "cp -rf #{self.class.source_root}/app/ app/" end |
#copy_initializers ⇒ Object
42 43 44 |
# File 'lib/generators/petergate_api/install_generator.rb', line 42 def copy_initializers run "cp -rf #{self.class.source_root}/initializers config/" end |
#create_migrations ⇒ Object
46 47 48 49 50 51 |
# File 'lib/generators/petergate_api/install_generator.rb', line 46 def create_migrations Dir["#{self.class.source_root}/migrations/*.rb"].sort.each do |filepath| name = File.basename(filepath) migration_template "migrations/#{name}", "db/migrate/#{name}" end end |
#insert_into_user_model ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/generators/petergate_api/install_generator.rb', line 20 def insert_into_user_model inject_into_file "app/models/user.rb", after: /^class\sUser < ActiveRecord::Base/ do "\n has_many :api_connections, class_name: \"::Api::Connection\"\n \n def set_mobile_reset_token!\n begin\nself.mobile_reset_token = Base64.strict_encode64(Devise.friendly_token + self.email).strip\n end while self.class.find_by(mobile_reset_token: self.mobile_reset_token).present?\n self.save\n self.mobile_reset_token\n end\n \n RUBY\n end\nend\n" |