Class: Log::Message

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/log/message.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.valid_levelsObject



9
10
11
# File 'app/models/log/message.rb', line 9

def self.valid_levels
  [:info, :warning, :error]
end

Instance Method Details

#_get_artifactObject

Store the old artifact and artifact= functions for later usage



22
# File 'app/models/log/message.rb', line 22

alias_method :_get_artifact, :artifact

#_set_artifactObject



23
# File 'app/models/log/message.rb', line 23

alias_method :_set_artifact, :artifact=

#artifactObject

Returns either the model, or the object



26
27
28
# File 'app/models/log/message.rb', line 26

def artifact
  _get_artifact.nil? ? artifact_type : _get_artifact
end

#artifact=(val) ⇒ Object

Assignment overriden to allow the model to be used as well



31
32
33
34
35
36
37
# File 'app/models/log/message.rb', line 31

def artifact= val
  if val.is_a? Class
    self[:artifact_type] = val.model_name
  else
    _set_artifact val
  end
end

#artifact_typeObject

Finds the class of object which we’re dealing with



40
41
42
# File 'app/models/log/message.rb', line 40

def artifact_type
  self[:artifact_type].nil? ? nil : self[:artifact_type].constantize
end

#level=(level) ⇒ Object



44
45
46
# File 'app/models/log/message.rb', line 44

def level= level
  super level.to_sym
end

#valid_levelsObject



13
14
15
16
17
18
19
# File 'app/models/log/message.rb', line 13

def valid_levels
  if artifact_type
    artifact_type.valid_log_levels || self.class.valid_levels
  else
    self.class.valid_levels
  end
end