Class: Rubopolis::Cop::MigrationFilename
- Inherits:
-
RuboCop::Cop::Base
- Object
- RuboCop::Cop::Base
- Rubopolis::Cop::MigrationFilename
- Includes:
- RuboCop::Cop::RangeHelp
- Defined in:
- lib/rubopolis/cop/migration_filename.rb
Overview
Constant Summary collapse
- MSG_FUTURE_TIMESTAMP =
'The name of this file (`%<basename>s`) should not use future timestamp.'
Instance Method Summary collapse
- #for_bad_filename(file_path) {|source_range(processed_source.buffer, 1, 0), msg| ... } ⇒ Object
- #on_new_investigation ⇒ Object
Instance Method Details
#for_bad_filename(file_path) {|source_range(processed_source.buffer, 1, 0), msg| ... } ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/rubopolis/cop/migration_filename.rb', line 28 def for_bad_filename(file_path) basename = File.basename(file_path) filename_datetime = basename.split('_', 2).first = Time.now.strftime('%Y%m%d%H%M%S') msg = format(MSG_FUTURE_TIMESTAMP, basename: basename) if filename_datetime > yield source_range(processed_source.buffer, 1, 0), msg if msg end |
#on_new_investigation ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/rubopolis/cop/migration_filename.rb', line 20 def on_new_investigation file_path = processed_source.file_path return unless file_path.include?('/db/') for_bad_filename(file_path) { |range, msg| add_offense(range, message: msg) } end |