Module: LogFu::LogGeneral::MongoIdModels::ClassMethods

Defined in:
app/models/log_fu/log_general.rb

Instance Method Summary collapse

Instance Method Details

#define_logged_it_methods(name) ⇒ Object

Usage: In Model:

class SubjectLog

include LogGeneral::MongoIdModels
define_logged_it_methods :subject

end

In Controller: class SubjectsController < ApplicationController

def show
  @subject = Subject.find params[:id]
  SubjectLog.subject_logged_it(request, params)
end

end



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/models/log_fu/log_general.rb', line 34

def define_logged_it_methods name
  singleton_class.class_eval do
    define_method("#{name}_logged_it") do |request, params|
      client_key    = params[:api_key] if !params[:api_key].blank?
      client_id     = params[:client_id] if !params[:client_id].blank?
      resource_type = name.to_s.capitalize
      resource_id   = params[:id] if !params[:id].blank?
      client_id_by_key = Client.find_by_api_key(client_key) if client_key
      channel_id    = params[:channel_id] if !params[:channel_id].blank?
      ip            = request.remote_ip
      uniquely_code = params[:uniquely_code] if !params[:uniquely_code].blank?
      created_at    = Time.now

      create(:resource_type => resource_type, 
      :resource_id   => resource_id,
      :client_id     => (client_id || client_id_by_key),
      :channel_id    => channel_id,
      :ip            => ip,
      :uniquely_code => uniquely_code,
      :status        => 1,
      :created_at    => created_at)
    end
  end
end