lib/avo/base_action.rb in avo-2.5.2.pre.2 vs lib/avo/base_action.rb in avo-2.5.2.pre.3

- old
+ new

@@ -59,12 +59,11 @@ self.class.message ||= I18n.t("avo.are_you_sure_you_want_to_run_this_option") self.class.confirm_button_label ||= I18n.t("avo.run") self.class.cancel_button_label ||= I18n.t("avo.cancel") @response ||= {} - @response[:message_type] ||= :notice - @response[:message] ||= I18n.t("avo.action_ran_successfully") + @response[:messages] = [] end def context self.class.context end @@ -129,23 +128,33 @@ def param_id self.class.to_s.demodulize.underscore.tr "/", "_" end def succeed(text) - response[:message_type] = :notice - response[:message] = text + add_message text, :success self end def fail(text) - response[:message_type] = :alert - response[:message] = text + add_message text, :error self end + def inform(text) + add_message text, :info + + self + end + + def warn(text) + add_message text, :warning + + self + end + def redirect_to(path = nil, &block) response[:type] = :redirect response[:path] = if block.present? block else @@ -165,8 +174,17 @@ response[:type] = :download response[:path] = path response[:filename] = filename self + end + + private + + def add_message(body, type = :info) + response[:messages] << { + type: type, + body: body + } end end end