Sha256: e4fb7f01674b26abdd3c802062ce0036a5ac71ab87181e67262a55d6f5074777

Contents?: true

Size: 1.37 KB

Versions: 20

Compression:

Stored size: 1.37 KB

Contents

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

module ExternalServices
  module Generators
    # Installs ExternalServices in a rails app.
    class InstallGenerator < ::Rails::Generators::Base
      include ::Rails::Generators::Migration

      source_root File.expand_path('../templates', __FILE__)

      desc 'Generates migrations and directories.'

      def create_migration_files
        add_migration('create_external_services')
        add_migration('create_external_services_api_actions')
      end

      def create_directories
        create_directory 'app/models/external_services/api_actions'
        create_directory 'app/jobs/external_services'
        create_directory 'lib/external_services/api'
      end

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

      protected

      def create_directory(dir)
        dir = File.expand_path(dir)
        empty_directory dir
        add_file File.join(dir, '.keep')
      end

      def add_migration(template)
        migration_dir = File.expand_path('db/migrate')
        if self.class.migration_exists?(migration_dir, template)
          ::Kernel.warn "Migration already exists: #{template}"
        else
          migration_template "migrations/#{template}.rb", "db/migrate/#{template}.rb"
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
external_services-0.4.2 lib/generators/install_generator.rb
external_services-0.4.1 lib/generators/install_generator.rb
external_services-0.4.0 lib/generators/install_generator.rb
external_services-0.3.1 lib/generators/install_generator.rb
external_services-0.3.0 lib/generators/install_generator.rb
external_services-0.2.4 lib/generators/install_generator.rb
external_services-0.2.3 lib/generators/install_generator.rb
external_services-0.2.2 lib/generators/install_generator.rb
external_services-0.2.1 lib/generators/install_generator.rb
external_services-0.2.0 lib/generators/install_generator.rb
external_services-0.1.9 lib/generators/install_generator.rb
external_services-0.1.8 lib/generators/install_generator.rb
external_services-0.1.7 lib/generators/install_generator.rb
external_services-0.1.6 lib/generators/install_generator.rb
external_services-0.1.5 lib/generators/install_generator.rb
external_services-0.1.4 lib/generators/install_generator.rb
external_services-0.1.3 lib/generators/install_generator.rb
external_services-0.1.2 lib/generators/install_generator.rb
external_services-0.1.1 lib/generators/install_generator.rb
external_services-0.1.0 lib/generators/install_generator.rb