mirror of
https://github.com/ditkrg/outboxable.git
synced 2026-01-22 22:06:47 +00:00
Adds generator
This commit is contained in:
parent
ac72c51681
commit
ea688be970
36
lib/generators/outboxable/install_generator.rb
Normal file
36
lib/generators/outboxable/install_generator.rb
Normal file
@ -0,0 +1,36 @@
|
||||
module Outboxable
|
||||
class InstallGenerator < Rails::Generators::Base
|
||||
include Rails::Generators::Migration
|
||||
|
||||
source_root File.expand_path('../../../templates', __FILE__)
|
||||
|
||||
# Copy initializer into user app
|
||||
def copy_initializer
|
||||
copy_file('initializer.rb', 'config/initializers/outboxable.rb')
|
||||
end
|
||||
|
||||
# Copy user information (model & Migrations) into user app
|
||||
def create_user_model
|
||||
target_path = "app/models/outbox.rb"
|
||||
unless File.exist?(File.join(Rails.root, target_path))
|
||||
template("outbox.rb", target_path)
|
||||
else
|
||||
say_status('skipped', "Model outbox already exists")
|
||||
end
|
||||
end
|
||||
|
||||
# Copy migrations
|
||||
def copy_migrations
|
||||
if self.class.migration_exists?('db/migrate', "create_outboxable_outboxes")
|
||||
say_status('skipped', "Migration create_outboxable_outboxes already exists")
|
||||
else
|
||||
migration_template('create_outboxable_outboxes.rb', "db/migrate/create_outboxable_outboxes.rb")
|
||||
end
|
||||
end
|
||||
|
||||
# Use to assign migration time otherwise generator will error
|
||||
def self.next_migration_number(dir)
|
||||
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Reference in New Issue
Block a user