class ActiveRecord::Generators::YellinGenerator

Public Instance Methods

handle_migration() click to toggle source
# File lib/generators/active_record/yellin_generator.rb, line 8
def handle_migration
  @preexisting_model = (behavior == :invoke && model_exists?) || (behavior == :revoke && migration_exists?)
  if @preexisting_model
    migration_template "migration_update.rb", "db/migrate/add_yellin_to_#{table_name}.rb"
  else
    migration_template "migration_create.rb", "db/migrate/yellin_create_#{table_name}.rb"
  end
end
handle_model() click to toggle source
# File lib/generators/active_record/yellin_generator.rb, line 17
def handle_model
  yellinize_model if behavior == :revoke
  unless @preexisting_model
    invoke "active_record:model", [name], migration: false
  end
  yellinize_model if behavior == :invoke
end

Private Instance Methods

migration_exists?() click to toggle source
# File lib/generators/active_record/yellin_generator.rb, line 41
def migration_exists?
  pattern = File.join(destination_root, "db/migrate", "*_add_yellin_to_#{table_name}.rb")
  Dir.glob(pattern).first
end
model_exists?() click to toggle source
# File lib/generators/active_record/yellin_generator.rb, line 37
def model_exists?
  File.exists? File.join(destination_root, "app/models", "#{file_name}.rb")
end
yellinize_model() click to toggle source
# File lib/generators/active_record/yellin_generator.rb, line 26
      def yellinize_model
        # Avoid subtracting from non-existent file
        if model_exists?
          inject_into_file "app/models/#{file_name}.rb", after: "class #{class_name} < ApplicationRecord\n" do <<-YELLIN
  include Yellin::ActsAsUser
  acts_as_user
         YELLIN
          end
        end
      end