Module: ServiceObjects::Helpers::Messages
- Included in:
- Base, Exceptions, Validations
- Defined in:
- lib/service_objects/helpers/messages.rb
Overview
Note:
A target class should include the module
Features for collecting service messages
Instance Method Summary collapse
-
#add_message(options) ⇒ Array<ServiceObjects::Message>
Translates the text and adds a new message to the list of #messages.
-
#messages ⇒ Array<ServiceObjects::Message>
A list of object messages.
-
#translate(text, options = {}) ⇒ String
Translates the text in the current scope with given options.
Instance Method Details
#add_message(options) ⇒ Array<ServiceObjects::Message>
Translates the text and adds a new message to the list of #messages
74 75 76 77 78 79 80 |
# File 'lib/service_objects/helpers/messages.rb', line 74 def () params = Utils::NormalHash.from() type = params.delete :type priority = params.delete :priority text = translate params.delete(:text), params << Message.new(text: text, type: type, priority: priority) end |
#messages ⇒ Array<ServiceObjects::Message>
A list of object messages
47 48 49 |
# File 'lib/service_objects/helpers/messages.rb', line 47 def ||= [] end |
#translate(text, options = {}) ⇒ String
Translates the text in the current scope with given options
The method uses I18n.t library method.
39 40 41 42 |
# File 'lib/service_objects/helpers/messages.rb', line 39 def translate(text, = {}) return text.to_s unless text.is_a? Symbol I18n.t text, Utils::NormalHash.from().merge(scope: __scope__) end |