iprog_otp_generator 0.1.7 → 0.1.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
 - data/lib/generators/install_generator.rb +29 -17
 - data/lib/iprog_otp_generator/version.rb +1 -1
 - metadata +1 -1
 
    
        checksums.yaml
    CHANGED
    
    | 
         @@ -1,7 +1,7 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            ---
         
     | 
| 
       2 
2 
     | 
    
         
             
            SHA256:
         
     | 
| 
       3 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       4 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 3 
     | 
    
         
            +
              metadata.gz: fa66607446cd7a6261c70e60cb747b11bb34b5a2999ae07a58c9c9df305b7df1
         
     | 
| 
      
 4 
     | 
    
         
            +
              data.tar.gz: 1dbabeabf55f99190992098a7a787c30f6a41ec3c86d0965d42f5afb9cbed2ba
         
     | 
| 
       5 
5 
     | 
    
         
             
            SHA512:
         
     | 
| 
       6 
     | 
    
         
            -
              metadata.gz:  
     | 
| 
       7 
     | 
    
         
            -
              data.tar.gz:  
     | 
| 
      
 6 
     | 
    
         
            +
              metadata.gz: 41e4b462bbbd5739a1f119ec28eb293c66a0db65870c97b6ba269a56111b11f8a35ae5d2e383787f1fbbbae2e33dee5e8ee9044882cffe7ce89f577af1d3f7e6
         
     | 
| 
      
 7 
     | 
    
         
            +
              data.tar.gz: '09d20261de58d30a5d1c0f4a69ffd46b1a70477264a89bbe3dcdf0090b7d458092b03d655364dba421d512f79fefafe2a155cf8432390414d06a8b1fd734a714'
         
     | 
| 
         @@ -1,29 +1,41 @@ 
     | 
|
| 
       1 
1 
     | 
    
         
             
            # frozen_string_literal: true
         
     | 
| 
       2 
2 
     | 
    
         
             
            require 'rails/generators'
         
     | 
| 
      
 3 
     | 
    
         
            +
            require 'rails/generators/migration'
         
     | 
| 
       3 
4 
     | 
    
         | 
| 
       4 
5 
     | 
    
         
             
            module IprogOtpGenerator
         
     | 
| 
       5 
     | 
    
         
            -
             
     | 
| 
       6 
     | 
    
         
            -
             
     | 
| 
       7 
     | 
    
         
            -
             
     | 
| 
      
 6 
     | 
    
         
            +
              module Generators
         
     | 
| 
      
 7 
     | 
    
         
            +
                class InstallGenerator < Rails::Generators::Base
         
     | 
| 
      
 8 
     | 
    
         
            +
                  include Rails::Generators::Migration  # Place it here to include migration support
         
     | 
| 
       8 
9 
     | 
    
         | 
| 
       9 
     | 
    
         
            -
             
     | 
| 
      
 10 
     | 
    
         
            +
                  source_root File.expand_path('../', __dir__)  # Make sure this points to your templates folder
         
     | 
| 
       10 
11 
     | 
    
         | 
| 
       11 
     | 
    
         
            -
             
     | 
| 
      
 12 
     | 
    
         
            +
                  argument :model_name, type: :string, default: "User", banner: "MODEL"
         
     | 
| 
       12 
13 
     | 
    
         | 
| 
       13 
     | 
    
         
            -
             
     | 
| 
       14 
     | 
    
         
            -
                model      = model_name.constantize
         
     | 
| 
       15 
     | 
    
         
            -
                table_name = model.table_name
         
     | 
| 
       16 
     | 
    
         
            -
                timestamp  = Time.now.utc.strftime("%Y%m%d%H%M%S")
         
     | 
| 
      
 14 
     | 
    
         
            +
                  desc "Creates a migration to add OTP fields to the specified model's table"
         
     | 
| 
       17 
15 
     | 
    
         | 
| 
       18 
     | 
    
         
            -
             
     | 
| 
       19 
     | 
    
         
            -
             
     | 
| 
      
 16 
     | 
    
         
            +
                  def copy_migration
         
     | 
| 
      
 17 
     | 
    
         
            +
                    model      = model_name.constantize
         
     | 
| 
      
 18 
     | 
    
         
            +
                    table_name = model.table_name
         
     | 
| 
       20 
19 
     | 
    
         | 
| 
       21 
     | 
    
         
            -
             
     | 
| 
       22 
     | 
    
         
            -
             
     | 
| 
       23 
     | 
    
         
            -
             
     | 
| 
       24 
     | 
    
         
            -
             
     | 
| 
      
 20 
     | 
    
         
            +
                    migration_template "migration.rb.tt", "db/migrate/add_otp_fields_to_#{table_name}.rb", table_name: table_name, migration_version: migration_version
         
     | 
| 
      
 21 
     | 
    
         
            +
                  end
         
     | 
| 
      
 22 
     | 
    
         
            +
             
     | 
| 
      
 23 
     | 
    
         
            +
                  # This method is required by Rails generators to create a unique timestamp for migration files
         
     | 
| 
      
 24 
     | 
    
         
            +
                  def self.next_migration_number(dirname)
         
     | 
| 
      
 25 
     | 
    
         
            +
                    if ActiveRecord::Base.timestamped_migrations
         
     | 
| 
      
 26 
     | 
    
         
            +
                      Time.now.utc.strftime("%Y%m%d%H%M%S")
         
     | 
| 
      
 27 
     | 
    
         
            +
                    else
         
     | 
| 
      
 28 
     | 
    
         
            +
                      "%.3d" % (current_migration_number(dirname) + 1)
         
     | 
| 
      
 29 
     | 
    
         
            +
                    end
         
     | 
| 
      
 30 
     | 
    
         
            +
                  end
         
     | 
| 
      
 31 
     | 
    
         
            +
             
     | 
| 
      
 32 
     | 
    
         
            +
                  private
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                  def migration_version
         
     | 
| 
      
 35 
     | 
    
         
            +
                    if Rails::VERSION::MAJOR >= 5
         
     | 
| 
      
 36 
     | 
    
         
            +
                      "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
         
     | 
| 
      
 37 
     | 
    
         
            +
                    end
         
     | 
| 
      
 38 
     | 
    
         
            +
                  end
         
     | 
| 
       25 
39 
     | 
    
         
             
                end
         
     | 
| 
       26 
     | 
    
         
            -
               end
         
     | 
| 
       27 
40 
     | 
    
         
             
              end
         
     | 
| 
       28 
     | 
    
         
            -
             end
         
     | 
| 
       29 
41 
     | 
    
         
             
            end
         
     |