Module: Writefully::FlashHelper

Defined in:
app/helpers/writefully/flash_helper.rb

Instance Method Summary collapse

Instance Method Details

#can_flash?Boolean

Returns:

  • (Boolean)


7
8
9
10
# File 'app/helpers/writefully/flash_helper.rb', line 7

def can_flash?
  flash.keys.sort == [:from, :object_id, :object_type, :type] and \
  flash.to_hash.values.compact.count == flash_values_count
end

#flash_colorObject



24
25
26
27
28
29
# File 'app/helpers/writefully/flash_helper.rb', line 24

def flash_color
  { success: 'alert-success',
    error:   'alert-danger',
    notice:  'alert-info',
    warn:    'alert-warning' }[flash[:type]]
end

#flash_objectObject



16
17
18
# File 'app/helpers/writefully/flash_helper.rb', line 16

def flash_object
  flash[:object_type].classify.constantize.where(id: flash[:object_id]).first
end

#flash_pathObject



20
21
22
# File 'app/helpers/writefully/flash_helper.rb', line 20

def flash_path
  File.join((flash[:namespace] || nil), controller_name, 'flash', flash[:from].to_s, flash[:type].to_s)
end

#flash_values_countObject



12
13
14
# File 'app/helpers/writefully/flash_helper.rb', line 12

def flash_values_count
  action_name == "create" ? 3 : flash.keys.count
end

#render_flashObject



3
4
5
# File 'app/helpers/writefully/flash_helper.rb', line 3

def render_flash
  render 'flash' if can_flash?
end