Class: EventSourcedRecord::EventGenerator
- Inherits:
-
ActiveRecord::Generators::Base
- Object
- ActiveRecord::Generators::Base
- EventSourcedRecord::EventGenerator
- Defined in:
- lib/generators/event_sourced_record/event_generator.rb
Instance Method Summary collapse
Instance Method Details
#attributes_with_index ⇒ Object
34 35 36 |
# File 'lib/generators/event_sourced_record/event_generator.rb', line 34 def attributes_with_index attributes.select { |a| a.has_index? || (a.reference? && [:indexes]) } end |
#create_migration_file ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/generators/event_sourced_record/event_generator.rb', line 8 def create_migration_file ar_major_version = ActiveRecord::VERSION::MAJOR if ar_major_version >= 4 attributes_str = attributes.map { |attr| = attr.name << ":#{attr.type}" if attr.type << ':index' if attr.has_index? }.join(' ') generate( "migration", "create_#{event_table_name} #{attributes_str}" ) else migration_template( "event_migration.ar3.rb", "db/migrate/create_#{event_table_name}.rb" ) end end |
#create_model_file ⇒ Object
27 28 29 30 31 32 |
# File 'lib/generators/event_sourced_record/event_generator.rb', line 27 def create_model_file template( 'event_model.rb', File.join('app/models', class_path, "#{event_file_name}.rb") ) end |