Class: VAProfileRedis::VeteranStatus

Inherits:
Common::RedisStore show all
Includes:
Common::CacheAside
Defined in:
app/models/va_profile_redis/veteran_status.rb

Constant Summary

Constants inherited from Common::RedisStore

Common::RedisStore::REQ_CLASS_INSTANCE_VARS

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Common::CacheAside

#cache, #cached?, #do_cached_with, #set_attributes

Methods inherited from Common::RedisStore

create, delete, #destroy, #destroyed?, exists?, #expire, find, find_or_build, #initialize, #initialize_dup, keys, #persisted?, pop, redis_key, redis_store, redis_ttl, #save, #save!, #ttl, #update, #update!

Constructor Details

This class inherits a constructor from Common::RedisStore

Instance Attribute Details

#userObject

Returns the value of attribute user.



14
15
16
# File 'app/models/va_profile_redis/veteran_status.rb', line 14

def user
  @user
end

Class Method Details

.for_user(user) ⇒ Object



16
17
18
19
20
21
22
# File 'app/models/va_profile_redis/veteran_status.rb', line 16

def self.for_user(user)
  veteran_status      = new
  veteran_status.user = user
  veteran_status.populate_from_redis

  veteran_status
end

Instance Method Details

#military_person?Boolean

Returns boolean for user being/not being considered a military person, by VA Profile, based on their Title 38 Status Code.

Returns:

  • (Boolean)


39
40
41
# File 'app/models/va_profile_redis/veteran_status.rb', line 39

def military_person?
  title38_status == 'V3' || title38_status == 'V6'
end

#populate_from_redisObject



53
54
55
# File 'app/models/va_profile_redis/veteran_status.rb', line 53

def populate_from_redis
  response_from_redis_or_service
end

#responseObject



49
50
51
# File 'app/models/va_profile_redis/veteran_status.rb', line 49

def response
  @response ||= response_from_redis_or_service
end

#response_from_redis_or_serviceObject (private)



65
66
67
68
69
70
71
72
73
# File 'app/models/va_profile_redis/veteran_status.rb', line 65

def response_from_redis_or_service
  unless VAProfile::Configuration::SETTINGS.veteran_status.cache_enabled
    return veteran_status_service.get_veteran_status
  end

  do_cached_with(key: @user.uuid) do
    veteran_status_service.get_veteran_status
  end
end

#statusObject



43
44
45
46
47
# File 'app/models/va_profile_redis/veteran_status.rb', line 43

def status
  return VAProfile::Response::RESPONSE_STATUS[:not_authorized] unless @user.loa3?

  response.status
end

#title38_statusObject



28
29
30
31
32
# File 'app/models/va_profile_redis/veteran_status.rb', line 28

def title38_status
  return unless @user.loa3?

  value_for('title38_status_code')
end

#value_for(key) ⇒ Object (private)



59
60
61
62
63
# File 'app/models/va_profile_redis/veteran_status.rb', line 59

def value_for(key)
  value = response&.title38_status_code&.send(key)

  value.presence
end

#veteran?Boolean

Returns:

  • (Boolean)


24
25
26
# File 'app/models/va_profile_redis/veteran_status.rb', line 24

def veteran?
  title38_status == 'V1'
end

#veteran_status_serviceObject (private)



75
76
77
# File 'app/models/va_profile_redis/veteran_status.rb', line 75

def veteran_status_service
  @service ||= VAProfile::VeteranStatus::Service.new(@user)
end