Class: Outboxable::InstallGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Outboxable::InstallGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/generators/outboxable/install_generator.rb
Class Method Summary collapse
-
.next_migration_number(_dir) ⇒ Object
Use to assign migration time otherwise generator will error.
Instance Method Summary collapse
-
#copy_initializer ⇒ Object
Copy initializer into user app.
-
#copy_migrations ⇒ Object
Copy migrations.
-
#create_user_model ⇒ Object
Copy user information (model & Migrations) into user app.
-
#initialize ⇒ InstallGenerator
constructor
A new instance of InstallGenerator.
Constructor Details
#initialize ⇒ InstallGenerator
Returns a new instance of InstallGenerator.
8 9 10 11 12 13 |
# File 'lib/generators/outboxable/install_generator.rb', line 8 def initialize super @orm = [:orm] || 'activerecord' %w[activerecord mongoid].include?(@orm) || raise(ArgumentError, 'Invalid ORM. Only ActiveRecord and Mongoid are supported.') end |
Class Method Details
.next_migration_number(_dir) ⇒ Object
Use to assign migration time otherwise generator will error
45 46 47 |
# File 'lib/generators/outboxable/install_generator.rb', line 45 def self.next_migration_number(_dir) Time.now.utc.strftime('%Y%m%d%H%M%S') end |
Instance Method Details
#copy_initializer ⇒ Object
Copy initializer into user app
16 17 18 19 |
# File 'lib/generators/outboxable/install_generator.rb', line 16 def copy_initializer copy_file('activerecord_initializer.rb', 'config/initializers/z_outboxable.rb') if @orm == 'activerecord' copy_file('mongoid_initializer.rb', 'config/initializers/z_outboxable.rb') if @orm == 'mongoid' end |
#copy_migrations ⇒ Object
Copy migrations
34 35 36 37 38 39 40 41 42 |
# File 'lib/generators/outboxable/install_generator.rb', line 34 def copy_migrations return if @orm == 'mongoid' 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 |
#create_user_model ⇒ Object
Copy user information (model & Migrations) into user app
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/generators/outboxable/install_generator.rb', line 22 def create_user_model target_path = 'app/models/outbox.rb' if Rails.root.join(target_path).exist? say_status('skipped', 'Model outbox already exists') else template('activerecrod_outbox.rb', target_path) if @orm == 'activerecord' template('mongoid_outbox.rb', target_path) if @orm == 'mongoid' end end |