Class: EtFakeCcd::DataStoreService::InMemoryAdapter
- Inherits:
-
Object
- Object
- EtFakeCcd::DataStoreService::InMemoryAdapter
- Defined in:
- lib/et_fake_ccd/data_store_service.rb
Instance Method Summary collapse
- #fetch_all(jid:, ctid:, filters: {}, page: 1, sort_direction: 'asc', page_size: 25) ⇒ Object
- #fetch_by_id(id, jid:, ctid:) ⇒ Object
-
#initialize ⇒ InMemoryAdapter
constructor
A new instance of InMemoryAdapter.
- #store(json, jid:, ctid:) ⇒ Object
- #update_case_data(json, jid:, ctid:, cid:) ⇒ Object
Constructor Details
#initialize ⇒ InMemoryAdapter
Returns a new instance of InMemoryAdapter.
42 43 44 45 |
# File 'lib/et_fake_ccd/data_store_service.rb', line 42 def initialize self.data = {} self.id = 10000000000 end |
Instance Method Details
#fetch_all(jid:, ctid:, filters: {}, page: 1, sort_direction: 'asc', page_size: 25) ⇒ Object
65 66 67 68 69 70 71 72 |
# File 'lib/et_fake_ccd/data_store_service.rb', line 65 def fetch_all(jid:, ctid:, filters: {}, page: 1, sort_direction: 'asc', page_size: 25) hash = data.dig(jid, ctid) return {} if hash.nil? || hash.empty? filtered_list = filter(hash, filters: filters) sorted_list = sort(filtered_list, sort_direction: sort_direction) paginate(sorted_list, page_size: page_size, page: page) end |
#fetch_by_id(id, jid:, ctid:) ⇒ Object
61 62 63 |
# File 'lib/et_fake_ccd/data_store_service.rb', line 61 def fetch_by_id(id, jid:, ctid:) data.dig(jid, ctid, id.to_s) end |
#store(json, jid:, ctid:) ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/et_fake_ccd/data_store_service.rb', line 47 def store(json, jid:, ctid:) self.id = id + 1 if ctid =~ /Multiples/ primary_case_ref = json.dig('data', 'caseIdCollection').first.dig('value', 'ethos_CaseReference') json['data']['multipleReference'] = next_case_reference(primary_case_ref[0,2]) if primary_case_ref && (json.dig('data', 'multipleReference').nil? || json.dig('data', 'multipleReference') == '') else json['data']['ethosCaseReference'] = next_case_reference(json.dig('data', 'feeGroupReference')[0,2].to_i) if json.dig('data', 'ethosCaseReference').nil? || json.dig('data', 'ethosCaseReference') == '' end data[jid] ||= {} data[jid][ctid] ||= {} data[jid][ctid][id.to_s] = json id.to_s end |
#update_case_data(json, jid:, ctid:, cid:) ⇒ Object
74 75 76 77 |
# File 'lib/et_fake_ccd/data_store_service.rb', line 74 def update_case_data(json, jid:, ctid:, cid:) existing = fetch_by_id(cid.to_s, jid: jid, ctid: ctid) existing['data'].merge!(json['data']) end |