Class: Avm::Data::Dumper

Inherits:
Performer show all
Defined in:
lib/avm/data/dumper.rb

Constant Summary collapse

DEFAULT_EXPIRE_TIME =
1.day

Instance Method Summary collapse

Methods inherited from Performer

#immutable_constructor_args, #perform, #performable?

Instance Method Details

#cannot_perform_reasonString?

Returns:

  • (String, nil)


19
20
21
22
23
24
25
26
27
28
# File 'lib/avm/data/dumper.rb', line 19

def cannot_perform_reason
  return nil if !target_path.exist? ||
                [EXISTING_OVERWRITE, EXISTING_ROTATE].include?(existing)

  if existing == EXISTING_DENIED
    'Data exist and overwriting is denied'
  elsif existing == EXISTING_ROTATE_EXPIRED && !target_path_expired?
    'Data exist and yet is not expired'
  end
end

#default_dump_pathPathname

Returns:

  • (Pathname)


31
32
33
34
35
36
# File 'lib/avm/data/dumper.rb', line 31

def default_dump_path
  r = data_owner.data_default_dump_path
  include_excludes_path_suffix.if_present(r) do |v|
    r.basename_sub('.*') { |b| "#{b}#{v}#{r.extname}" }
  end
end

#target_path_expired?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/avm/data/dumper.rb', line 39

def target_path_expired?
  target_path_time.if_present(false) { |v| v >= expire_time }
end

#target_path_timeActiveSupport::Duration?

Returns:

  • (ActiveSupport::Duration, nil)


44
45
46
# File 'lib/avm/data/dumper.rb', line 44

def target_path_time
  target_path.exist? ? ::Time.now - ::File.mtime(target_path) : nil
end