Class: OsCtld::Transfer::Log

Inherits:
Object
  • Object
show all
Defined in:
lib/osctld/transfer/log.rb

Direct Known Subclasses

LocalTransfer::Log, SendReceive::Log

Constant Summary collapse

STATES =
%i[stage base incremental transfer cleanup].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ Log

Returns a new instance of Log.



10
11
12
13
14
15
16
17
# File 'lib/osctld/transfer/log.rb', line 10

def initialize(opts)
  @role = opts[:role]
  @state = opts[:state] || :stage
  @snapshots = opts[:snapshots] || []
  @state_snapshot = opts[:state_snapshot]
  @state_running = opts[:state_running]
  @opts = opts[:opts]
end

Instance Attribute Details

#optsObject (readonly)

Returns the value of attribute opts.



7
8
9
# File 'lib/osctld/transfer/log.rb', line 7

def opts
  @opts
end

#roleObject (readonly)

Returns the value of attribute role.



7
8
9
# File 'lib/osctld/transfer/log.rb', line 7

def role
  @role
end

#snapshotsObject (readonly)

Returns the value of attribute snapshots.



7
8
9
# File 'lib/osctld/transfer/log.rb', line 7

def snapshots
  @snapshots
end

#stateObject

Returns the value of attribute state.



7
8
9
# File 'lib/osctld/transfer/log.rb', line 7

def state
  @state
end

#state_runningObject

Returns the value of attribute state_running.



8
9
10
# File 'lib/osctld/transfer/log.rb', line 8

def state_running
  @state_running
end

#state_snapshotObject

Returns the value of attribute state_snapshot.



8
9
10
# File 'lib/osctld/transfer/log.rb', line 8

def state_snapshot
  @state_snapshot
end

Instance Method Details

#can_cancel?(force = false) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
37
# File 'lib/osctld/transfer/log.rb', line 33

def can_cancel?(force = false)
  cancellable = %i[stage base incremental]
  cancellable << :transfer if force
  cancellable.include?(state)
end

#can_continue?(next_state, sync_states: %i[base incremental])) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/osctld/transfer/log.rb', line 19

def can_continue?(next_state, sync_states: %i[base incremental])
  cur_i = STATES.index(state)
  next_i = STATES.index(next_state)

  if !cur_i || !next_i
    false
  elsif (state == :cleanup && next_state == :cleanup) ||
        (sync_states.include?(state) && sync_states.include?(next_state))
    true
  else
    next_i > cur_i
  end
end