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 +4 -4
- data/README.md +16 -5
- data/lib/acts_as_active/activable.rb +12 -1
- data/lib/acts_as_active/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8d77b8db36fd55b8e5a5fd11c5d3c66086ca2edc782802accbc6dd868f7edd0e
|
|
4
|
+
data.tar.gz: c815c49b4daaa44a2b2dc752c744016ca3125a31be46700342053270759be6b6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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],
|
|
26
|
-
if:
|
|
27
|
-
unless:
|
|
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") # ➜
|
|
33
|
-
record.update!(title: "Second draft") # ➜
|
|
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
|
-
|
|
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
|
|