Sha256: 9fbe55f3bcdd68d299726078de07bd87fceb886fb02f4d428d4bc5daa623ec4d

Contents?: true

Size: 948 Bytes

Versions: 6

Compression:

Stored size: 948 Bytes

Contents

require 'rails/generators'
require 'rails/generators/migration'

module Sunrise
  module Posts
    class InstallGenerator < Rails::Generators::Base
      include Rails::Generators::Migration
      
      source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
      class_option :migrations, :type => :boolean, :default => true, :description => "Generate migrations files"

      desc "Generates post migration and model"

      def self.current_time
        @current_time ||= Time.now
        @current_time += 1.minute
      end

      def self.next_migration_number(dirname)
        current_time.strftime("%Y%m%d%H%M%S")
      end
      
      def create_model
        copy_file('post.rb', 'app/models/post.rb')
      end
      
      def create_migration
        if options.migrations
          migration_template "create_posts.rb", File.join('db/migrate', "sunrise_create_posts.rb")
        end
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
sunrise-posts-0.1.5 lib/generators/sunrise/posts/install_generator.rb
sunrise-posts-0.1.4 lib/generators/sunrise/posts/install_generator.rb
sunrise-posts-0.1.3 lib/generators/sunrise/posts/install_generator.rb
sunrise-posts-0.1.2 lib/generators/sunrise/posts/install_generator.rb
sunrise-posts-0.1.1 lib/generators/sunrise/posts/install_generator.rb
sunrise-posts-0.1.0 lib/generators/sunrise/posts/install_generator.rb