aboutsummaryrefslogblamecommitdiffstats
path: root/activerecord/lib/rails/generators/active_record/session_migration/session_migration_generator.rb
blob: 90923f6e74d6178c6cd97ffa0fca94927d56908b (plain) (tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
                                        
                                                  












                                                                        
                                                                             
                                                            


                                                                                                             




           
require 'rails/generators/active_record'
require 'active_support/core_ext/object/inclusion'

module ActiveRecord
  module Generators
    class SessionMigrationGenerator < Base
      argument :name, :type => :string, :default => "add_sessions_table"

      def create_migration_file
        migration_template "migration.rb", "db/migrate/#{file_name}.rb"
      end

      protected

        def session_table_name
          current_table_name = ActiveRecord::SessionStore::Session.table_name
          if current_table_name.in?(["sessions", "session"])
            current_table_name = (ActiveRecord::Base.pluralize_table_names ? 'session'.pluralize : 'session')
          end
          current_table_name
        end

    end
  end
end