Class: Ominous::Warning

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/ominous/warning.rb

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(symbol, *args, &block) ⇒ Object (private)



47
48
49
50
51
52
53
# File 'app/models/ominous/warning.rb', line 47

def method_missing(symbol, *args, &block)
  if acts_as_list_method?(symbol)
    pass_method_to_warning_closer(symbol, args.first)
  else
    super
  end
end

Class Method Details

.after_action_tasksObject

Called after each controller action.



38
39
40
# File 'app/models/ominous/warning.rb', line 38

def self.after_action_tasks
  clear_requests # So that warnings called while processing one action are not carried over to the next where they may not be relevant
end

.clear_requestsObject



33
34
35
# File 'app/models/ominous/warning.rb', line 33

def self.clear_requests
  @requests = []
end

.requestsObject



29
30
31
# File 'app/models/ominous/warning.rb', line 29

def self.requests
  @requests ||= []
end

.trigger(name) ⇒ Object



22
23
24
25
26
27
# File 'app/models/ominous/warning.rb', line 22

def self.trigger(name)
  unless exists?(:name => name)
    raise "Attempt to trigger warning failed: #{name} not recognised"
  end
  requests << name.to_sym
end

Instance Method Details

#titleObject



42
43
44
# File 'app/models/ominous/warning.rb', line 42

def title
  (super.blank? and name?) ? name.humanize : super
end