Module: Mache::Helpers::Rails::Flash

Defined in:
lib/mache/helpers/rails/flash.rb

Overview

The Flash module can be included into page object classes that support flash behaviour.

rubocop:disable Naming/PredicateName

Defined Under Namespace

Modules: ClassMethods

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



9
10
11
# File 'lib/mache/helpers/rails/flash.rb', line 9

def self.included(base)
  base.extend(ClassMethods)
end

Instance Method Details

#has_alert_message?(text) ⇒ Boolean

Tests whether the page has an alert message.

Parameters:

  • text (Regexp, String)

    a value to match

Returns:

  • (Boolean)

    ‘true` if the page has a matching message, `false` otherwise



50
51
52
# File 'lib/mache/helpers/rails/flash.rb', line 50

def has_alert_message?(text)
  has_message?(:alert, text)
end

#has_error_message?(text) ⇒ Boolean

Tests whether the page has an error message.

Parameters:

  • text (Regexp, String)

    a value to match

Returns:

  • (Boolean)

    ‘true` if the page has a matching message, `false` otherwise



58
59
60
# File 'lib/mache/helpers/rails/flash.rb', line 58

def has_error_message?(text)
  has_message?(:error, text)
end

#has_message?(type, text) ⇒ Boolean

Tests whether the page has a flash message.

Parameters:

  • type (String, Symbol)

    a flash message type

  • text (Regexp, String)

    a value to match

Returns:

  • (Boolean)

    ‘true` if the page has a matching message, `false` otherwise



24
25
26
27
28
# File 'lib/mache/helpers/rails/flash.rb', line 24

def has_message?(type, text)
  css_class = flash[:class] || ''
  regexp = text.is_a?(String) ? /\A#{Regexp.escape(text)}\Z/ : text
  css_class.include?(type.to_s) && flash.text.strip =~ regexp
end

#has_notice_message?(text) ⇒ Boolean

Tests whether the page has a notice message.

Parameters:

  • text (Regexp, String)

    a value to match

Returns:

  • (Boolean)

    ‘true` if the page has a matching message, `false` otherwise



42
43
44
# File 'lib/mache/helpers/rails/flash.rb', line 42

def has_notice_message?(text)
  has_message?(:notice, text)
end

#has_success_message?(text) ⇒ Boolean

Tests whether the page has a success message.

Parameters:

  • text (Regexp, String)

    a value to match

Returns:

  • (Boolean)

    ‘true` if the page has a matching message, `false` otherwise



34
35
36
# File 'lib/mache/helpers/rails/flash.rb', line 34

def has_success_message?(text)
  has_message?(:success, text)
end