Class: Eventsimple::Generators::EventGenerator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Eventsimple::Generators::EventGenerator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/eventsimple/generators/install_generator.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.next_migration_number(dirname) ⇒ Object
15 16 17 18 |
# File 'lib/eventsimple/generators/install_generator.rb', line 15 def self.next_migration_number(dirname) next_migration_number = current_migration_number(dirname) + 1 ActiveRecord::Migration.next_migration_number(next_migration_number) end |
Instance Method Details
#copy_migrations ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/eventsimple/generators/install_generator.rb', line 20 def copy_migrations migration_template "create_events.erb", "db/migrate/create_#{model_name.underscore}_events.rb", migration_version: migration_version template "event.erb", "app/models/#{model_name.underscore}_event.rb" line = "class #{model_name.camelize} < ApplicationRecord" gsub_file "app/models/#{model_name.underscore}.rb", /(#{Regexp.escape(line)})/mi do |match| <<~RUBY #{match}\n extend Eventsimple::Entity event_driven_by #{model_name.camelize}Event, aggregate_id: :id RUBY end end |
#migration_version ⇒ Object
37 38 39 |
# File 'lib/eventsimple/generators/install_generator.rb', line 37 def migration_version "[#{Rails::VERSION::MAJOR}.#{Rails::VERSION::MINOR}]" end |