Sha256: 1930dae46ed2c66b1a65c9f8168cb288439d7ad0b30e80fea5530c2a84ce57ed
Contents?: true
Size: 1.29 KB
Versions: 1
Compression:
Stored size: 1.29 KB
Contents
# frozen_string_literal: true require 'rails/generators' require 'rails/generators/migration' class ActsAsFavoritorGenerator < Rails::Generators::Base include Rails::Generators::Migration source_root(File.join(File.dirname(__FILE__), 'templates')) desc 'Install acts_as_favoritor' def self.timestamped_migrations if ActiveRecord.respond_to?(:timestamped_migrations) ActiveRecord.timestamped_migrations elsif ActiveRecord::Base.respond_to?(:timestamped_migrations) ActiveRecord::Base.timestamped_migrations end end def self.next_migration_number(dirname) if timestamped_migrations Time.now.utc.strftime('%Y%m%d%H%M%S') else format('%<migration_number>.3d', migration_number: current_migration_number(dirname) + 1) end end def create_initializer template 'initializer.rb', 'config/initializers/acts_as_favoritor.rb' end def create_migration_file migration_template( 'migration.rb.erb', 'db/migrate/acts_as_favoritor_migration.rb', migration_version: migration_version ) end def create_model template 'model.rb', 'app/models/favorite.rb' end private def migration_version return unless Rails.version >= '5.0.0' "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]" end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
acts_as_favoritor-6.0.2 | lib/generators/acts_as_favoritor_generator.rb |