impressionist 1.0.1 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +11 -0
- data/.rspec +1 -0
- data/.travis.yml +11 -0
- data/CHANGELOG.rdoc +1 -1
- data/Gemfile +8 -19
- data/README.md +65 -34
- data/Rakefile +10 -82
- data/app/controllers/impressionist_controller.rb +11 -11
- data/app/models/impression.rb +2 -15
- data/app/models/impressionist/bots.rb +3 -3
- data/app/models/impressionist/impressionable.rb +29 -41
- data/impressionist.gemspec +22 -65
- data/lib/generators/active_record/impressionist_generator.rb +21 -0
- data/lib/generators/{impressionist → active_record}/templates/create_impressions_table.rb +1 -9
- data/lib/generators/impressionist_generator.rb +12 -0
- data/lib/generators/mongo_mapper/impressionist_generator.rb +8 -0
- data/lib/generators/templates/impression.rb +5 -0
- data/lib/impressionist.rb +10 -3
- data/lib/impressionist/bots.rb +1 -1
- data/lib/impressionist/engine.rb +11 -3
- data/lib/impressionist/models/active_record/impression.rb +18 -0
- data/lib/impressionist/models/active_record/impressionist/impressionable.rb +12 -0
- data/lib/impressionist/models/mongo_mapper/impression.rb +17 -0
- data/lib/impressionist/models/mongo_mapper/impressionist/impressionable.rb +12 -0
- data/lib/impressionist/version.rb +3 -0
- data/test_app/.gitignore +17 -0
- data/test_app/.rspec +1 -0
- data/test_app/Gemfile +58 -0
- data/test_app/README +256 -0
- data/test_app/README.rdoc +261 -0
- data/test_app/Rakefile +7 -0
- data/test_app/app/assets/images/rails.png +0 -0
- data/test_app/app/assets/javascripts/application.js +15 -0
- data/test_app/app/assets/stylesheets/application.css +13 -0
- data/test_app/app/controllers/application_controller.rb +8 -0
- data/test_app/app/controllers/articles_controller.rb +18 -0
- data/test_app/app/controllers/dummy_controller.rb +6 -0
- data/test_app/app/controllers/posts_controller.rb +23 -0
- data/test_app/app/controllers/widgets_controller.rb +13 -0
- data/test_app/app/helpers/application_helper.rb +2 -0
- data/{lib/impressionist/railties/tasks.rake → test_app/app/mailers/.gitkeep} +0 -0
- data/test_app/app/models/.gitkeep +0 -0
- data/test_app/app/models/article.rb +3 -0
- data/test_app/app/models/dummy.rb +7 -0
- data/test_app/app/models/post.rb +3 -0
- data/test_app/app/models/user.rb +3 -0
- data/test_app/app/models/widget.rb +3 -0
- data/test_app/app/views/articles/index.html.erb +1 -0
- data/test_app/app/views/articles/show.html.erb +1 -0
- data/test_app/app/views/layouts/application.html.erb +14 -0
- data/test_app/app/views/posts/edit.html.erb +0 -0
- data/test_app/app/views/posts/index.html.erb +0 -0
- data/test_app/app/views/posts/show.html.erb +0 -0
- data/test_app/app/views/widgets/index.html.erb +0 -0
- data/test_app/app/views/widgets/new.html.erb +0 -0
- data/test_app/app/views/widgets/show.html.erb +0 -0
- data/test_app/config.ru +4 -0
- data/test_app/config/application.rb +59 -0
- data/test_app/config/boot.rb +6 -0
- data/test_app/config/cucumber.yml +8 -0
- data/test_app/config/database.yml +30 -0
- data/test_app/config/environment.rb +5 -0
- data/test_app/config/environments/development.rb +37 -0
- data/test_app/config/environments/pg_test.rb +35 -0
- data/test_app/config/environments/production.rb +67 -0
- data/test_app/config/environments/test.rb +37 -0
- data/test_app/config/initializers/backtrace_silencers.rb +7 -0
- data/test_app/config/initializers/impression.rb +5 -0
- data/test_app/config/initializers/inflections.rb +15 -0
- data/test_app/config/initializers/mime_types.rb +5 -0
- data/test_app/config/initializers/secret_token.rb +7 -0
- data/test_app/config/initializers/session_store.rb +8 -0
- data/test_app/config/initializers/wrap_parameters.rb +14 -0
- data/test_app/config/locales/en.yml +5 -0
- data/test_app/config/routes.rb +3 -0
- data/test_app/db/migrate/20110201153144_create_articles.rb +13 -0
- data/test_app/db/migrate/20110210205028_create_posts.rb +13 -0
- data/test_app/db/migrate/20111127184039_create_widgets.rb +15 -0
- data/test_app/db/seeds.rb +7 -0
- data/test_app/lib/assets/.gitkeep +0 -0
- data/test_app/lib/tasks/.gitkeep +0 -0
- data/test_app/lib/tasks/cucumber.rake +53 -0
- data/test_app/log/.gitkeep +0 -0
- data/test_app/public/404.html +26 -0
- data/test_app/public/422.html +26 -0
- data/test_app/public/500.html +25 -0
- data/test_app/public/favicon.ico +0 -0
- data/test_app/public/images/rails.png +0 -0
- data/test_app/public/index.html +241 -0
- data/test_app/public/javascripts/application.js +2 -0
- data/test_app/public/javascripts/controls.js +965 -0
- data/test_app/public/javascripts/dragdrop.js +974 -0
- data/test_app/public/javascripts/effects.js +1123 -0
- data/test_app/public/javascripts/prototype.js +6001 -0
- data/test_app/public/javascripts/rails.js +175 -0
- data/test_app/public/robots.txt +5 -0
- data/test_app/public/stylesheets/.gitkeep +0 -0
- data/test_app/script/cucumber +10 -0
- data/test_app/script/rails +6 -0
- data/test_app/spec/controllers/controller_spec.rb +125 -0
- data/test_app/spec/controllers/impressionist_uniqueness_spec.rb +310 -0
- data/test_app/spec/fixtures/articles.yml +3 -0
- data/test_app/spec/fixtures/impressions.yml +43 -0
- data/test_app/spec/fixtures/posts.yml +3 -0
- data/test_app/spec/fixtures/widgets.yml +4 -0
- data/test_app/spec/intializers/initializers_spec.rb +18 -0
- data/test_app/spec/models/counter_caching_spec.rb +30 -0
- data/test_app/spec/models/model_spec.rb +94 -0
- data/test_app/spec/rails_generators/rails_generators_spec.rb +23 -0
- data/test_app/spec/spec_helper.rb +36 -0
- data/upgrade_migrations/version_0_3_0.rb +7 -7
- data/upgrade_migrations/version_0_4_0.rb +2 -2
- metadata +356 -99
- data/VERSION +0 -1
- data/config/routes.rb +0 -2
- data/lib/generators/impressionist/impressionist_generator.rb +0 -20
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.travis.yml
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
before_install: gem install bundler
|
2
|
+
before_script: "cd test_app && bundle install && ./script/rails generate impressionist && bundle exec rake db:migrate && cd .."
|
3
|
+
language: ruby
|
4
|
+
rvm:
|
5
|
+
- 1.8.7
|
6
|
+
- 1.9.2
|
7
|
+
- 1.9.3
|
8
|
+
- jruby-18mode
|
9
|
+
- jruby-19mode
|
10
|
+
- rbx-18mode
|
11
|
+
- rbx-19mode
|
data/CHANGELOG.rdoc
CHANGED
@@ -16,4 +16,4 @@
|
|
16
16
|
* @widget.unique_impression_count now uses request_hash. This was incorrectly stated in the README, since it was using ip_address. The README is correct as a result of the method change.
|
17
17
|
|
18
18
|
== 0.2.4 (2011-02-17)
|
19
|
-
* Fix issue #1 - action_name and controller_name were not being logged for impressionist method inside action
|
19
|
+
* Fix issue #1 - action_name and controller_name were not being logged for impressionist method inside action
|
data/Gemfile
CHANGED
@@ -1,24 +1,13 @@
|
|
1
|
-
source
|
1
|
+
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
|
4
|
-
gem
|
5
|
-
gem
|
6
|
-
gem
|
7
|
-
gem "rcov", ">= 0"
|
3
|
+
platforms :jruby do
|
4
|
+
gem 'activerecord-jdbcsqlite3-adapter'
|
5
|
+
gem 'jdbc-sqlite3'
|
6
|
+
gem 'jruby-openssl'
|
8
7
|
end
|
9
8
|
|
10
|
-
|
11
|
-
gem '
|
12
|
-
gem "rspec"
|
13
|
-
gem "rspec-rails"
|
14
|
-
gem "mongrel", "1.2.0.pre2"
|
15
|
-
gem 'capybara'
|
16
|
-
gem 'database_cleaner'
|
17
|
-
gem 'cucumber-rails'
|
18
|
-
gem 'cucumber'
|
19
|
-
gem 'spork'
|
20
|
-
gem 'launchy'
|
21
|
-
gem 'autotest-notification'
|
22
|
-
gem 'httpclient'
|
9
|
+
platforms :ruby, :mswin, :mingw do
|
10
|
+
gem 'sqlite3'
|
23
11
|
end
|
24
12
|
|
13
|
+
gemspec
|
data/README.md
CHANGED
@@ -1,29 +1,30 @@
|
|
1
1
|
![Impressionist Logo](https://github.com/charlotte-ruby/impressionist/raw/master/logo.png)
|
2
2
|
|
3
|
+
[![Build Status](https://secure.travis-ci.org/charlotte-ruby/impressionist.png?branch=master)](http://travis-ci.org/charlotte-ruby/impressionist)
|
4
|
+
|
3
5
|
impressionist
|
4
6
|
=============
|
5
7
|
|
6
8
|
A lightweight plugin that logs impressions per action or manually per model
|
7
9
|
|
8
|
-
|
9
|
-
------------------------------------------------------------------------------------------------------------------------------
|
10
|
+
--------------------------------------------------------------------------------
|
10
11
|
|
11
12
|
What does this thing do?
|
12
13
|
------------------------
|
13
|
-
Logs an impression... and I use that term loosely. It can log page impressions
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
Logs an impression... and I use that term loosely. It can log page impressions
|
15
|
+
(technically action impressions), but it is not limited to that. You can log
|
16
|
+
impressions multiple times per request. And you can also attach it to a model.
|
17
|
+
The goal of this project is to provide customizable stats that are immediately
|
18
|
+
accessible in your application as opposed to using Google Analytics and pulling
|
19
|
+
data using their API. You can attach custom messages to impressions. No
|
20
|
+
reporting yet.. this thingy just creates the data.
|
17
21
|
|
18
22
|
What about bots?
|
19
23
|
----------------
|
20
|
-
They are ignored. 1200 known bots have been added to the ignore list as of
|
24
|
+
They are ignored. 1200 known bots have been added to the ignore list as of
|
25
|
+
February 1, 2011. Impressionist uses this list:
|
21
26
|
http://www.user-agents.org/allagents.xml
|
22
27
|
|
23
|
-
Which versions of Rails and Ruby is this compatible with?
|
24
|
-
---------------------------------------------------------
|
25
|
-
Rails 3.0.4 and Ruby 1.9.2 (also tested on REE 1.8.7) - Sorry, but you need to upgrade if you are using Rails 2. You know you want to anyways.. all the cool kids are doing it ;-)
|
26
|
-
|
27
28
|
Installation
|
28
29
|
------------
|
29
30
|
Add it to your Gemfile
|
@@ -73,46 +74,70 @@ Usage
|
|
73
74
|
impressionist :actions=>[:show,:index]
|
74
75
|
end
|
75
76
|
|
76
|
-
3. Make your models impressionable. This allows you to attach impressions to
|
77
|
+
3. Make your models impressionable. This allows you to attach impressions to
|
78
|
+
an AR model instance. Impressionist will automatically log the Model name
|
79
|
+
(based on action_name) and the id (based on params[:id]), but in order to
|
80
|
+
get the count of impressions (example: @widget.impression_count), you will
|
81
|
+
need to make your model impressionalble
|
77
82
|
|
78
83
|
class Widget < ActiveRecord::Base
|
79
84
|
is_impressionable
|
80
85
|
end
|
81
86
|
|
82
|
-
4. Log an impression per model instance in your controller. Note that it is
|
87
|
+
4. Log an impression per model instance in your controller. Note that it is
|
88
|
+
not necessary to specify "impressionist" (usage #1) in the top of you
|
89
|
+
controller if you are using this method. If you add "impressionist" to the
|
90
|
+
top of your controller and also use this method in your action, it will
|
91
|
+
result in 2 impressions being logged (but associated with one request_hash)
|
83
92
|
|
84
93
|
def show
|
85
94
|
@widget = Widget.find
|
86
95
|
impressionist(@widget,message:"wtf is a widget?") #message is optional
|
87
96
|
end
|
88
97
|
|
89
|
-
5. Get unique impression count from a model. This groups impressions by
|
98
|
+
5. Get unique impression count from a model. This groups impressions by
|
99
|
+
request_hash, so if you logged multiple impressions per request, it will
|
100
|
+
only count them one time. This unique impression count will not filter out
|
101
|
+
unique users, only unique requests
|
90
102
|
|
91
103
|
@widget.impressionist_count
|
92
104
|
@widget.impressionist_count(:start_date=>"2011-01-01",:end_date=>"2011-01-05")
|
93
105
|
@widget.impressionist_count(:start_date=>"2011-01-01") #specify start date only, end date = now
|
94
106
|
|
95
|
-
6. Get the unique impression count from a model filtered by IP address. This
|
107
|
+
6. Get the unique impression count from a model filtered by IP address. This
|
108
|
+
in turn will give you impressions with unique request_hash, since rows with
|
109
|
+
the same request_hash will have the same IP address.
|
96
110
|
|
97
111
|
@widget.impressionist_count(:filter=>:ip_address)
|
98
112
|
|
99
|
-
7. Get the unique impression count from a model filtered by session hash. Same
|
113
|
+
7. Get the unique impression count from a model filtered by session hash. Same
|
114
|
+
as #6 regarding request hash. This may be more desirable than filtering by
|
115
|
+
IP address depending on your situation, since filtering by IP may ignore
|
116
|
+
visitors that use the same IP. The downside to this filtering is that a
|
117
|
+
user could clear session data in their browser and skew the results.
|
100
118
|
|
101
119
|
@widget.impressionist_count(:filter=>:session_hash)
|
102
120
|
|
103
|
-
8. Get total impression count. This may return more than 1 impression per http
|
121
|
+
8. Get total impression count. This may return more than 1 impression per http
|
122
|
+
request, depending on how you are logging impressions
|
104
123
|
|
105
124
|
@widget.impressionist_count(:filter=>:all)
|
106
125
|
|
107
|
-
Logging impressions for authenticated users happens automatically. If you have
|
126
|
+
Logging impressions for authenticated users happens automatically. If you have
|
127
|
+
a current_user helper or use @current_user in your before_filter to set your
|
128
|
+
authenticated user, current_user.id will be written to the user_id field in the
|
129
|
+
impressions table.
|
108
130
|
|
109
131
|
Adding a counter cache
|
110
132
|
----------------------
|
111
|
-
Impressionist makes it easy to add a `counter_cache` column to your model. The
|
133
|
+
Impressionist makes it easy to add a `counter_cache` column to your model. The
|
134
|
+
most basic configuration looks like:
|
112
135
|
|
113
136
|
is_impressionable :counter_cache => true
|
114
137
|
|
115
|
-
This will automatically increment the `impressions_count` column in the
|
138
|
+
This will automatically increment the `impressions_count` column in the
|
139
|
+
included model. Note: You'll need to add that column to your model. If you'd
|
140
|
+
like specific a different column name, you can:
|
116
141
|
|
117
142
|
is_impressionable :counter_cache => { :column_name => :my_column }
|
118
143
|
|
@@ -120,10 +145,11 @@ If you'd like to include only unique impressions in your count:
|
|
120
145
|
|
121
146
|
is_impressionable :counter_cache => { :column_name => :my_column, :unique => true }
|
122
147
|
|
123
|
-
|
124
148
|
What if I only want to record unique impressions?
|
125
149
|
-------------------------------------------------
|
126
|
-
Maybe you only care about unique impressions and would like to
|
150
|
+
Maybe you only care about unique impressions and would like to avoid
|
151
|
+
unnecessary database records. You can specify conditions for recording
|
152
|
+
impressions in your controller:
|
127
153
|
|
128
154
|
# only record impression if the request has a unique combination of type, id, and session
|
129
155
|
impressionist :unique => [:impressionable_type, :impressionable_id, :session_hash]
|
@@ -138,30 +164,35 @@ Or you can use the `impressionist` method directly:
|
|
138
164
|
|
139
165
|
impressionist(impressionable, "some message", :unique => [:session_hash])
|
140
166
|
|
141
|
-
|
142
167
|
Development Roadmap
|
143
168
|
-------------------
|
144
|
-
* Automatic impression logging in views. For example, log initial view, and
|
145
|
-
|
169
|
+
* Automatic impression logging in views. For example, log initial view, and
|
170
|
+
any partials called from initial view
|
171
|
+
* Customizable black list for user-agents or IP addresses. Impressions will be
|
172
|
+
ignored. Web admin as part of the Engine.
|
146
173
|
* Reporting engine
|
147
174
|
* AB testing integration
|
148
175
|
|
149
176
|
Contributing to impressionist
|
150
177
|
-----------------------------
|
151
|
-
* Check out the latest master to make sure the feature hasn't been implemented
|
152
|
-
|
178
|
+
* Check out the latest master to make sure the feature hasn't been implemented
|
179
|
+
or the bug hasn't been fixed yet
|
180
|
+
* Check out the issue tracker to make sure someone already hasn't requested it
|
181
|
+
and/or contributed it
|
153
182
|
* Fork the project
|
154
183
|
* Start a feature/bugfix branch
|
155
184
|
* Commit and push until you are happy with your contribution
|
156
|
-
* Make sure to add rpsec tests for it. Patches or features without tests will
|
157
|
-
|
158
|
-
*
|
185
|
+
* Make sure to add rpsec tests for it. Patches or features without tests will
|
186
|
+
be ignored. Also, try to write better tests than I do ;-)
|
187
|
+
* If adding engine controller or view functionality, use HAML and Inherited
|
188
|
+
Resources.
|
189
|
+
* All testing is done inside a small Rails app (test_app). You will find specs
|
190
|
+
within this app.
|
159
191
|
|
160
192
|
Contributors
|
161
193
|
------------
|
162
|
-
* johnmcaliley
|
163
|
-
* coryschires
|
164
|
-
* georgmittendorfer
|
165
|
-
|
194
|
+
* [johnmcaliley](https://github.com/johnmcaliley)
|
195
|
+
* [coryschires](https://github.com/coryschires)
|
196
|
+
* [georgmittendorfer](https://github.com/georgmittendorfer)
|
166
197
|
|
167
198
|
Copyright (c) 2011 John McAliley. See LICENSE.txt for further details.
|
data/Rakefile
CHANGED
@@ -1,89 +1,17 @@
|
|
1
|
-
|
2
|
-
require 'bundler'
|
1
|
+
#!/usr/bin/env rake
|
3
2
|
|
4
|
-
|
5
|
-
|
6
|
-
rescue Bundler::BundlerError => e
|
7
|
-
$stderr.puts e.message
|
8
|
-
$stderr.puts "Run `bundle install` to install missing gems"
|
9
|
-
exit e.status_code
|
10
|
-
end
|
11
|
-
require 'rake'
|
12
|
-
|
13
|
-
require 'jeweler'
|
14
|
-
Jeweler::Tasks.new do |gem|
|
15
|
-
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
16
|
-
gem.name = "impressionist"
|
17
|
-
gem.homepage = "http://github.com/cowboycoded/impressionist"
|
18
|
-
gem.license = "MIT"
|
19
|
-
gem.summary = %Q{Easy way to log impressions}
|
20
|
-
gem.description = %Q{Log impressions from controller actions or from a model}
|
21
|
-
gem.email = "john.mcaliley@gmail.com"
|
22
|
-
gem.authors = ["cowboycoded"]
|
23
|
-
gem.files.exclude "test_app/**/*", "test_app/**/.*"
|
24
|
-
end
|
25
|
-
Jeweler::RubygemsDotOrgTasks.new
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'rspec/core/rake_task'
|
26
5
|
|
27
|
-
|
28
|
-
Rake::TestTask.new(:test) do |test|
|
29
|
-
test.libs << 'lib' << 'test'
|
30
|
-
test.pattern = 'test/**/test_*.rb'
|
31
|
-
test.verbose = true
|
32
|
-
end
|
6
|
+
Bundler::GemHelper.install_tasks
|
33
7
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
test.pattern = 'test/**/test_*.rb'
|
38
|
-
test.verbose = true
|
8
|
+
RSpec::Core::RakeTask.new do |task|
|
9
|
+
task.rspec_opts = "-I ./test_app/spec"
|
10
|
+
task.pattern = "./test_app/spec/**/*_spec.rb"
|
39
11
|
end
|
40
12
|
|
41
|
-
task :
|
42
|
-
|
43
|
-
require 'rake/rdoctask'
|
44
|
-
Rake::RDocTask.new do |rdoc|
|
45
|
-
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
46
|
-
|
47
|
-
rdoc.rdoc_dir = 'rdoc'
|
48
|
-
rdoc.title = "impressionist #{version}"
|
49
|
-
rdoc.rdoc_files.include('README*')
|
50
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
51
|
-
end
|
52
|
-
|
53
|
-
namespace :version do
|
54
|
-
desc "create a new version, create tag and push to github"
|
55
|
-
task :patch_release do
|
56
|
-
if Jeweler::Commands::ReleaseToGit.new.clean_staging_area?
|
57
|
-
Rake::Task['version:bump:patch'].invoke
|
58
|
-
Rake::Task['gemspec:release'].invoke
|
59
|
-
Rake::Task['git:release'].invoke
|
60
|
-
else
|
61
|
-
puts "Commit your changed files first"
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
desc "create a new version, create tag and push to github"
|
66
|
-
task :minor_release do
|
67
|
-
if Jeweler::Commands::ReleaseToGit.new.clean_staging_area?
|
68
|
-
Rake::Task['version:bump:minor'].invoke
|
69
|
-
Rake::Task['gemspec:release'].invoke
|
70
|
-
Rake::Task['git:release'].invoke
|
71
|
-
else
|
72
|
-
puts "Commit your changed files first"
|
73
|
-
end
|
74
|
-
end
|
75
|
-
|
76
|
-
desc "create a new version, create tag and push to github"
|
77
|
-
task :major_release do
|
78
|
-
if Jeweler::Commands::ReleaseToGit.new.clean_staging_area?
|
79
|
-
Rake::Task['version:bump:major'].invoke
|
80
|
-
Rake::Task['gemspec:release'].invoke
|
81
|
-
Rake::Task['git:release'].invoke
|
82
|
-
else
|
83
|
-
puts "Commit your changed files first"
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
13
|
+
task :test => :spec
|
14
|
+
task :default => :spec
|
87
15
|
|
88
16
|
namespace :impressionist do
|
89
17
|
require File.dirname(__FILE__) + "/lib/impressionist/bots"
|
@@ -92,4 +20,4 @@ namespace :impressionist do
|
|
92
20
|
task :bots do
|
93
21
|
p Impressionist::Bots.consume
|
94
22
|
end
|
95
|
-
end
|
23
|
+
end
|
@@ -39,22 +39,22 @@ module ImpressionistController
|
|
39
39
|
end
|
40
40
|
|
41
41
|
private
|
42
|
-
|
42
|
+
|
43
43
|
def bypass
|
44
44
|
Impressionist::Bots::WILD_CARDS.each do |wild_card|
|
45
45
|
return true if request.user_agent and request.user_agent.downcase.include? wild_card
|
46
46
|
end
|
47
47
|
Impressionist::Bots::LIST.include? request.user_agent
|
48
48
|
end
|
49
|
-
|
49
|
+
|
50
50
|
def unique_instance?(impressionable, unique_opts)
|
51
|
-
return unique_opts.blank? || impressionable.impressions.where(unique_query(unique_opts)).
|
51
|
+
return unique_opts.blank? || !impressionable.impressions.where(unique_query(unique_opts)).exists?
|
52
52
|
end
|
53
|
-
|
53
|
+
|
54
54
|
def unique?(unique_opts)
|
55
|
-
return unique_opts.blank? || Impression.where(unique_query(unique_opts)).
|
55
|
+
return unique_opts.blank? || !Impression.where(unique_query(unique_opts)).exists?
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
58
|
# creates the query to check for uniqueness
|
59
59
|
def unique_query(unique_opts)
|
60
60
|
full_statement = direct_create_statement
|
@@ -64,7 +64,7 @@ module ImpressionistController
|
|
64
64
|
query
|
65
65
|
end
|
66
66
|
end
|
67
|
-
|
67
|
+
|
68
68
|
# creates a statment hash that contains default values for creating an impression via an AR relation.
|
69
69
|
def associative_create_statement(query_params={})
|
70
70
|
query_params.reverse_merge!(
|
@@ -77,7 +77,7 @@ module ImpressionistController
|
|
77
77
|
:referrer => request.referer
|
78
78
|
)
|
79
79
|
end
|
80
|
-
|
80
|
+
|
81
81
|
# creates a statment hash that contains default values for creating an impression.
|
82
82
|
def direct_create_statement(query_params={})
|
83
83
|
query_params.reverse_merge!(
|
@@ -86,7 +86,7 @@ module ImpressionistController
|
|
86
86
|
)
|
87
87
|
associative_create_statement(query_params)
|
88
88
|
end
|
89
|
-
|
89
|
+
|
90
90
|
def session_hash
|
91
91
|
# # careful: request.session_options[:id] encoding in rspec test was ASCII-8BIT
|
92
92
|
# # that broke the database query for uniqueness. not sure if this is a testing only issue.
|
@@ -95,7 +95,7 @@ module ImpressionistController
|
|
95
95
|
# # request.session_options[:id].encode("ISO-8859-1")
|
96
96
|
request.session_options[:id]
|
97
97
|
end
|
98
|
-
|
98
|
+
|
99
99
|
#use both @current_user and current_user helper
|
100
100
|
def user_id
|
101
101
|
user_id = @current_user ? @current_user.id : nil rescue nil
|
@@ -103,4 +103,4 @@ module ImpressionistController
|
|
103
103
|
user_id
|
104
104
|
end
|
105
105
|
end
|
106
|
-
end
|
106
|
+
end
|
data/app/models/impression.rb
CHANGED
@@ -1,16 +1,3 @@
|
|
1
|
-
class Impression
|
1
|
+
class Impression
|
2
2
|
belongs_to :impressionable, :polymorphic=>true
|
3
|
-
|
4
|
-
after_save :update_impressions_counter_cache
|
5
|
-
|
6
|
-
private
|
7
|
-
|
8
|
-
def update_impressions_counter_cache
|
9
|
-
impressionable_class = self.impressionable_type.constantize
|
10
|
-
|
11
|
-
if impressionable_class.counter_cache_options
|
12
|
-
resouce = impressionable_class.find(self.impressionable_id)
|
13
|
-
resouce.try(:update_counter_cache)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
3
|
+
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module Impressionist
|
2
2
|
module Bots
|
3
3
|
WILD_CARDS = ["bot","yahoo","slurp","google","msn","crawler"]
|
4
|
-
|
5
|
-
LIST = ["<a href='http://www.unchaos.com/'> UnChaos </a> From Chaos To Order Hybrid Web Search Engine.(vadim_gonchar@unchaos.com)",
|
4
|
+
|
5
|
+
LIST = ["<a href='http://www.unchaos.com/'> UnChaos </a> From Chaos To Order Hybrid Web Search Engine.(vadim_gonchar@unchaos.com)",
|
6
6
|
"<a href='http://www.unchaos.com/'> UnChaos Bot Hybrid Web Search Engine. </a> (vadim_gonchar@unchaos.com)",
|
7
7
|
"<b> UnChaosBot From Chaos To Order UnChaos Hybrid Web Search Engine at www.unchaos.com </b> (info@unchaos.com)",
|
8
8
|
"<http://www.sygol.com/> http://www.sygol.com",
|
@@ -1459,4 +1459,4 @@ module Impressionist
|
|
1459
1459
|
"zspider/0.9-dev http://feedback.redkolibri.com/",
|
1460
1460
|
"ZyBorg/1.0 (ZyBorg@WISEnut.com; http://www.WISEnut.com)"]
|
1461
1461
|
end
|
1462
|
-
end
|
1462
|
+
end
|