# File app/components/app_flash_message_component.rb, line 51 def primary_message_keys @primary_message_keys ||= %i[info success warning] end
class AppFlashMessageComponent
Attributes
Public Class Methods
Source
# File app/components/app_flash_message_component.rb, line 6 def initialize(flash:) flash = flash.to_h.with_indifferent_access @message_key = (recognised_message_keys & flash.keys.map(&:to_sym)).first if flash[@message_key].is_a?(Hash) @title = flash[@message_key][:title] @heading = flash[@message_key][:heading] @heading_link_text = flash[@message_key][:heading_link_text] @heading_link_href = flash[@message_key][:heading_link_href] @body = flash[@message_key][:body].to_s elsif flash[@message_key].is_a?(Array) @heading = flash[@message_key].first @body = flash[@message_key][1..].join(" ") else @heading = flash[@message_key] end end
Public Instance Methods
Source
# File app/components/app_flash_message_component.rb, line 37 def classes "nhsuk-notification-banner--#{type}" end
Source
# File app/components/app_flash_message_component.rb, line 55 def devise_message_keys_hash @devise_message_keys_hash ||= { alert: :warning, notice: :info } end
Source
Source
# File app/components/app_flash_message_component.rb, line 59 def recognised_message_keys @recognised_message_keys ||= primary_message_keys + devise_message_keys_hash.keys end
Source
# File app/components/app_flash_message_component.rb, line 24 def render? @heading.present? || @body.present? end
Source
# File app/components/app_flash_message_component.rb, line 41 def role %i[warning success].include?(type) ? "alert" : "region" end
Source
# File app/components/app_flash_message_component.rb, line 45 def success? = type == :success private delegate :govuk_notification_banner, to: :helpers def primary_message_keys @primary_message_keys ||= %i[info success warning] end def devise_message_keys_hash @devise_message_keys_hash ||= { alert: :warning, notice: :info } end def recognised_message_keys @recognised_message_keys ||= primary_message_keys + devise_message_keys_hash.keys end end
Source
# File app/components/app_flash_message_component.rb, line 28 def title @title || I18n.t(type, scope: :notification_banner, default: type.to_s.humanize) end
Source
# File app/components/app_flash_message_component.rb, line 33 def type @type ||= devise_message_keys_hash.fetch(@message_key, @message_key) end