Class: MHVAccountTypeService
- Inherits:
-
Object
- Object
- MHVAccountTypeService
- Defined in:
- app/services/mhv_account_type_service.rb
Overview
Models logic pertaining to the verification and logging of MHV accounts
Constant Summary collapse
- ELIGIBLE_DATA_CLASS_COUNT_TO_ACCOUNT_LEVEL =
{ 32 => 'Premium', 18 => 'Advanced', 16 => 'Basic' }.freeze
- DEFAULT_ACCOUNT_LEVEL =
'Unknown'
- MHV_DOWN_MESSAGE =
'MHVAccountTypeService: could not fetch eligible data classes'
- UNEXPECTED_DATA_CLASS_COUNT_MESSAGE =
'MHVAccountTypeService: eligible data class mapping inconsistency'
Instance Attribute Summary collapse
-
#eligible_data_classes ⇒ Object
readonly
Returns the value of attribute eligible_data_classes.
-
#user ⇒ Object
readonly
Returns the value of attribute user.
Instance Method Summary collapse
-
#account_type_known? ⇒ Boolean
Is the user MHV account type known?.
-
#initialize(user) ⇒ MHVAccountTypeService
constructor
A new instance of MHVAccountTypeService.
-
#mhv_account? ⇒ Boolean
Does the user have an MHV correlation ID?.
-
#mhv_account_type ⇒ NilClass, String
Retrieve the MHV account type.
Constructor Details
#initialize(user) ⇒ MHVAccountTypeService
Returns a new instance of MHVAccountTypeService.
20 21 22 23 |
# File 'app/services/mhv_account_type_service.rb', line 20 def initialize(user) @user = user @eligible_data_classes = fetch_eligible_data_classes if mhv_account? end |
Instance Attribute Details
#eligible_data_classes ⇒ Object (readonly)
Returns the value of attribute eligible_data_classes.
25 26 27 |
# File 'app/services/mhv_account_type_service.rb', line 25 def eligible_data_classes @eligible_data_classes end |
#user ⇒ Object (readonly)
Returns the value of attribute user.
25 26 27 |
# File 'app/services/mhv_account_type_service.rb', line 25 def user @user end |
Instance Method Details
#account_type_known? ⇒ Boolean
Returns is the user MHV account type known?.
58 59 60 |
# File 'app/services/mhv_account_type_service.rb', line 58 def account_type_known? user.identity.mhv_account_type.present? end |
#mhv_account? ⇒ Boolean
Returns does the user have an MHV correlation ID?.
51 52 53 |
# File 'app/services/mhv_account_type_service.rb', line 51 def mhv_account? user.mhv_correlation_id.present? end |
#mhv_account_type ⇒ NilClass, String
Retrieve the MHV account type
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/services/mhv_account_type_service.rb', line 33 def mhv_account_type return nil unless mhv_account? if account_type_known? user.identity.mhv_account_type elsif eligible_data_classes.nil? 'Error' else ELIGIBLE_DATA_CLASS_COUNT_TO_ACCOUNT_LEVEL.fetch(eligible_data_classes.size) end rescue KeyError log_account_type_heuristic(UNEXPECTED_DATA_CLASS_COUNT_MESSAGE) DEFAULT_ACCOUNT_LEVEL end |