Class: LightServiceExt::ApplicationContext
- Inherits:
-
LightService::Context
- Object
- LightService::Context
- LightServiceExt::ApplicationContext
show all
- Defined in:
- lib/light-service-ext/application_context.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *arguments, &block) ⇒ Object
137
138
139
140
141
|
# File 'lib/light-service-ext/application_context.rb', line 137
def method_missing(method_name, *arguments, &block)
return self[method_name] if key?(method_name)
super
end
|
Instance Attribute Details
#error_info ⇒ Object
Returns the value of attribute error_info.
5
6
7
|
# File 'lib/light-service-ext/application_context.rb', line 5
def error_info
@error_info
end
|
Class Method Details
.make_with_defaults(input = {}, overrides = {}) ⇒ Object
8
9
10
11
12
13
|
# File 'lib/light-service-ext/application_context.rb', line 8
def make_with_defaults(input = {}, overrides = {})
defaults = default_attrs
allowed_override_keys = defaults.keys.excluding(:input)
allowed_overrides = overrides.slice(*allowed_override_keys)
make({ input: input.symbolize_keys }.merge(defaults, allowed_overrides))
end
|
Instance Method Details
#action_name ⇒ Object
106
107
108
109
110
|
# File 'lib/light-service-ext/application_context.rb', line 106
def action_name
return nil if invoked_action.blank?
invoked_action.name.split('::').last
end
|
#add_current_api_response(api_response) ⇒ Object
53
54
55
|
# File 'lib/light-service-ext/application_context.rb', line 53
def add_current_api_response(api_response)
add_value_to_ctx(:current_api_response, api_response)
end
|
#add_errors(**errors) ⇒ Object
38
39
40
|
# File 'lib/light-service-ext/application_context.rb', line 38
def add_errors(**errors)
add_attrs_to_ctx(:errors, **errors)
end
|
#add_errors!(**errors) ⇒ Object
42
43
44
45
46
47
|
# File 'lib/light-service-ext/application_context.rb', line 42
def add_errors!(**errors)
return if errors.blank?
add_errors(**errors)
fail_and_return!
end
|
#add_internal_only(**attrs) ⇒ Object
63
64
65
|
# File 'lib/light-service-ext/application_context.rb', line 63
def add_internal_only(**attrs)
add_attrs_to_ctx(:internal_only, **attrs)
end
|
#add_invoked_action(invoked_action) ⇒ Object
92
93
94
|
# File 'lib/light-service-ext/application_context.rb', line 92
def add_invoked_action(invoked_action)
add_value_to_ctx(:invoked_action, invoked_action)
end
|
#add_last_failed_context(failed_context) ⇒ Object
57
58
59
60
61
|
# File 'lib/light-service-ext/application_context.rb', line 57
def add_last_failed_context(failed_context)
return if failed_context.nil? || failed_context.try(:success?)
add_value_to_ctx(:last_failed_context, failed_context)
end
|
67
68
69
|
# File 'lib/light-service-ext/application_context.rb', line 67
def add_meta(**attrs)
add_attrs_to_ctx(:meta, **attrs)
end
|
#add_params(**params) ⇒ Object
34
35
36
|
# File 'lib/light-service-ext/application_context.rb', line 34
def add_params(**params)
add_attrs_to_ctx(:params, **params)
end
|
#add_status(status) ⇒ Object
49
50
51
|
# File 'lib/light-service-ext/application_context.rb', line 49
def add_status(status)
add_value_to_ctx(:status, status)
end
|
#add_to_api_responses(*api_response) ⇒ Object
84
85
86
|
# File 'lib/light-service-ext/application_context.rb', line 84
def add_to_api_responses(*api_response)
add_collection_to_ctx(:api_responses, *api_response)
end
|
#add_to_successful_actions(*action_name) ⇒ Object
88
89
90
|
# File 'lib/light-service-ext/application_context.rb', line 88
def add_to_successful_actions(*action_name)
add_collection_to_ctx(:successful_actions, *action_name)
end
|
#allow_raise_on_failure? ⇒ Boolean
96
97
98
|
# File 'lib/light-service-ext/application_context.rb', line 96
def allow_raise_on_failure?
!!self[:allow_raise_on_failure]
end
|
112
113
114
|
# File 'lib/light-service-ext/application_context.rb', line 112
def formatted_errors
JSON.pretty_generate(errors.presence || {})
end
|
#organizer_name ⇒ Object
100
101
102
103
104
|
# File 'lib/light-service-ext/application_context.rb', line 100
def organizer_name
return nil if organized_by.nil?
organized_by.name.split('::').last
end
|
#record_raised_error(error) ⇒ Object
72
73
74
75
76
77
78
79
80
81
82
|
# File 'lib/light-service-ext/application_context.rb', line 72
def record_raised_error(error)
@error_info = ErrorInfo.new(error)
error_type = @error_info.type
error_message = @error_info.message
add_internal_only(error_info: { organizer: organizer_name,
action_name: action_name,
error: { type: error_type, message: error_message, backtrace: @error_info.clean_backtrace } })
add_errors(base: error_message)
LightServiceExt.config.on_raised_error.call(self, error)
end
|