Sha256: 0b469da3654c86b22fcf4f1ab73b7ff8ccfcb18ff7318d41106c6d98059ec79f

Contents?: true

Size: 1.04 KB

Versions: 3

Compression:

Stored size: 1.04 KB

Contents

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

module Crono
  module Generators
    # rails generate crono:install
    class InstallGenerator < ::Rails::Generators::Base
      include Rails::Generators::Migration

      def self.next_migration_number(path)
        ActiveRecord::Generators::Base.next_migration_number(path)
      end

      desc 'Installs crono and generates the necessary configuration files'
      source_root File.expand_path('../templates', __FILE__)

      def copy_config
        template 'cronotab.rb.erb', 'config/cronotab.rb'
      end

      def create_migrations
        migration_template 'migrations/create_crono_jobs.rb',
                           'db/migrate/create_crono_jobs.rb',
                           migration_version: migration_version
      end

      def rails5?
        Rails.version.start_with? '5'
      end

      def migration_version
        if rails5?
          "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]"
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
crono-2.1.0 lib/generators/crono/install/install_generator.rb
crono-2.0.1 lib/generators/crono/install/install_generator.rb
crono-2.0.0 lib/generators/crono/install/install_generator.rb