Class: ContentfulMigrationGenerator

Inherits:
Rails::Generators::NamedBase
  • Object
show all
Defined in:
lib/generators/contentful_migration/contentful_migration_generator.rb

Instance Method Summary collapse

Instance Method Details

#copy_initializer_fileObject

source_root File.expand_path(“../templates”, __FILE__)



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/generators/contentful_migration/contentful_migration_generator.rb', line 6

def copy_initializer_file
  name = file_name.to_s
  migration_file = "db/contentful_migrations/#{next_migration_number}_#{name.underscore}.rb"
  create_file migration_file, <<-FILE.strip_heredoc
    class #{name.camelize} < ContentfulMigrations::Migration

      def up
        with_space do |space|
          # TODO: use contentful-management.rb here
        end
      end

      def down
        with_space do |space|
          # TODO: use contentful-management.rb here
        end
      end

    end
 FILE
end

#next_migration_numberObject



28
29
30
# File 'lib/generators/contentful_migration/contentful_migration_generator.rb', line 28

def next_migration_number
  Time.now.utc.strftime('%Y%m%d%H%M%S')
end