Class: StorageService

Inherits:
Object
  • Object
show all
Defined in:
lib/wingify/services/storage_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeStorageService

Returns a new instance of StorageService.



26
27
28
# File 'lib/wingify/services/storage_service.rb', line 26

def initialize
  @storage_data = {}
end

Instance Attribute Details

#storage_dataObject

Returns the value of attribute storage_data.



24
25
26
# File 'lib/wingify/services/storage_service.rb', line 24

def storage_data
  @storage_data
end

Instance Method Details

#get_data_from_storage(feature_key, context) ⇒ Hash

Retrieves data from storage based on the feature key and user ID.

Parameters:

  • feature_key (String)

    The key to identify the feature data.

  • context (ContextModel)

    The user context containing an ID.

Returns:

  • (Hash)

    The data retrieved or a storage status enum.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/wingify/services/storage_service.rb', line 34

def get_data_from_storage(feature_key, context)
  storage_instance = Storage.instance.get_connector

  # Check if the storage instance is available
  return StorageEnum::STORAGE_UNDEFINED if DataTypeUtil.is_null(storage_instance) || DataTypeUtil.is_undefined(storage_instance)

  begin
    data = storage_instance.get(feature_key, context.get_id)
    return data.nil? ? StorageEnum::NO_DATA_FOUND : data
  rescue StandardError => e
    LoggerService.log(LogLevelEnum::ERROR, "ERROR_READING_DATA_FROM_STORAGE", { err: e.message, an: ApiEnum::GET_FLAG, sId: context.get_session_id, uuid: context.get_uuid})
    return StorageEnum::NO_DATA_FOUND
  end
end

#set_data_in_storage(data, context) ⇒ Boolean

Stores data in the storage.

Parameters:

  • data (Hash)

    The data to be stored.

Returns:

  • (Boolean)

    True if data is successfully stored, otherwise false.



52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/wingify/services/storage_service.rb', line 52

def set_data_in_storage(data, context)
  storage_instance = Storage.instance.get_connector

  # Check if the storage instance is available
  return false if storage_instance.nil?

  begin
    storage_instance.set(data)
    return true
  rescue StandardError => e
    LoggerService.log(LogLevelEnum::ERROR, "ERROR_STORING_DATA_IN_STORAGE", { err: e.message, an: ApiEnum::GET_FLAG, sId: context.get_session_id, uuid: context.get_uuid})
    return false
  end
end