Module: ImpressionistController::InstanceMethods

Defined in:
app/controllers/impressionist_controller.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



11
12
13
# File 'app/controllers/impressionist_controller.rb', line 11

def self.included(base)
  base.before_filter :impressionist_app_filter
end

Instance Method Details

#impressionist(obj, message = nil) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/impressionist_controller.rb', line 15

def impressionist(obj,message=nil)
  unless bypass
    if obj.respond_to?("impressionable?")
      obj.impressions.create(:message=> message,
                             :request_hash=> @impressionist_hash,
                             :session_hash=> request.session_options[:id],
                             :ip_address=> request.remote_ip,
                             :user_id=> user_id,
                             :controller_name=>controller_name,
                             :action_name=> action_name,
                             :referrer=>request.referer)
    else
      raise "#{obj.class.to_s} is not impressionable!"
    end
  end
end

#impressionist_app_filterObject



32
33
34
# File 'app/controllers/impressionist_controller.rb', line 32

def impressionist_app_filter
  @impressionist_hash = Digest::SHA2.hexdigest(Time.now.to_f.to_s+rand(10000).to_s)
end

#impressionist_subapp_filter(actions = nil) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/impressionist_controller.rb', line 36

def impressionist_subapp_filter(actions=nil)
  unless bypass
    actions.collect!{|a|a.to_s} unless actions.blank?
    if actions.blank? or actions.include?(action_name)
      Impression.create(:controller_name=> controller_name,
                        :action_name=> action_name,
                        :user_id=> user_id,
                        :request_hash=> @impressionist_hash,
                        :session_hash=> request.session_options[:id],
                        :ip_address=> request.remote_ip,
                        :impressionable_type=> controller_name.singularize.camelize,
                        :impressionable_id=> params[:id],
                        :referrer=>request.referer)
    end
  end
end