class Spectifly::Sequel::MigrationGenerator
Public Class Methods
new(entity, configuration)
click to toggle source
# File lib/spectifly/sequel/migration_generator.rb, line 4 def initialize(entity, configuration) @migration_path = File.expand_path(configuration.migration_path) @entity_definition_path = File.expand_path(configuration.entity_path) @migration_version_type = configuration.migration_version_type @builder = Spectifly::Sequel::Builder.from_path(File.join(@entity_definition_path, entity + '.entity')) end
Public Instance Methods
migration_name()
click to toggle source
# File lib/spectifly/sequel/migration_generator.rb, line 16 def migration_name '%s_create_%s.rb' % [next_migration_version, @builder.model.table_name] end
next_migration_version()
click to toggle source
# File lib/spectifly/sequel/migration_generator.rb, line 20 def next_migration_version if @migration_version_type == 'Timestamp' DateTime.now.strftime('%Y%m%d%H%M%S') else last_migration = 0 length = 3 Dir.glob("#{@migration_path}/*.rb") do |rb_file| migration = File.basename(rb_file).split('_').first if migration.to_i > last_migration last_migration = migration.to_i length = migration.length end end (last_migration + 1).to_s.rjust(length, "0") end end
run!()
click to toggle source
# File lib/spectifly/sequel/migration_generator.rb, line 11 def run! migration_output = @builder.build File.open(File.join(@migration_path, migration_name), 'w') { |f| f.write(migration_output) } end