impressionist 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.travis.yml +1 -2
- data/README.md +16 -8
- data/app/controllers/impressionist_controller.rb +1 -1
- data/lib/generators/active_record/templates/create_impressions_table.rb +1 -1
- data/lib/impressionist/controllers/mongoid/impressionist_controller.rb +2 -2
- data/lib/impressionist/engine.rb +41 -26
- data/lib/impressionist/models/active_record/impression.rb +6 -5
- data/lib/impressionist/models/mongoid/impressionist/impressionable.rb +3 -2
- data/lib/impressionist/version.rb +1 -1
- data/test_app/app/controllers/dummy_controller.rb +2 -0
- data/test_app/app/views/dummy/index.html.erb +0 -0
- data/test_app/config/routes.rb +1 -1
- data/test_app/spec/controllers/controller_spec.rb +9 -0
- data/test_app/spec/controllers/impressionist_uniqueness_spec.rb +1 -1
- metadata +6 -5
- data/upgrade_migrations/version_1_1_2.rb +0 -9
data/.travis.yml
CHANGED
@@ -1,10 +1,9 @@
|
|
1
1
|
before_install: gem install bundler
|
2
|
-
before_script: "cd test_app && bundle install && ./script/rails generate impressionist && bundle exec rake db:migrate && cd .."
|
2
|
+
before_script: "cd test_app && bundle install && ./script/rails generate impressionist -f && bundle exec rake db:migrate && cd .."
|
3
3
|
language: ruby
|
4
4
|
rvm:
|
5
5
|
- rbx-18mode
|
6
6
|
- rbx-19mode
|
7
|
-
- jruby-18mode
|
8
7
|
- 1.8.7
|
9
8
|
- 1.9.2
|
10
9
|
- 1.9.3
|
data/README.md
CHANGED
@@ -164,14 +164,22 @@ Or you can use the `impressionist` method directly:
|
|
164
164
|
|
165
165
|
impressionist(impressionable, "some message", :unique => [:session_hash])
|
166
166
|
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
167
|
+
Are you using Mongoid?
|
168
|
+
---------------------
|
169
|
+
|
170
|
+
Execute this command on your terminal/console:
|
171
|
+
|
172
|
+
rails g impressionist --orm mongoid
|
173
|
+
|
174
|
+
This command create a file `impression.rb` on `config/initializer` folder. Add `config.orm = :mongoid` to this file:
|
175
|
+
|
176
|
+
# Use this hook to configure impressionist parameters
|
177
|
+
Impressionist.setup do |config|
|
178
|
+
# Define ORM. Could be :active_record (default), :mongo_mapper or :mongoid
|
179
|
+
# config.orm = :active_record
|
180
|
+
config.orm = :mongoid
|
181
|
+
end
|
182
|
+
|
175
183
|
|
176
184
|
Contributing to impressionist
|
177
185
|
-----------------------------
|
@@ -78,7 +78,7 @@ module ImpressionistController
|
|
78
78
|
# creates a statment hash that contains default values for creating an impression.
|
79
79
|
def direct_create_statement(query_params={})
|
80
80
|
query_params.reverse_merge!(
|
81
|
-
:impressionable_type =>
|
81
|
+
:impressionable_type => controller_path.singularize.camelize,
|
82
82
|
:impressionable_id=> params[:id]
|
83
83
|
)
|
84
84
|
associative_create_statement(query_params)
|
@@ -14,7 +14,7 @@ class CreateImpressionsTable < ActiveRecord::Migration
|
|
14
14
|
t.text :referrer
|
15
15
|
t.timestamps
|
16
16
|
end
|
17
|
-
add_index :impressions, [:impressionable_type, :message, :impressionable_id], :name => "impressionable_type_message_index", :unique => false
|
17
|
+
add_index :impressions, [:impressionable_type, :message, :impressionable_id], :name => "impressionable_type_message_index", :unique => false, :length => {:message => 255 }
|
18
18
|
add_index :impressions, [:impressionable_type, :impressionable_id, :request_hash], :name => "poly_request_index", :unique => false
|
19
19
|
add_index :impressions, [:impressionable_type, :impressionable_id, :ip_address], :name => "poly_ip_index", :unique => false
|
20
20
|
add_index :impressions, [:impressionable_type, :impressionable_id, :session_hash], :name => "poly_session_index", :unique => false
|
@@ -3,8 +3,8 @@ ImpressionistController::InstanceMethods.send(:define_method, :direct_create_sta
|
|
3
3
|
# if :impressionable_id is a valid ObjectId then convert it into one
|
4
4
|
base = (defined? Moped) ? Moped::BSON : BSON
|
5
5
|
query_params.reverse_merge!(
|
6
|
-
:impressionable_type =>
|
6
|
+
:impressionable_type => controller_path.singularize.camelize,
|
7
7
|
:impressionable_id=> !base::ObjectId.legal?(params[:id]) ? params[:id] : base::ObjectId.from_string(params[:id])
|
8
8
|
)
|
9
9
|
associative_create_statement(query_params)
|
10
|
-
end
|
10
|
+
end
|
data/lib/impressionist/engine.rb
CHANGED
@@ -3,31 +3,46 @@ require "rails"
|
|
3
3
|
|
4
4
|
module Impressionist
|
5
5
|
class Engine < Rails::Engine
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
6
|
+
attr_accessor :orm
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
define_orm_type(Impressionist.orm)
|
10
|
+
end
|
11
|
+
|
12
|
+
initializer 'impressionist.model' do |app|
|
13
|
+
require_orm
|
14
|
+
ActiveRecord::Base.send(:include, Impressionist::Impressionable)
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
|
19
|
+
initializer 'impressionist.controller' do
|
20
|
+
require "impressionist/controllers/mongoid/impressionist_controller.rb" if orm == :mongoid.to_s
|
21
|
+
|
22
|
+
ActiveSupport.on_load(:action_controller) do
|
23
|
+
include ImpressionistController::InstanceMethods
|
24
|
+
extend ImpressionistController::ClassMethods
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
|
29
|
+
private
|
30
|
+
def require_orm
|
31
|
+
require "#{root}/app/models/impressionist/impressionable.rb"
|
32
|
+
require "impressionist/models/#{orm}/impression.rb"
|
33
|
+
require "impressionist/models/#{orm}/impressionist/impressionable.rb"
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
def define_orm_type(str)
|
38
|
+
@orm = matcher(str.to_s)
|
39
|
+
end
|
40
|
+
|
41
|
+
def matcher(str)
|
42
|
+
matched = str.match(/active_record|mongo_mapper|mongoid|/)
|
43
|
+
matched[0]
|
44
|
+
end
|
45
|
+
|
46
|
+
|
32
47
|
end
|
33
48
|
end
|
@@ -10,11 +10,12 @@ class Impression < ActiveRecord::Base
|
|
10
10
|
private
|
11
11
|
|
12
12
|
def update_impressions_counter_cache
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
13
|
+
if self.impressionable_type && self.impressionable_id
|
14
|
+
impressionable_class = self.impressionable_type.constantize
|
15
|
+
if impressionable_class.impressionist_counter_cache_options
|
16
|
+
resouce = impressionable_class.find(self.impressionable_id)
|
17
|
+
resouce.try(:update_impressionist_counter_cache)
|
18
|
+
end
|
18
19
|
end
|
19
20
|
end
|
20
21
|
end
|
@@ -37,7 +37,8 @@ module Impressionist
|
|
37
37
|
def impressionist_count(options={})
|
38
38
|
options.reverse_merge!(:filter=>:request_hash, :start_date=>nil, :end_date=>Time.now)
|
39
39
|
imps = options[:start_date].blank? ? impressions : impressions.between(created_at: options[:start_date]..options[:end_date])
|
40
|
-
|
40
|
+
filter = options[:filter]
|
41
|
+
filter == :all ? imps.count : imps.where(filter.ne => nil).distinct(filter).count
|
41
42
|
end
|
42
43
|
|
43
44
|
def update_impressionist_counter_cache
|
@@ -49,4 +50,4 @@ module Impressionist
|
|
49
50
|
end
|
50
51
|
|
51
52
|
end
|
52
|
-
end
|
53
|
+
end
|
File without changes
|
data/test_app/config/routes.rb
CHANGED
@@ -123,3 +123,12 @@ describe WidgetsController do
|
|
123
123
|
end
|
124
124
|
|
125
125
|
end
|
126
|
+
describe DummyController do
|
127
|
+
fixtures :impressions
|
128
|
+
render_views
|
129
|
+
|
130
|
+
it "should log impression at the per action level on non-restful controller" do
|
131
|
+
get "index"
|
132
|
+
Impression.all.size.should eq 12
|
133
|
+
end
|
134
|
+
end
|
@@ -294,7 +294,7 @@ describe DummyController do
|
|
294
294
|
|
295
295
|
it "should recognize uniqueness" do
|
296
296
|
impressionable = Post.create
|
297
|
-
controller.stub!(:
|
297
|
+
controller.stub!(:controller_path).and_return("posts") # for correct impressionable type in filter
|
298
298
|
controller.stub!(:params).and_return({:id => impressionable.id.to_s}) # for correct impressionable id in filter
|
299
299
|
controller.stub!(:session_hash).and_return("foo")
|
300
300
|
controller.request.stub!(:remote_ip).and_return("1.2.3.4")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: impressionist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-05-06 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: httpclient
|
@@ -232,6 +232,7 @@ files:
|
|
232
232
|
- test_app/app/models/widget.rb
|
233
233
|
- test_app/app/views/articles/index.html.erb
|
234
234
|
- test_app/app/views/articles/show.html.erb
|
235
|
+
- test_app/app/views/dummy/index.html.erb
|
235
236
|
- test_app/app/views/layouts/application.html.erb
|
236
237
|
- test_app/app/views/posts/edit.html.erb
|
237
238
|
- test_app/app/views/posts/index.html.erb
|
@@ -296,7 +297,6 @@ files:
|
|
296
297
|
- test_app/spec/spec_helper.rb
|
297
298
|
- upgrade_migrations/version_0_3_0.rb
|
298
299
|
- upgrade_migrations/version_0_4_0.rb
|
299
|
-
- upgrade_migrations/version_1_1_2.rb
|
300
300
|
homepage: https://github.com/charlotte-ruby/impressionist
|
301
301
|
licenses:
|
302
302
|
- MIT
|
@@ -312,7 +312,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
312
312
|
version: '0'
|
313
313
|
segments:
|
314
314
|
- 0
|
315
|
-
hash:
|
315
|
+
hash: -3654668397609165147
|
316
316
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
317
317
|
none: false
|
318
318
|
requirements:
|
@@ -321,7 +321,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
321
321
|
version: 1.3.6
|
322
322
|
requirements: []
|
323
323
|
rubyforge_project:
|
324
|
-
rubygems_version: 1.8.
|
324
|
+
rubygems_version: 1.8.23
|
325
325
|
signing_key:
|
326
326
|
specification_version: 3
|
327
327
|
summary: Easy way to log impressions
|
@@ -348,6 +348,7 @@ test_files:
|
|
348
348
|
- test_app/app/models/widget.rb
|
349
349
|
- test_app/app/views/articles/index.html.erb
|
350
350
|
- test_app/app/views/articles/show.html.erb
|
351
|
+
- test_app/app/views/dummy/index.html.erb
|
351
352
|
- test_app/app/views/layouts/application.html.erb
|
352
353
|
- test_app/app/views/posts/edit.html.erb
|
353
354
|
- test_app/app/views/posts/index.html.erb
|
@@ -1,9 +0,0 @@
|
|
1
|
-
class Version04UpdateImpressionsTable < ActiveRecord::Migration
|
2
|
-
def self.up
|
3
|
-
add_index :impressions, [:impressionable_type, :message, :impressionable_id], :name => "impressionable_type_message_index", :unique => false
|
4
|
-
end
|
5
|
-
|
6
|
-
def self.down
|
7
|
-
remove_index :impressions, :impressionable_type_message_index
|
8
|
-
end
|
9
|
-
end
|