impressionist 1.4.6 → 1.4.7
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.
- checksums.yaml +4 -4
- data/.gitignore +2 -0
- data/README.md +4 -4
- data/lib/impressionist/counter_cache.rb +27 -34
- data/lib/impressionist/version.rb +1 -1
- data/tests/test_app/db/schema.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21d3757724d47e6661766a7c05a6d356718fe45e
|
4
|
+
data.tar.gz: bd7700838203dbb58c7f73c64315fb7ab85e1f49
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 17efd95cec969a5ab546f2e4947c4ea04e2db002c96f335965b562e994c00ec307cb364587a873bdac50c4e1781f030724b988a5ddd66f39c3bbcd4611d81af4
|
7
|
+
data.tar.gz: e574582253eeed54ef6d2d490b123f38bb1c4445db87bf9a281fadaf26914de1b4ead38465aaec9978f0eaab73ab71bee1a9c42b364336bfc8a80519e069f940
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -139,19 +139,19 @@ This will automatically increment the `impressions_count` column in the
|
|
139
139
|
included model. <b>Note: You'll need to add that column to your model. If you'd
|
140
140
|
like specific a different column name, you can:</b>
|
141
141
|
|
142
|
-
is_impressionable :counter_cache =>
|
142
|
+
is_impressionable :counter_cache => true, :column_name => :my_column_name
|
143
143
|
|
144
144
|
If you'd like to include only unique impressions in your count:
|
145
145
|
|
146
146
|
# default will be filtered by ip_address
|
147
|
-
is_impressionable :counter_cache =>
|
147
|
+
is_impressionable :counter_cache => true, :column_name => :my_column_name, :unique => true
|
148
148
|
|
149
149
|
If you'd like to specify what sort of unique impression you'd like to save? Fear not,
|
150
150
|
Any option you pass to unique, impressionist_count will use it as its filter to update_counters based on that unique option.
|
151
151
|
|
152
152
|
# options are any column in the impressions' table.
|
153
|
-
is_impressionable :counter_cache =>
|
154
|
-
is_impressionable :counter_cache =>
|
153
|
+
is_impressionable :counter_cache => true, :column_name => :my_column_name, :unique => :request_hash
|
154
|
+
is_impressionable :counter_cache => true, :column_name => :my_column_name, :unique => :all
|
155
155
|
|
156
156
|
|
157
157
|
Adding column to model
|
@@ -1,10 +1,3 @@
|
|
1
|
-
# Note
|
2
|
-
# It is only updatable if
|
3
|
-
# impressionist_id && impressionist_type(class) are present &&
|
4
|
-
# impressionable_class(which is imp_type.constantize) is counter_caching
|
5
|
-
# Defined like so
|
6
|
-
# is_impressionable :counter_cache => true
|
7
|
-
|
8
1
|
module Impressionist
|
9
2
|
module CounterCache
|
10
3
|
|
@@ -12,43 +5,30 @@ module Impressionist
|
|
12
5
|
|
13
6
|
private
|
14
7
|
|
15
|
-
#
|
16
|
-
#
|
8
|
+
# A valid impression must
|
9
|
+
# have a valid impressionable class
|
10
|
+
# be counter_caching
|
11
|
+
# have a record saved in the db
|
12
|
+
# then it should give it a try
|
17
13
|
def impressionable_counter_cache_updatable?
|
18
|
-
|
14
|
+
updatable? && impressionable_try
|
19
15
|
end
|
20
16
|
|
21
|
-
# asks imp_id && imp_class whether it's present or not
|
22
|
-
# so that it is updatable
|
23
17
|
def updatable?
|
24
|
-
|
25
|
-
impressionable_valid?
|
26
|
-
end
|
27
|
-
|
28
|
-
def impressionable_valid?
|
29
|
-
(self.impressionable_id.present? && impressionable_class)
|
18
|
+
valid_impressionable_class? && impressionable_find
|
30
19
|
end
|
31
20
|
|
32
|
-
def
|
33
|
-
|
34
|
-
@entity = impressionable_class.find(self.impressionable_id)
|
35
|
-
}
|
36
|
-
@entity
|
37
|
-
|
21
|
+
def valid_impressionable_class?
|
22
|
+
set_impressionable_class && counter_caching?
|
38
23
|
end
|
39
24
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
# Must be !~ Object and be counter_caching to be qualified as updatable
|
45
|
-
def impressionable_class_set
|
46
|
-
klass = self.impressionable_type.to_s.constantize
|
47
|
-
(klass.to_s !~ /Object/) && klass.impressionist_counter_caching? ? klass : false
|
25
|
+
def set_impressionable_class
|
26
|
+
klass = self.impressionable_type || false
|
27
|
+
@impressionable_class = klass.
|
28
|
+
to_s.safe_constantize || false
|
48
29
|
end
|
49
30
|
|
50
31
|
# default mode is ERROR
|
51
|
-
# ruby 1.8.7 support
|
52
32
|
def impressionist_log(str, mode=:error)
|
53
33
|
Rails.logger.send(mode.to_s, str)
|
54
34
|
end
|
@@ -57,10 +37,23 @@ module Impressionist
|
|
57
37
|
# counter_cache column
|
58
38
|
# entity is a impressionable instance model
|
59
39
|
def impressionable_try
|
60
|
-
impressionable_find
|
61
40
|
entity.try(:update_impressionist_counter_cache)
|
62
41
|
end
|
63
42
|
|
43
|
+
def impressionable_find
|
44
|
+
exeception_rescuer {
|
45
|
+
@entity = impressionable_class.find(self.impressionable_id)
|
46
|
+
}
|
47
|
+
@entity
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
def counter_caching?
|
52
|
+
impressionable_class.
|
53
|
+
impressionist_counter_caching?
|
54
|
+
end
|
55
|
+
|
56
|
+
|
64
57
|
# Returns false, as it is only handling one exeception
|
65
58
|
# It would make updatable to fail thereafter it would not try
|
66
59
|
# to update cache_counter
|
data/tests/test_app/db/schema.rb
CHANGED
@@ -11,7 +11,7 @@
|
|
11
11
|
#
|
12
12
|
# It's strongly recommended to check this file into your version control system.
|
13
13
|
|
14
|
-
ActiveRecord::Schema.define(:version =>
|
14
|
+
ActiveRecord::Schema.define(:version => 20130719024021) do
|
15
15
|
|
16
16
|
create_table "articles", :force => true do |t|
|
17
17
|
t.string "name"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: impressionist
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- johnmcaliley
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-08-
|
11
|
+
date: 2013-08-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httpclient
|