Skip to content

Commit

Permalink
Added :alert to FLASH_MESSAGE_TYPES. Using define_method instead of h…
Browse files Browse the repository at this point in the history
…ard coding methods names. Using enumerable's any? method for method, flash_message_set?
  • Loading branch information
eddorre committed Apr 4, 2013
1 parent c8126f4 commit bb09705
Showing 1 changed file with 4 additions and 16 deletions.
20 changes: 4 additions & 16 deletions lib/flash-message-conductor/controller_helpers.rb
Original file line number Diff line number Diff line change
@@ -1,25 +1,13 @@
module FlashMessageConductor
FLASH_MESSAGE_TYPES = [ :error, :notice, :message ]
FLASH_MESSAGE_TYPES = [ :alert, :error, :notice, :message ]

module ControllerHelpers
def add_error(msg)
flash[:error] = msg
end

def add_notice(msg)
flash[:notice] = msg
end

def add_message(msg)
flash[:message] = msg
FLASH_MESSAGE_TYPES.each do |message_type|
define_method("add_#{message_type.to_s}") { |message| flash[message_type] = message}
end

def flash_message_set?
flash_set = false
FLASH_MESSAGE_TYPES.each do |key|
flash_set = true unless flash[key].blank?
end
return flash_set
FLASH_MESSAGE_TYPES.any? { |key| flash[key].present? }
end
end
end

0 comments on commit bb09705

Please sign in to comment.