Module: ImpressionistController::InstanceMethods

Defined in:
app/controllers/impressionist_controller.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object


15
16
17
18
19
20
21
# File 'app/controllers/impressionist_controller.rb', line 15

def self.included(base)
  if Rails::VERSION::MAJOR >= 5
    base.before_action :impressionist_app_filter
  else
    base.before_filter :impressionist_app_filter
  end
end

Instance Method Details

#impressionist(obj, message = nil, opts = {}) ⇒ Object


23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/controllers/impressionist_controller.rb', line 23

def impressionist(obj,message=nil,opts={})
  if should_count_impression?(opts)
    if obj.respond_to?("impressionable?")
      if unique_instance?(obj, opts[:unique])
        obj.impressions.create(associative_create_statement({:message => message}))
      end
    else
      # we could create an impression anyway. for classes, too. why not?
      raise "#{obj.class.to_s} is not impressionable!"
    end
  end
end

#impressionist_app_filterObject


36
37
38
# File 'app/controllers/impressionist_controller.rb', line 36

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

#impressionist_subapp_filter(opts = {}) ⇒ Object


40
41
42
43
44
45
46
47
48
# File 'app/controllers/impressionist_controller.rb', line 40

def impressionist_subapp_filter(opts = {})
  if should_count_impression?(opts)
    actions = opts[:actions]
    actions.collect!{|a|a.to_s} unless actions.blank?
    if (actions.blank? || actions.include?(action_name)) && unique?(opts[:unique])
      Impression.create(direct_create_statement)
    end
  end
end