Class: Mighost::OrphanDetector::OrphanedMigration

Inherits:
Object
  • Object
show all
Defined in:
lib/mighost/orphan_detector.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version:, filename: nil, branch_name: nil, git_sha: nil, migrated_at: nil, source: nil, dismissed: false, author_name: nil, author_email: nil) ⇒ OrphanedMigration

Returns a new instance of OrphanedMigration.



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/mighost/orphan_detector.rb', line 14

def initialize(version:, filename: nil, branch_name: nil, git_sha: nil, migrated_at: nil, source: nil, dismissed: false, author_name: nil, author_email: nil)
  @version = version
  @filename = filename
  @branch_name = branch_name
  @git_sha = git_sha
  @migrated_at = migrated_at
  @source = source
  @dismissed = dismissed
  @author_name = author_name
  @author_email = author_email
end

Instance Attribute Details

#author_emailObject (readonly)

Returns the value of attribute author_email.



12
13
14
# File 'lib/mighost/orphan_detector.rb', line 12

def author_email
  @author_email
end

#author_nameObject (readonly)

Returns the value of attribute author_name.



12
13
14
# File 'lib/mighost/orphan_detector.rb', line 12

def author_name
  @author_name
end

#branch_nameObject (readonly)

Returns the value of attribute branch_name.



12
13
14
# File 'lib/mighost/orphan_detector.rb', line 12

def branch_name
  @branch_name
end

#dismissedObject (readonly)

Returns the value of attribute dismissed.



12
13
14
# File 'lib/mighost/orphan_detector.rb', line 12

def dismissed
  @dismissed
end

#filenameObject (readonly)

Returns the value of attribute filename.



12
13
14
# File 'lib/mighost/orphan_detector.rb', line 12

def filename
  @filename
end

#git_shaObject (readonly)

Returns the value of attribute git_sha.



12
13
14
# File 'lib/mighost/orphan_detector.rb', line 12

def git_sha
  @git_sha
end

#migrated_atObject (readonly)

Returns the value of attribute migrated_at.



12
13
14
# File 'lib/mighost/orphan_detector.rb', line 12

def migrated_at
  @migrated_at
end

#sourceObject (readonly)

Returns the value of attribute source.



12
13
14
# File 'lib/mighost/orphan_detector.rb', line 12

def source
  @source
end

#versionObject (readonly)

Returns the value of attribute version.



12
13
14
# File 'lib/mighost/orphan_detector.rb', line 12

def version
  @version
end

Instance Method Details

#actionable?Boolean

Is actionable? (recoverable OR not old enough to suggest dismissal)

Returns:

  • (Boolean)


64
65
66
# File 'lib/mighost/orphan_detector.rb', line 64

def actionable?
  !suggested_for_dismiss?
end

#created_atObject

Parse version timestamp (YYYYMMDDHHmmss) -> Time



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/mighost/orphan_detector.rb', line 39

def created_at
  return @created_at if defined?(@created_at)

  @created_at = begin
    if version =~ /^(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})$/
      Time.new($1.to_i, $2.to_i, $3.to_i, $4.to_i, $5.to_i, $6.to_i)
    end
  rescue ArgumentError
    nil
  end
end

#old?(threshold: Mighost.configuration.dismiss_old_threshold) ⇒ Boolean

Is migration older than threshold?

Returns:

  • (Boolean)


52
53
54
55
56
# File 'lib/mighost/orphan_detector.rb', line 52

def old?(threshold: Mighost.configuration.dismiss_old_threshold)
  return false unless created_at

  created_at < threshold.ago
end

#recoverable?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/mighost/orphan_detector.rb', line 26

def recoverable?
  source.present?
end

#recovery_sourceObject



30
31
32
33
34
35
36
# File 'lib/mighost/orphan_detector.rb', line 30

def recovery_source
  case source
  when "file" then :snapshot
  when "git" then :branch
  when "worktree" then :worktree
  end
end

#suggested_for_dismiss?Boolean

Should suggest dismissal? (unrecoverable AND old)

Returns:

  • (Boolean)


59
60
61
# File 'lib/mighost/orphan_detector.rb', line 59

def suggested_for_dismiss?
  !recoverable? && old?
end