Class: EasyML::Support::SyncedDirectory

Inherits:
Object
  • Object
show all
Includes:
GlueGun::DSL
Defined in:
lib/easy_ml/support/synced_directory.rb

Instance Method Summary collapse

Instance Method Details

#age(format: "human") ⇒ Object



27
28
29
# File 'lib/easy_ml/support/synced_directory.rb', line 27

def age(format: "human")
  Age.age(last_updated_at, EST.now, format: format)
end

#filesObject



23
24
25
# File 'lib/easy_ml/support/synced_directory.rb', line 23

def files
  Dir.glob(File.join(root_dir, File.join(s3_prefix, "*.csv")))
end

#last_updated_atObject



41
42
43
44
45
# File 'lib/easy_ml/support/synced_directory.rb', line 41

def last_updated_at
  return nil if files.empty?

  files.map { |file| File.mtime(file) }.max.in_time_zone(EST)
end

#stale?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/easy_ml/support/synced_directory.rb', line 31

def stale?
  !synced?
end

#syncObject



14
15
16
17
18
19
20
21
# File 'lib/easy_ml/support/synced_directory.rb', line 14

def sync
  return false if synced?

  mk_dir
  clean_dir!
  download
  true
end

#synced?Boolean

Returns:

  • (Boolean)


35
36
37
38
39
# File 'lib/easy_ml/support/synced_directory.rb', line 35

def synced?
  return @synced unless @synced.nil?

  @synced = calculate_synced
end