Class: ArchivedRemoteObject::Archive::ArchivedObject

Inherits:
Object
  • Object
show all
Defined in:
lib/archived_remote_object/archive/archived_object.rb

Constant Summary collapse

CantBeRestoredError =
Class.new(StandardError)
CantStopArchivingOnDurationError =
Class.new(StandardError)

Instance Method Summary collapse

Constructor Details

#initialize(key:, remote_object: AwsS3::ArchivedObject.new(key: key)) ⇒ ArchivedObject

Returns a new instance of ArchivedObject.



9
10
11
12
13
14
# File 'lib/archived_remote_object/archive/archived_object.rb', line 9

def initialize(
  key:,
  remote_object: AwsS3::ArchivedObject.new(key: key)
)
  self.remote_object = remote_object
end

Instance Method Details

#archived?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/archived_remote_object/archive/archived_object.rb', line 16

def archived?
  remote_object.archived?
end

#available?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/archived_remote_object/archive/archived_object.rb', line 44

def available?
  !archived? || restored?
end

#debug_stateObject



52
53
54
55
56
57
58
# File 'lib/archived_remote_object/archive/archived_object.rb', line 52

def debug_state
  {
    restore_in_progress: restore_in_progress?,
    restored: restored?,
    **remote_object.debug_state
  }
end

#restoreObject



32
33
34
35
36
# File 'lib/archived_remote_object/archive/archived_object.rb', line 32

def restore
  raise CantBeRestoredError if available? || restore_in_progress?

  remote_object.restore
end

#restore_in_progress?Boolean

Returns:

  • (Boolean)


20
21
22
23
24
# File 'lib/archived_remote_object/archive/archived_object.rb', line 20

def restore_in_progress?
  return false unless archived?

  remote_object.restore_in_progress?
end

#restored?Boolean

Returns:

  • (Boolean)


26
27
28
29
30
# File 'lib/archived_remote_object/archive/archived_object.rb', line 26

def restored?
  return false unless archived?

  remote_object.restored?
end

#stop_archiving_on_durationObject



38
39
40
41
42
# File 'lib/archived_remote_object/archive/archived_object.rb', line 38

def stop_archiving_on_duration
  raise CantStopArchivingOnDurationError if !restored? || restore_in_progress?

  remote_object.stop_archiving_on_duration
end

#syncObject



48
49
50
# File 'lib/archived_remote_object/archive/archived_object.rb', line 48

def sync
  tap { remote_object.sync }
end