Class: LcpRuby::DataSource::ResilientWrapper
- Defined in:
- lib/lcp_ruby/data_source/resilient_wrapper.rb
Overview
Decorator that catches connection errors and returns graceful fallbacks instead of raising. Used as the outermost wrapper in the adapter chain.
Instance Attribute Summary collapse
-
#inner ⇒ Object
readonly
Returns the value of attribute inner.
-
#model_name ⇒ Object
readonly
Returns the value of attribute model_name.
Instance Method Summary collapse
- #count(params = {}) ⇒ Object
- #find(id) ⇒ Object
- #find_many(ids) ⇒ Object
-
#initialize(inner, model_name:) ⇒ ResilientWrapper
constructor
A new instance of ResilientWrapper.
- #search(params = {}, sort: nil, page: 1, per: 25) ⇒ Object
- #select_options(search: nil, filter: {}, sort: nil, label_method: "to_label", limit: 200) ⇒ Object
- #supported_operators ⇒ Object
- #writable? ⇒ Boolean
Methods inherited from Base
Constructor Details
#initialize(inner, model_name:) ⇒ ResilientWrapper
Returns a new instance of ResilientWrapper.
8 9 10 11 |
# File 'lib/lcp_ruby/data_source/resilient_wrapper.rb', line 8 def initialize(inner, model_name:) @inner = inner @model_name = model_name end |
Instance Attribute Details
#inner ⇒ Object (readonly)
Returns the value of attribute inner.
6 7 8 |
# File 'lib/lcp_ruby/data_source/resilient_wrapper.rb', line 6 def inner @inner end |
#model_name ⇒ Object (readonly)
Returns the value of attribute model_name.
6 7 8 |
# File 'lib/lcp_ruby/data_source/resilient_wrapper.rb', line 6 def model_name @model_name end |
Instance Method Details
#count(params = {}) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/lcp_ruby/data_source/resilient_wrapper.rb', line 38 def count(params = {}) @inner.count(params) rescue ConnectionError => e log_error("count", params.inspect, e) 0 end |
#find(id) ⇒ Object
13 14 15 16 17 18 |
# File 'lib/lcp_ruby/data_source/resilient_wrapper.rb', line 13 def find(id) @inner.find(id) rescue ConnectionError => e log_error("find", id, e) ApiErrorPlaceholder.new(id: id, model_name: @model_name) end |
#find_many(ids) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/lcp_ruby/data_source/resilient_wrapper.rb', line 20 def find_many(ids) @inner.find_many(ids) rescue ConnectionError => e log_error("find_many", ids.inspect, e) ids.map { |id| ApiErrorPlaceholder.new(id: id, model_name: @model_name) } end |
#search(params = {}, sort: nil, page: 1, per: 25) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/lcp_ruby/data_source/resilient_wrapper.rb', line 27 def search(params = {}, sort: nil, page: 1, per: 25) @inner.search(params, sort: sort, page: page, per: per) rescue ConnectionError => e log_error("search", params.inspect, e) SearchResult.new( records: [], total_count: 0, current_page: page, per_page: per, error: true, message: e. ) end |
#select_options(search: nil, filter: {}, sort: nil, label_method: "to_label", limit: 200) ⇒ Object
45 46 47 48 49 50 |
# File 'lib/lcp_ruby/data_source/resilient_wrapper.rb', line 45 def (search: nil, filter: {}, sort: nil, label_method: "to_label", limit: 200) @inner.(search: search, filter: filter, sort: sort, label_method: label_method, limit: limit) rescue ConnectionError => e log_error("select_options", search.inspect, e) [] end |
#supported_operators ⇒ Object
56 57 58 |
# File 'lib/lcp_ruby/data_source/resilient_wrapper.rb', line 56 def supported_operators @inner.supported_operators end |
#writable? ⇒ Boolean
52 53 54 |
# File 'lib/lcp_ruby/data_source/resilient_wrapper.rb', line 52 def writable? @inner.writable? end |