Module: S3lite::Base

Includes:
S3
Defined in:
lib/s3lite/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from S3

#s3_get, #s3_list, #s3_put

Instance Attribute Details

#last_backup_atObject

Returns the value of attribute last_backup_at.



2
3
4
# File 'lib/s3lite/base.rb', line 2

def last_backup_at
  @last_backup_at
end

Instance Method Details

#backedup?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/s3lite/base.rb', line 26

def backedup?
  to_json == latest.to_json
end

#backup(raise_error: false) ⇒ Object



5
6
7
8
9
10
# File 'lib/s3lite/base.rb', line 5

def backup(raise_error: false)
  s3_put(path: s3_path, body: to_json)
rescue => e
  raise e if raise_error
  false
end

#backup!Object



12
13
14
# File 'lib/s3lite/base.rb', line 12

def backup!
  backup(raise_error: true)
end

#latestObject



16
17
18
19
20
21
22
23
24
# File 'lib/s3lite/base.rb', line 16

def latest
  obj = s3_get(s3_path)
  body = obj.body.read
  json = S3lite::Parse.json(body)
  json[:last_backup_at] = obj.last_modified
  self.class.new(json)
rescue Aws::S3::Errors::AccessDenied, Aws::S3::Errors::NotFound
  nil
end

#s3_pathObject



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

def s3_path
  if defined?(Rails)
    "#{Rails.env}/#{self.class.to_s.parameterize}/#{id}"
  else
    "#{self.class}/#{id}"
  end
end