Class: GoodMigrations::MigrationDetails

Inherits:
Object
  • Object
show all
Defined in:
lib/good_migrations/migration_details.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ MigrationDetails

Returns a new instance of MigrationDetails.



4
5
6
# File 'lib/good_migrations/migration_details.rb', line 4

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



3
4
5
# File 'lib/good_migrations/migration_details.rb', line 3

def path
  @path
end

Class Method Details

.currently_executingObject



8
9
10
11
12
13
14
15
# File 'lib/good_migrations/migration_details.rb', line 8

def self.currently_executing
  migrate_dir_path = Rails.root.join("db/migrate/").to_s

  if (loc = caller.detect { |loc| loc.start_with?(migrate_dir_path) })
    line_number_index = loc.index(":", migrate_dir_path.size)
    new(loc[0...line_number_index])
  end
end

Instance Method Details

#associated_timeObject



17
18
19
20
21
# File 'lib/good_migrations/migration_details.rb', line 17

def associated_time
  timestamp_string = File.basename(@path).partition("_").first
  return if timestamp_string.size != 14
  Time.parse(timestamp_string)
end

#considered_before?(time) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
26
27
28
# File 'lib/good_migrations/migration_details.rb', line 23

def considered_before?(time)
  return false if time.nil?
  my_time = associated_time
  return false if my_time.nil?
  my_time < time
end