loggable_activity 0.1.48 → 0.1.49

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ee3e20a374ac054a343ce5ff1c35c5fcce765fb631788fb6d9b738e52161a16a
4
- data.tar.gz: 042cc1db90cf6b99eeb2c8d5ab3f16a5473178c00085f42400c4eec344a99731
3
+ metadata.gz: e3a71b62ddccb997e31e0592a4069f3c1684043fe5dee77691801930ebd86a43
4
+ data.tar.gz: 7b8cf906c1357bbc2e90172020de8ab712132ba43de3a53fc0d4058cfa391bd8
5
5
  SHA512:
6
- metadata.gz: 1f4063eb4cd98a16061d151759735e0b5cc98e7747151dc2c56856f2010f23936c2c338991c5cc85dfd3c72af4f60133a4e39271f29ec76e5ee04383ad6dd073
7
- data.tar.gz: 8be57a52cfd948825e273648ffaec5809975dc14863f49206ee8f364f07b58a193758d80d867155f21760522a24bc2cf49d183ba757c503af1fdf51317b78202
6
+ metadata.gz: a951d551a83e4cab2c58ec1b6a3b00c1814ecd099bdf38682d024a99298417912f6efcaf1c1d625f8ee4f877ac60f7ab851cc9a00b2c7201fb9fba2cf1e093b1
7
+ data.tar.gz: 4821fd58720ad28bd77d7f958f0c1ce39de246503b93a4027097fa61c3b5f4b4e3ca3f673f37271205a121717905f3dbb12337ad3193e40fe12f6098f69667ec
data/CHANGELOG.md CHANGED
@@ -1,5 +1,7 @@
1
1
  ## [Unreleased]
2
2
  - nothing so far
3
+ ## [0.1.49] - 2024-02-18
4
+ - Metadata, pointing to hompage
3
5
 
4
6
  ## [0.1.48] - 2024-02-16
5
7
  ### Breaking change
@@ -7,14 +9,19 @@
7
9
  - Updated README.md
8
10
  - Updated GETTING_STARTED.md
9
11
  - Added PULL_REQUEST_TEMPLATE.md
12
+
10
13
  ## [0.1.46] - 2024-02-16
11
14
  - Fixed spelling error in EncryptionKey
15
+
12
16
  ## [0.1.43] - 2024-02-15
13
17
  - Updated README.md and GETTING-STARTED.md
18
+
14
19
  ## [0.1.39] - 2024-02-12
15
20
  - Updated README.md and GETTING-STARTED.md
21
+
16
22
  ## [0.1.38] - 2024-02-12
17
23
  - Removed dependency on awesome print
24
+
18
25
  ## [0.1.35] - 2024-02-11
19
26
  - Initial release
20
27
 
data/GETTING-STARTED.md CHANGED
@@ -8,26 +8,77 @@ This document should you getting started with `LoggableActivity`
8
8
  ## Demo Application
9
9
  You can download a demo application from<br/>
10
10
  [https://github.com/maxgronlund/LoggableActivityDemoApp](https://github.com/maxgronlund/LoggableActivityDemoApp)
11
+ <br/>
12
+ You can try a demo here<br/>
13
+ [https://loggableactivity-efe7b931c886.herokuapp.com/](https://loggableactivity-efe7b931c886.herokuapp.com/)
14
+
15
+ ## Getting started
16
+ First we add the loggable_activity gem to the Gemfile `gem 'loggable_activity', '~> x.x.xx'` and then `$ bundle install`<br/>
17
+ Then we have to generate some migrations and additionals files<br/>
18
+ `rails generate loggable_activity:install Activity`<br/>
11
19
 
12
20
  ## Configuration
13
- First you have to create a configuration file named `loggable_activity.yml` and locate it in the config folder.<br/>
14
- It has the following tags
15
- - `User` (example)<br>
16
- This is the name of the model you are configuring, as you can see there is alos a `Demo::Address` in the configuration file below, So if you have a model named `Demo::Club` you have to create at tag for that and fill in the other tags under that.
17
- - record_display_name: <br>
18
- Used to display something human to identify a given log entry, in this example the **User** model has a method named `full_name`
19
-
20
- - loggable_attrs:<br/>
21
- This are the attributes on a model and reflect the fields in the database you HAS to define, what fields to log.
22
-
23
- - auto_log:<br/>
24
- This are the actions that will be logged automatically, although you can log manually at any time.
25
- Note there is no hook for `Show` in Rails so you would have to log that manually like this `log(:show)`, more about that later.
26
-
27
- - relations:<br/>
28
- If a model has `belongs_to` and `has_one` relations you can log them automatically as well<br>
29
- <br/>
30
- *Example confuguration for logging of the user model*
21
+ You need a configuration file inside the `config/loggable_activity.yaml`
22
+ This file defines:
23
+ - What tables to log
24
+ - What fields in a table to log
25
+ - How data is aggregated.
26
+ - What should happen to the aggregation if a record is deleted.
27
+ - What actions to log.
28
+
29
+ *Here is an example*
30
+ ```
31
+ Demo::Club:
32
+ record_display_name: name
33
+ loggable_attrs:
34
+ - name
35
+ auto_log:
36
+ - create
37
+ - update
38
+ - destroy
39
+ relations:
40
+ - belongs_to: :address
41
+ model: Demo::Address
42
+ loggable_attrs:
43
+ - street
44
+ - city
45
+ ```
46
+
47
+ Lets break this down.
48
+ - First we can se that we are logging a model named Demo::Club.
49
+ - `record_display_name:` is the field/method on the on the model we want to display as a headline in the log
50
+ - Then we can se that we are logging the **name** of the club, in this example that's all there is to log.
51
+ - Then we can se that we are **logging create, update, and destroy** automatically.
52
+ - Then there are some relations: that we want to collect and add to the log, in this example we are logging the address as well.
53
+
54
+ Next we have to include some hooks to the model we want to log.
55
+
56
+ ```
57
+ class User < ApplicationRecord
58
+ include LoggableActivity::Hooks
59
+ ```
60
+
61
+ And then we have to add a this to the application_controller.rb
62
+ ```
63
+ class ApplicationController < ActionController::Base
64
+ include LoggableActivity::CurrentUser
65
+ ```
66
+ This will give us access to the current_user.
67
+
68
+ And then we have to add this to 'config/application.rb'
69
+ ```
70
+ config.loggable_activity = ActiveSupport::OrderedOptions.new
71
+ config.loggable_activity.actor_display_name = :full_name
72
+ config.loggable_activity.current_user_model_name = 'User'
73
+ LoggableActivity::Configuration.load_config_file('config/loggable_activity.yaml')
74
+ ```
75
+ actor_display_name: this is a method on the User model we want to use when presenting the actor.
76
+ current_user_model: This is the name of the model we use for current_user
77
+ load_config_file: this is the configuration file from above.
78
+
79
+
80
+ ## Configuration
81
+
31
82
  ```
32
83
  User:
33
84
  record_display_name: full_name
@@ -25,6 +25,7 @@ module LoggableActivity
25
25
  template 'loggable_activity.en.yml', 'config/locales/loggable_activity.en.yml'
26
26
  template 'loggable_activity.yml', 'config/loggable_activity.yml'
27
27
  template 'current_user.rb', 'app/controllers/concerns/loggable_activity/current_user.rb'
28
+ # template 'loggable_activity_helper.rb', 'app/helpers/loggable_activity_helper.rb'
28
29
  end
29
30
  end
30
31
  end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ module LoggableActivityHelper
4
+ include ApplicationHelper
5
+
6
+ def render_activity(activity)
7
+ render partial: template_path(activity), locals: { activity: }
8
+ end
9
+
10
+ def primary_type(activity)
11
+ I18n.t("loggable.activity.models.#{activity.record_type}")
12
+ end
13
+
14
+ def relation_type(relation_attrs)
15
+ I18n.t("loggable.activity.models.#{relation_attrs[:record_class]}")
16
+ end
17
+
18
+ def update_relation_class(update_attrs)
19
+ I18n.t("loggable.activity.models.#{update_attrs[:record_class]}")
20
+ end
21
+
22
+ private
23
+
24
+ def action_template_path(activity)
25
+ "loggable_activity/templates/#{activity.action.gsub('.', '/')}"
26
+ end
27
+
28
+ def template_path(activity)
29
+ template_path = action_template_path(activity)
30
+ if lookup_context.template_exists?(template_path, [], true)
31
+ template_path
32
+ else
33
+ action = activity.action.split('.').last || 'default'
34
+ "loggable_activity/templates/default/#{action}"
35
+ end
36
+ end
37
+
38
+ def activity_payload(activity)
39
+ @activity_payload ||= build_payload(activity)
40
+ end
41
+
42
+ def activity_attrs(activity)
43
+ @activity_attrs ||= activity_payload(activity).fetch(:activity, {})
44
+ end
45
+
46
+ def build_payload(activity)
47
+ Loggable::JsonPayloadFactory.new(activity).build_payload
48
+ end
49
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module LoggableActivity
4
- VERSION = '0.1.48'
4
+ VERSION = '0.1.49'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: loggable_activity
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.48
4
+ version: 0.1.49
5
5
  platform: ruby
6
6
  authors:
7
7
  - "Max \nGroenlund"
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-02-16 00:00:00.000000000 Z
11
+ date: 2024-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -116,6 +116,7 @@ files:
116
116
  - lib/generators/loggable_activity/templates/current_user.rb
117
117
  - lib/generators/loggable_activity/templates/loggable_activity.en.yml
118
118
  - lib/generators/loggable_activity/templates/loggable_activity.yml
119
+ - lib/generators/loggable_activity/templates/loggable_activity_helper.rb
119
120
  - lib/loggable_activity.rb
120
121
  - lib/loggable_activity/.DS_Store
121
122
  - lib/loggable_activity/activity.rb
@@ -133,6 +134,9 @@ homepage: https://loggableactivity-efe7b931c886.herokuapp.com/
133
134
  licenses:
134
135
  - MIT
135
136
  metadata:
137
+ homepage_uri: https://loggableactivity-efe7b931c886.herokuapp.com/
138
+ source_code_uri: https://github.com/maxgronlund/LoggableActivity
139
+ changelog_uri: https://github.com/maxgronlund/LoggableActivity/CHANGELOG.md
136
140
  documentation_uri: https://maxgronlund.github.io/LoggableActivity/
137
141
  rubygems_mfa_required: 'true'
138
142
  post_install_message: