Class: LcpRuby::DataSource::ApiErrorPlaceholder
- Inherits:
-
Object
- Object
- LcpRuby::DataSource::ApiErrorPlaceholder
show all
- Defined in:
- lib/lcp_ruby/data_source/api_error_placeholder.rb
Overview
Placeholder object returned when an API record cannot be fetched. Responds to common methods so views don’t crash on API failures.
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(id:, model_name: "Record") ⇒ ApiErrorPlaceholder
Returns a new instance of ApiErrorPlaceholder.
8
9
10
11
|
# File 'lib/lcp_ruby/data_source/api_error_placeholder.rb', line 8
def initialize(id:, model_name: "Record")
@id = id
@model_name_str = model_name
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *_args) ⇒ Object
39
40
41
42
43
44
|
# File 'lib/lcp_ruby/data_source/api_error_placeholder.rb', line 39
def method_missing(method_name, *_args)
if Rails.env.local?
Rails.logger.debug("[LcpRuby] ApiErrorPlaceholder##{@id}: #{method_name} called, returning nil")
end
nil
end
|
Instance Attribute Details
#id ⇒ Object
Returns the value of attribute id.
6
7
8
|
# File 'lib/lcp_ruby/data_source/api_error_placeholder.rb', line 6
def id
@id
end
|
#model_name_str ⇒ Object
Returns the value of attribute model_name_str.
6
7
8
|
# File 'lib/lcp_ruby/data_source/api_error_placeholder.rb', line 6
def model_name_str
@model_name_str
end
|
Instance Method Details
#error? ⇒ Boolean
29
30
31
|
# File 'lib/lcp_ruby/data_source/api_error_placeholder.rb', line 29
def error?
true
end
|
#persisted? ⇒ Boolean
25
26
27
|
# File 'lib/lcp_ruby/data_source/api_error_placeholder.rb', line 25
def persisted?
true
end
|
#respond_to_missing?(_method_name, _include_private = false) ⇒ Boolean
33
34
35
|
# File 'lib/lcp_ruby/data_source/api_error_placeholder.rb', line 33
def respond_to_missing?(_method_name, _include_private = false)
true
end
|
#to_label ⇒ Object
13
14
15
|
# File 'lib/lcp_ruby/data_source/api_error_placeholder.rb', line 13
def to_label
"#{@model_name_str} ##{@id} (unavailable)"
end
|
#to_param ⇒ Object
21
22
23
|
# File 'lib/lcp_ruby/data_source/api_error_placeholder.rb', line 21
def to_param
@id.to_s
end
|
#to_s ⇒ Object
17
18
19
|
# File 'lib/lcp_ruby/data_source/api_error_placeholder.rb', line 17
def to_s
to_label
end
|