lib/hexx/service.rb in hexx-3.1.0 vs lib/hexx/service.rb in hexx-3.2.0
- old
+ new
@@ -30,10 +30,14 @@
# @example
# service = Hexx::Service.new name: name
#
# @param [Hash] options The options to be assigned to the {#params}.
# @return [Hexx::Service] The service object.
+ def initialize(*)
+ super
+ @messages = []
+ end
# @!scope class
# @!visibility private
# @!method allow_params(*params)
# Whitelists {#params} and declares a parameter for corresponding keys.
@@ -214,10 +218,11 @@
return text unless text.is_a? Symbol
scope = %w(activemodel messages models) << self.class.name.underscore
I18n.t text, options.merge(scope: scope)
end
+ # @!attribute messages
# The array of service messages, added by the {#add_message} helper.
#
# @example
# class Test < Hexx::Service
# def run
@@ -230,12 +235,10 @@
# # => "info"
# result.text
# # => "translation not found: en.activemodel.messages.models.test.ok"
#
# @return [Array<Hexx::Service::Message>] The array of message objects.
- def messages
- @messages ||= []
- end
+ attr_accessor :messages
# Adds the translated message to the {#messages} array.
# @example (see Service#messages)
# @param [String] type The type of the message ("error", "info", "success")
# @param [String, Symbol] text The text of the message. The symbol will