Sha256: 4cca2156d42716fa3d15f55a2bafd6043fa3c4aa36a3963af78a6a1d93cc4300

Contents?: true

Size: 1.24 KB

Versions: 3

Compression:

Stored size: 1.24 KB

Contents

require 'lotus/generators/abstract'
require 'lotus/utils/string'

module Lotus
  module Generators
    # @since 0.4.0
    # @api private
    class Migration < Abstract
      # @since 0.4.0
      # @api private
      #
      # @example
      #   20150612160502
      TIMESTAMP_FORMAT = '%Y%m%d%H%M%S'.freeze

      # @since 0.4.0
      # @api private
      #
      # @example
      #   20150612160502_create_books.rb
      FILENAME = '%{timestamp}_%{name}.rb'.freeze

      # @since 0.4.0
      # @api private
      def initialize(command)
        super

        timestamp = Time.now.utc.strftime(TIMESTAMP_FORMAT)
        filename  = FILENAME % { timestamp: timestamp, name: name }

        env.require_application_environment
        @destination = Lotus::Model.configuration.migrations.join(filename)

        cli.class.source_root(source)
      end

      # @since 0.4.0
      # @api private
      def start
        templates = {
          'migration.rb.tt' => @destination
        }

        templates.each do |src, dst|
          cli.template(source.join(src), target.join(dst), {})
        end
      end

      private

      # @since 0.4.0
      # @api private
      def name
        Utils::String.new(app_name || super).underscore
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
lotusrb-0.5.0 lib/lotus/generators/migration.rb
lotusrb-0.4.1 lib/lotus/generators/migration.rb
lotusrb-0.4.0 lib/lotus/generators/migration.rb