Module: GritterNotices::ActiveRecord::InstanceMethods

Defined in:
lib/gritter_notices/active_record.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object

notice_success notice_error notice_warning notice_progress notice_notice - default. An alias for ‘notice`



41
42
43
44
45
46
47
48
49
50
# File 'lib/gritter_notices/active_record.rb', line 41

def method_missing(method_name, *args, &block)
  if level = ValidMethods[method_name.to_s] or level = ValidMethods["gritter_#{method_name}"]
    options = args.extract_options!
    options[:level] = level
    args << options
    gritter_notice *args
  else
    super(method_name, *args, &block)
  end
end

Instance Method Details

#gritter_notice(*args) ⇒ Object Also known as: notice

Examples:

notice :text=>‘asdsad’, :image=>:notice notice ‘message’, :level=>:success



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/gritter_notices/active_record.rb', line 19

def gritter_notice *args
  options = args.extract_options!
  text = args.first || options[:text]
  options = {:scope=>:gritter_notices}.merge options
  if text.is_a? Symbol
    options[:gritter_key] = text
    options[:level] = text unless options[:level]
    text = options[:text] || I18n::translate(text, options)
  end
  options[:level]=:notice unless options[:level]
  gritter_notices.create! :text=>text, :options=>options
end