lib/padrino-gen/generators/components/actions.rb in padrino-gen-0.11.0 vs lib/padrino-gen/generators/components/actions.rb in padrino-gen-0.11.1

- old
+ new

@@ -76,13 +76,13 @@ forward_text = change_format.gsub(/!TABLE!/, table_name).gsub(/!COLUMNS!/, add_columns) if tuples.any? back_text = change_format.gsub(/!TABLE!/, table_name).gsub(/!COLUMNS!/, remove_columns) if tuples.any? contents = options[:base].dup.gsub(/\s{4}!UP!\n/m, (direction == 'add' ? forward_text.to_s : back_text.to_s)) contents.gsub!(/\s{4}!DOWN!\n/m, (direction == 'add' ? back_text.to_s : forward_text.to_s)) contents = contents.gsub(/!FILENAME!/, filename.underscore).gsub(/!FILECLASS!/, filename.underscore.camelize) - current_migration_number = return_last_migration_number - contents.gsub!(/!VERSION!/, (current_migration_number + 1).to_s) - migration_filename = "#{format("%03d", current_migration_number+1)}_#{filename.underscore}.rb" + migration_number = current_migration_number + contents.gsub!(/!VERSION!/, migration_number) + migration_filename = "#{format("%03d", migration_number)}_#{filename.underscore}.rb" create_file(destination_root('db/migrate/', migration_filename), contents, :skip => true) end end # For migration files @@ -93,10 +93,23 @@ Dir[destination_root('db/migrate/*.rb')].map { |f| File.basename(f).match(/^(\d+)/)[0].to_i }.max.to_i || 0 end + # For migration files + # returns the number of the migration that is being created + # returna timestamp instead if :migration_format: in .components is "timestamp" + # + # @api private + def current_migration_number + if fetch_component_choice(:migration_format).to_s == 'timestamp' + Time.now.utc.strftime("%Y%m%d%H%M%S") + else + return_last_migration_number + 1 + end.to_s + end + # Return true if the migration already exist # # @param [String] filename # File name of the migration file # @@ -183,12 +196,12 @@ # # @api private def controller_actions(fields) field_tuples = fields.map { |value| value.split(":") } action_declarations = field_tuples.map do |request, name| - "#{request} :#{name} do\n end\n" + "#{request} :#{name} do\n\nend\n" end - action_declarations.join("\n ") + action_declarations.join("\n").gsub(/^/, " " * 2).gsub(/^\s*$/, "") end end # Actions end # Components end # Generators end # Padrino