acts_as_active 0.1.3 → 0.2.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f32379b025f2eecaca909f9ea2fa6289cd353f480141fe8494e4179f339254b8
4
- data.tar.gz: be503eaf4cbf750cd66ab8eab07323050d6fee1e172e7eb5d01678418969cb0f
3
+ metadata.gz: 8d77b8db36fd55b8e5a5fd11c5d3c66086ca2edc782802accbc6dd868f7edd0e
4
+ data.tar.gz: c815c49b4daaa44a2b2dc752c744016ca3125a31be46700342053270759be6b6
5
5
  SHA512:
6
- metadata.gz: a546e8ca4ba37b06556559b763fae3433a8a23fa7eb1e2d2a5e3c845cd3b8072b95226463c3329cb390fbde29484f86a834932555cdc4be98aa1f775896411bb
7
- data.tar.gz: dfaae1ec7b0ce78e65bd218dcd01eac9e8048f90ec8597feeaea9ecbc311b397a303d11714b62ca4d2910563e9d573017cf73775525efefabec7b0e2b1e383f0
6
+ metadata.gz: f2bd60fd0f26c0e240179e2980c552aa69a83907742a33e3d979530ac4613e0227ce3c7357017ff22baa81019617809997e7af9e8fe9e2d19375dc385e89002d
7
+ data.tar.gz: 4fad00c674233c6b94b4eb4f2dbd1fe6011ac414cfa5946c85c9f2d31596dcf207c034d58c15c61c81be93a3981b95ff613fc44979af0ecfc3f50819d187849a
data/README.md CHANGED
@@ -22,15 +22,16 @@ gem install acts_as_active
22
22
 
23
23
  ```ruby
24
24
  class Record < ApplicationRecord
25
- acts_as_active on: [:create, :update], # ➜ track different actions
26
- if: -> { track_activity? }, # ➜ on different conditions
27
- unless: -> { skip_tracking? }
25
+ acts_as_active on: [:create, :update], # ➜ Track different actions
26
+ if: -> { track_activity? }, # ➜ On different conditions
27
+ unless: -> { skip_tracking? },
28
+ after_record: -> ( activity ) { puts "Modified: #{activity}" } # ➜ Hook: runs after an activity is created or updated
28
29
  end
29
30
  ```
30
31
 
31
32
  ```ruby
32
- record = Record.create!(title: "First draft") # ➜ records activity for today
33
- record.update!(title: "Second draft") # ➜ activity count for today = 2
33
+ record = Record.create!(title: "First draft") # ➜ Records activity for today
34
+ record.update!(title: "Second draft") # ➜ Activity count for today = 2
34
35
 
35
36
 
36
37
  record.active_today? # => true
@@ -46,6 +47,16 @@ record.longest_streak # => 3 (e.g. active 1-3 Aug)
46
47
  record.current_streak # => 2 (e.g. active 5-6 Aug, still “on a streak” today)
47
48
  ```
48
49
 
50
+ ## Accessing Activities
51
+
52
+ ```ruby
53
+ record = Record.find(1)
54
+ record.activities # Accessing activities for a model that includes ActsAsActive
55
+
56
+ ActsAsActive::Activity.where(trackable: record) # Query the namespaced model directly
57
+ ActsAsActive::Activity.all # Get all activities across all trackable types
58
+ ```
59
+
49
60
  ## Run Tests
50
61
 
51
62
  ```bash
@@ -14,7 +14,9 @@ module ActsAsActive
14
14
  def acts_as_active(options = {})
15
15
  has_many :activities, as: :trackable, class_name: "ActsAsActive::Activity"
16
16
 
17
- events = Array(options[:on] || SUPPORTED_EVENTS) & SUPPORTED_EVENTS
17
+ @acts_as_active_after_record = options[:after_record]
18
+ events = Array(options[:on] || SUPPORTED_EVENTS) & SUPPORTED_EVENTS
19
+
18
20
  events.each do |ev|
19
21
  after_commit on: ev do |_ignored|
20
22
  should_run = true
@@ -25,6 +27,10 @@ module ActsAsActive
25
27
  end
26
28
  end
27
29
  end
30
+
31
+ def acts_as_active_after_record
32
+ @acts_as_active_after_record
33
+ end
28
34
  end
29
35
 
30
36
 
@@ -35,6 +41,11 @@ module ActsAsActive
35
41
  activity.count ||= 0
36
42
  activity.count += 1
37
43
  activity.save!
44
+
45
+ hook = self.class.acts_as_active_after_record
46
+ hook&.call(activity)
47
+
48
+ activity
38
49
  end
39
50
  end
40
51
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActsAsActive
4
- VERSION = "0.1.3"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acts_as_active
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Amit Leshed