class StandardFile::AbstractSyncManager

Attributes

sync_fields[RW]

Public Class Methods

new(user) click to toggle source
# File lib/standard_file/abstract/sync_manager.rb, line 6
def initialize(user)
  @user = user
  raise "User must be set" unless @user
end

Public Instance Methods

destroy_items(uuids) click to toggle source
# File lib/standard_file/abstract/sync_manager.rb, line 19
def destroy_items(uuids)
  items = @user.items.where(uuid: uuids)
  items.destroy_all
end
set_sync_fields(val) click to toggle source
# File lib/standard_file/abstract/sync_manager.rb, line 11
def set_sync_fields(val)
  @sync_fields = val
end

Private Instance Methods

datetime_from_sync_token(sync_token) click to toggle source
# File lib/standard_file/abstract/sync_manager.rb, line 31
def datetime_from_sync_token(sync_token)
  decoded = Base64.decode64(sync_token)
  parts = decoded.rpartition(":")
  timestamp_string = parts.last
  version = parts.first
  if version == "1"
    date = DateTime.strptime(timestamp_string,'%s')
  elsif version == "2"
    date = Time.at(timestamp_string.to_f).to_datetime.utc
  end

  return date
end
item_params() click to toggle source
# File lib/standard_file/abstract/sync_manager.rb, line 52
def item_params
  params.permit(*permitted_params)
end
permitted_params() click to toggle source
# File lib/standard_file/abstract/sync_manager.rb, line 56
def permitted_params
  sync_fields
end
set_deleted(item) click to toggle source
# File lib/standard_file/abstract/sync_manager.rb, line 45
def set_deleted(item)
  item.deleted = true
  item.content = nil if item.has_attribute?(:content)
  item.enc_item_key = nil if item.has_attribute?(:enc_item_key)
  item.auth_hash = nil if item.has_attribute?(:auth_hash)
end
sync_token_from_datetime(datetime) click to toggle source
# File lib/standard_file/abstract/sync_manager.rb, line 26
def sync_token_from_datetime(datetime)
  version = 2
  Base64.encode64("#{version}:" + "#{datetime.to_f}")
end