Sha256: 21000a4dcf1a6b3b2511e372046f73fe30b1633f24af8cb938047febac3588ad

Contents?: true

Size: 1.22 KB

Versions: 1

Compression:

Stored size: 1.22 KB

Contents

module Merb::Generators
  
  class SessionMigrationGenerator < ComponentGenerator

    def self.source_root
      File.join(super, 'session_migration')
    end
    
    desc <<-DESC
      Generates a new session migration.
    DESC
    
    option :orm, :desc => 'Object-Relation Mapper to use (one of: none, activerecord, datamapper, sequel)'
    
    template :session_migration_activerecord, :orm => :activerecord do
      source('activerecord/schema/migrations/%version%_sessions.rb')
      destination("schema/migrations/#{version}_sessions.rb")
    end
    
    template :session_migration_sequel, :orm => :sequel do
      source('sequel/schema/migrations/%version%_sessions.rb')
      destination("schema/migrations/#{version}_sessions.rb")
    end
    
    def version
      # TODO: handle ActiveRecord timestamped migrations
      format("%03d", current_migration_nr + 1)
    end

    protected
    
    def destination_directory
      File.join(destination_root, 'schema', 'migrations')
    end
    
    def current_migration_nr
      current_migration_number = Dir["#{destination_directory}/*"].map{|f| File.basename(f).match(/^(\d+)/)[0].to_i  }.max.to_i
    end
    
  end
  
  add :session_migration, SessionMigrationGenerator
  
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
thorero-gen-0.9.4 lib/merb-gen/session_migration.rb