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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e54acf13c5302ba85596ef90c1a3a5c62b00600e
4
- data.tar.gz: abd480468c4233dc53d90a9c99e33e9c4d8f92df
3
+ metadata.gz: 21d3757724d47e6661766a7c05a6d356718fe45e
4
+ data.tar.gz: bd7700838203dbb58c7f73c64315fb7ab85e1f49
5
5
  SHA512:
6
- metadata.gz: c12ab157990533c5fed66d2db6e7c8ba614d778bc66751c5bf9eaa142464c1d91664571fe8767b0ad29e59f813e68f804c3447a5a09ad8bf26cb8988debef9dd
7
- data.tar.gz: 08bfbbe4c048647c2ff2246bf7d0bec789643d26da13344fdb7ac8d0fca11cedc010bd95e6cb82b3e4a7275747bfdab24313045dfba8f955c143b3afffbe528b
6
+ metadata.gz: 17efd95cec969a5ab546f2e4947c4ea04e2db002c96f335965b562e994c00ec307cb364587a873bdac50c4e1781f030724b988a5ddd66f39c3bbcd4611d81af4
7
+ data.tar.gz: e574582253eeed54ef6d2d490b123f38bb1c4445db87bf9a281fadaf26914de1b4ead38465aaec9978f0eaab73ab71bee1a9c42b364336bfc8a80519e069f940
data/.gitignore CHANGED
@@ -8,3 +8,5 @@
8
8
  /test_app/test
9
9
  /test_app/vendor
10
10
  Gemfile.lock
11
+ *.swo
12
+ *.swp
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 => { :column_name => :my_column_name }
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 => { :column_name => :my_column_name, :unique => true }
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 => { :column_name => :my_column_name, :unique => :request_hash }
154
- is_impressionable :counter_cache => { :column_name => :my_column_name, :unique => :all }
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
- # if updatable returns true, it must be qualified to update_counters
16
- # impressionable_class instance var is set when updatable? is called
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
- updatable? && impressionable_try
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
- @impressionable_class = impressionable_class_set
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 impressionable_find
33
- exeception_rescuer {
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
- # imps_type == nil, constantize returns Object
41
- # It attemps to return false so it won't be updatable
42
- # calls to_s otherwise it would try to constantize nil
43
- # and it would raise an exeception
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
@@ -1,3 +1,3 @@
1
1
  module Impressionist
2
- VERSION = "1.4.6"
2
+ VERSION = "1.4.7"
3
3
  end
@@ -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 => 20130709003307) do
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.6
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-17 00:00:00.000000000 Z
11
+ date: 2013-08-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httpclient