Module: Ubiquitously::Loggable::Post::ClassMethods

Defined in:
lib/ubiquitously/models/service/post/loggable.rb

Instance Method Summary collapse

Instance Method Details

#loggableObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/ubiquitously/models/service/post/loggable.rb', line 15

def loggable
  before_create do
    unless valid?
      logger.info "[invalid] #{errors.full_messages}"
      return false
    end
    authorize
    return false unless new_record?
    logger.info "[create:before] #{tokenize.inspect}"
  end
  
  after_create do
    logger.info "[create:after] #{tokenize.inspect}"
  end
  
  before_update do
    unless valid?
      logger.info "[invalid] #{errors.full_messages}"
      return false
    end
    authorize
    logger.info "[update:before] #{tokenize.inspect}"
  end
  
  after_update do
    logger.info "[update:after] #{tokenize.inspect}"
  end
end

#loggerObject



11
12
13
# File 'lib/ubiquitously/models/service/post/loggable.rb', line 11

def logger
  Ubiquitously.logger
end

#serviceObject



44
45
46
# File 'lib/ubiquitously/models/service/post/loggable.rb', line 44

def service
  to_s.split("::")[1].underscore.gsub(/\s+/, "_").downcase
end