loggable_activity 0.1.56 → 0.1.58
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/.rubocop.yml +10 -1
- data/CHANGELOG.md +9 -0
- data/GETTING-STARTED.md +8 -47
- data/PAYLOAD_EXAMPLE.md +63 -0
- data/docs/LoggableActivity/Activity.html +92 -241
- data/docs/LoggableActivity/Configuration.html +162 -15
- data/docs/LoggableActivity/ConfigurationError.html +148 -0
- data/docs/LoggableActivity/DataOwner.html +138 -0
- data/docs/LoggableActivity/Encryption.html +18 -14
- data/docs/LoggableActivity/EncryptionError.html +47 -1
- data/docs/LoggableActivity/EncryptionKey.html +54 -35
- data/docs/LoggableActivity/Error.html +48 -0
- data/docs/LoggableActivity/Hooks.html +221 -89
- data/docs/LoggableActivity/Payload.html +103 -27
- data/docs/LoggableActivity/Services/BasePayloadsBuilder.html +442 -0
- data/docs/LoggableActivity/Services/DestroyPayloadsBuilder.html +395 -0
- data/docs/LoggableActivity/Services/PayloadsBuilder.html +342 -0
- data/docs/LoggableActivity/Services/UpdatePayloadsBuilder.html +490 -0
- data/docs/LoggableActivity/Services.html +93 -0
- data/docs/created.rid +14 -10
- data/docs/index.html +10 -2
- data/docs/js/navigation.js.gz +0 -0
- data/docs/js/search_index.js +1 -1
- data/docs/js/search_index.js.gz +0 -0
- data/docs/js/searcher.js.gz +0 -0
- data/docs/table_of_contents.html +253 -85
- data/lib/generators/loggable_activity/install_generator.rb +2 -18
- data/lib/generators/loggable_activity/templates/binary_ids/create_loggable_activities.rb +9 -10
- data/lib/generators/loggable_activity/templates/create_loggable_activities.rb +16 -13
- data/lib/loggable_activity/activity.rb +53 -102
- data/lib/loggable_activity/configuration.rb +60 -3
- data/lib/loggable_activity/data_owner.rb +18 -0
- data/lib/loggable_activity/encryption.rb +14 -14
- data/lib/loggable_activity/encryption_key.rb +26 -25
- data/lib/loggable_activity/error.rb +34 -0
- data/lib/loggable_activity/hooks.rb +78 -43
- data/lib/loggable_activity/payload.rb +70 -20
- data/lib/loggable_activity/services/base_payloads_builder.rb +127 -0
- data/lib/loggable_activity/services/destroy_payloads_builder.rb +127 -0
- data/lib/loggable_activity/services/payloads_builder.rb +98 -0
- data/lib/loggable_activity/services/update_payloads_builder.rb +168 -0
- data/lib/loggable_activity/version.rb +1 -1
- data/lib/loggable_activity.rb +6 -6
- data/lib/schemas/config_schema.json +90 -0
- metadata +37 -26
- data/docs/LoggableActivity/PayloadsBuilder.html +0 -441
- data/docs/LoggableActivity/UpdatePayloadsBuilder.html +0 -424
- data/lib/generators/loggable_activity/install_templates_generator.rb +0 -105
- data/lib/generators/loggable_activity/templates/helpers/activity_helper.rb +0 -37
- data/lib/generators/loggable_activity/templates/helpers/router.rb +0 -52
- data/lib/generators/loggable_activity/templates/helpers/routes_helper.rb +0 -20
- data/lib/generators/loggable_activity/templates/views/loggable_activity/templates/default/_create.html.erb +0 -23
- data/lib/generators/loggable_activity/templates/views/loggable_activity/templates/default/_create.html.slim +0 -18
- data/lib/generators/loggable_activity/templates/views/loggable_activity/templates/default/_destroy.html.erb +0 -18
- data/lib/generators/loggable_activity/templates/views/loggable_activity/templates/default/_destroy.html.slim +0 -17
- data/lib/generators/loggable_activity/templates/views/loggable_activity/templates/default/_show.html.erb +0 -18
- data/lib/generators/loggable_activity/templates/views/loggable_activity/templates/default/_show.html.slim +0 -17
- data/lib/generators/loggable_activity/templates/views/loggable_activity/templates/default/_update.html.erb +0 -18
- data/lib/generators/loggable_activity/templates/views/loggable_activity/templates/default/_update.html.slim +0 -12
- data/lib/generators/loggable_activity/templates/views/loggable_activity/templates/shared/_activity_info.html.erb +0 -12
- data/lib/generators/loggable_activity/templates/views/loggable_activity/templates/shared/_activity_info.html.slim +0 -11
- data/lib/generators/loggable_activity/templates/views/loggable_activity/templates/shared/_list_attrs.html.erb +0 -8
- data/lib/generators/loggable_activity/templates/views/loggable_activity/templates/shared/_list_attrs.html.slim +0 -6
- data/lib/generators/loggable_activity/templates/views/loggable_activity/templates/shared/_update_attrs.html.erb +0 -17
- data/lib/generators/loggable_activity/templates/views/loggable_activity/templates/shared/_update_attrs.html.slim +0 -14
- data/lib/generators/loggable_activity/templates/views/loggable_activity/templates/shared/_updated_relations.html.erb +0 -23
- data/lib/generators/loggable_activity/templates/views/loggable_activity/templates/shared/_updated_relations.html.slim +0 -21
- data/lib/loggable_activity/payloads_builder.rb +0 -153
- data/lib/loggable_activity/update_payloads_builder.rb +0 -127
@@ -1,424 +0,0 @@
|
|
1
|
-
<!DOCTYPE html>
|
2
|
-
|
3
|
-
<html>
|
4
|
-
<head>
|
5
|
-
<meta charset="UTF-8">
|
6
|
-
|
7
|
-
<title>module LoggableActivity::UpdatePayloadsBuilder - RDoc Documentation</title>
|
8
|
-
|
9
|
-
<script type="text/javascript">
|
10
|
-
var rdoc_rel_prefix = "../";
|
11
|
-
var index_rel_prefix = "../";
|
12
|
-
</script>
|
13
|
-
|
14
|
-
<script src="../js/navigation.js" defer></script>
|
15
|
-
<script src="../js/search.js" defer></script>
|
16
|
-
<script src="../js/search_index.js" defer></script>
|
17
|
-
<script src="../js/searcher.js" defer></script>
|
18
|
-
<script src="../js/darkfish.js" defer></script>
|
19
|
-
|
20
|
-
<link href="../css/fonts.css" rel="stylesheet">
|
21
|
-
<link href="../css/rdoc.css" rel="stylesheet">
|
22
|
-
|
23
|
-
|
24
|
-
<body id="top" role="document" class="module">
|
25
|
-
<nav role="navigation">
|
26
|
-
<div id="project-navigation">
|
27
|
-
<div id="home-section" role="region" title="Quick navigation" class="nav-section">
|
28
|
-
<h2>
|
29
|
-
<a href="../index.html" rel="home">Home</a>
|
30
|
-
</h2>
|
31
|
-
|
32
|
-
<div id="table-of-contents-navigation">
|
33
|
-
<a href="../table_of_contents.html#pages">Pages</a>
|
34
|
-
<a href="../table_of_contents.html#classes">Classes</a>
|
35
|
-
<a href="../table_of_contents.html#methods">Methods</a>
|
36
|
-
</div>
|
37
|
-
</div>
|
38
|
-
|
39
|
-
<div id="search-section" role="search" class="project-section initially-hidden">
|
40
|
-
<form action="#" method="get" accept-charset="utf-8">
|
41
|
-
<div id="search-field-wrapper">
|
42
|
-
<input id="search-field" role="combobox" aria-label="Search"
|
43
|
-
aria-autocomplete="list" aria-controls="search-results"
|
44
|
-
type="text" name="search" placeholder="Search (/) for a class, method, ..." spellcheck="false"
|
45
|
-
title="Type to search, Up and Down to navigate, Enter to load">
|
46
|
-
</div>
|
47
|
-
|
48
|
-
<ul id="search-results" aria-label="Search Results"
|
49
|
-
aria-busy="false" aria-expanded="false"
|
50
|
-
aria-atomic="false" class="initially-hidden"></ul>
|
51
|
-
</form>
|
52
|
-
</div>
|
53
|
-
|
54
|
-
</div>
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
<div id="class-metadata">
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
<!-- Method Quickref -->
|
65
|
-
<div id="method-list-section" class="nav-section">
|
66
|
-
<h3>Methods</h3>
|
67
|
-
|
68
|
-
<ul class="link-list" role="directory">
|
69
|
-
<li ><a href="#method-i-build_primary_update_payload">#build_primary_update_payload</a>
|
70
|
-
<li ><a href="#method-i-build_relation_update_for_belongs_to">#build_relation_update_for_belongs_to</a>
|
71
|
-
<li ><a href="#method-i-build_relation_update_for_has_many">#build_relation_update_for_has_many</a>
|
72
|
-
<li ><a href="#method-i-build_relation_update_for_has_one">#build_relation_update_for_has_one</a>
|
73
|
-
<li ><a href="#method-i-build_relation_update_payload">#build_relation_update_payload</a>
|
74
|
-
<li ><a href="#method-i-build_update_payloads">#build_update_payloads</a>
|
75
|
-
<li ><a href="#method-i-build_update_relation_payloads">#build_update_relation_payloads</a>
|
76
|
-
<li ><a href="#method-i-encrypted_update_attrs">#encrypted_update_attrs</a>
|
77
|
-
<li ><a href="#method-i-primary_update_attrs">#primary_update_attrs</a>
|
78
|
-
<li ><a href="#method-i-relation_encrypted_attrs">#relation_encrypted_attrs</a>
|
79
|
-
</ul>
|
80
|
-
</div>
|
81
|
-
|
82
|
-
</div>
|
83
|
-
</nav>
|
84
|
-
|
85
|
-
<main role="main" aria-labelledby="module-LoggableActivity::UpdatePayloadsBuilder">
|
86
|
-
<h1 id="module-LoggableActivity::UpdatePayloadsBuilder" class="module">
|
87
|
-
module LoggableActivity::UpdatePayloadsBuilder
|
88
|
-
</h1>
|
89
|
-
|
90
|
-
<section class="description">
|
91
|
-
|
92
|
-
<p>This module is responsible for building update payloads used in loggable activities.</p>
|
93
|
-
|
94
|
-
</section>
|
95
|
-
|
96
|
-
<section id="5Buntitled-5D" class="documentation-section">
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
<section id="public-instance-5Buntitled-5D-method-details" class="method-section">
|
103
|
-
<header>
|
104
|
-
<h3>Public Instance Methods</h3>
|
105
|
-
</header>
|
106
|
-
|
107
|
-
<div id="method-i-build_update_payloads" class="method-detail ">
|
108
|
-
<div class="method-header">
|
109
|
-
<div class="method-heading">
|
110
|
-
<span class="method-name">build_update_payloads</span><span
|
111
|
-
class="method-args">()</span>
|
112
|
-
<span class="method-click-advice">click to toggle source</span>
|
113
|
-
</div>
|
114
|
-
</div>
|
115
|
-
|
116
|
-
<div class="method-description">
|
117
|
-
<p>Builds payloads for an activity update event.</p>
|
118
|
-
|
119
|
-
<div class="method-source-code" id="build_update_payloads-source">
|
120
|
-
<pre><span class="ruby-comment"># File lib/loggable_activity/update_payloads_builder.rb, line 7</span>
|
121
|
-
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">build_update_payloads</span>
|
122
|
-
<span class="ruby-ivar">@update_payloads</span> = []
|
123
|
-
|
124
|
-
<span class="ruby-identifier">previous_values</span>, <span class="ruby-identifier">current_values</span> = <span class="ruby-identifier">primary_update_attrs</span>
|
125
|
-
<span class="ruby-identifier">build_primary_update_payload</span>(<span class="ruby-identifier">previous_values</span>, <span class="ruby-identifier">current_values</span>)
|
126
|
-
|
127
|
-
<span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">relations</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">relation_config</span><span class="ruby-operator">|</span>
|
128
|
-
<span class="ruby-identifier">build_update_relation_payloads</span>(<span class="ruby-identifier">relation_config</span>)
|
129
|
-
<span class="ruby-keyword">end</span>
|
130
|
-
<span class="ruby-ivar">@update_payloads</span>
|
131
|
-
<span class="ruby-keyword">end</span></pre>
|
132
|
-
</div>
|
133
|
-
</div>
|
134
|
-
|
135
|
-
|
136
|
-
</div>
|
137
|
-
|
138
|
-
</section>
|
139
|
-
|
140
|
-
<section id="private-instance-5Buntitled-5D-method-details" class="method-section">
|
141
|
-
<header>
|
142
|
-
<h3>Private Instance Methods</h3>
|
143
|
-
</header>
|
144
|
-
|
145
|
-
<div id="method-i-build_primary_update_payload" class="method-detail ">
|
146
|
-
<div class="method-header">
|
147
|
-
<div class="method-heading">
|
148
|
-
<span class="method-name">build_primary_update_payload</span><span
|
149
|
-
class="method-args">(previous_values, current_values)</span>
|
150
|
-
<span class="method-click-advice">click to toggle source</span>
|
151
|
-
</div>
|
152
|
-
</div>
|
153
|
-
|
154
|
-
<div class="method-description">
|
155
|
-
<p>Builds the primary update payload.</p>
|
156
|
-
|
157
|
-
<div class="method-source-code" id="build_primary_update_payload-source">
|
158
|
-
<pre><span class="ruby-comment"># File lib/loggable_activity/update_payloads_builder.rb, line 30</span>
|
159
|
-
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">build_primary_update_payload</span>(<span class="ruby-identifier">previous_values</span>, <span class="ruby-identifier">current_values</span>)
|
160
|
-
<span class="ruby-keyword">return</span> <span class="ruby-keyword">if</span> <span class="ruby-identifier">previous_values</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">current_values</span>
|
161
|
-
|
162
|
-
<span class="ruby-identifier">encrypted_update_attrs</span> = <span class="ruby-identifier">encrypted_update_attrs</span>(<span class="ruby-identifier">previous_values</span>, <span class="ruby-identifier">current_values</span>)
|
163
|
-
<span class="ruby-ivar">@update_payloads</span> <span class="ruby-operator"><<</span> <span class="ruby-constant">LoggableActivity</span><span class="ruby-operator">::</span><span class="ruby-constant">Payload</span>.<span class="ruby-identifier">new</span>(
|
164
|
-
<span class="ruby-value">record:</span> <span class="ruby-ivar">@record</span>,
|
165
|
-
<span class="ruby-value">payload_type:</span> <span class="ruby-string">'update_payload'</span>,
|
166
|
-
<span class="ruby-value">encrypted_attrs:</span> <span class="ruby-identifier">encrypted_update_attrs</span>,
|
167
|
-
<span class="ruby-value">route:</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">route</span>
|
168
|
-
)
|
169
|
-
<span class="ruby-keyword">end</span></pre>
|
170
|
-
</div>
|
171
|
-
</div>
|
172
|
-
|
173
|
-
|
174
|
-
</div>
|
175
|
-
|
176
|
-
<div id="method-i-build_relation_update_for_belongs_to" class="method-detail ">
|
177
|
-
<div class="method-header">
|
178
|
-
<div class="method-heading">
|
179
|
-
<span class="method-name">build_relation_update_for_belongs_to</span><span
|
180
|
-
class="method-args">(relation_config)</span>
|
181
|
-
<span class="method-click-advice">click to toggle source</span>
|
182
|
-
</div>
|
183
|
-
</div>
|
184
|
-
|
185
|
-
<div class="method-description">
|
186
|
-
<p>Builds the update payload for a belongs_to relation.</p>
|
187
|
-
|
188
|
-
<div class="method-source-code" id="build_relation_update_for_belongs_to-source">
|
189
|
-
<pre><span class="ruby-comment"># File lib/loggable_activity/update_payloads_builder.rb, line 86</span>
|
190
|
-
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">build_relation_update_for_belongs_to</span>(<span class="ruby-identifier">relation_config</span>)
|
191
|
-
<span class="ruby-identifier">relation_id</span> = <span class="ruby-node">"#{relation_config['belongs_to']}_id"</span>
|
192
|
-
<span class="ruby-identifier">model_class_name</span> = <span class="ruby-identifier">relation_config</span>[<span class="ruby-string">'model'</span>]
|
193
|
-
<span class="ruby-identifier">model_class</span> = <span class="ruby-identifier">model_class_name</span>.<span class="ruby-identifier">constantize</span>
|
194
|
-
|
195
|
-
<span class="ruby-keyword">return</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">saved_changes</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">relation_id</span>)
|
196
|
-
|
197
|
-
<span class="ruby-identifier">relation_id_changes</span> = <span class="ruby-identifier">saved_changes</span>[<span class="ruby-identifier">relation_id</span>]
|
198
|
-
<span class="ruby-identifier">previous_relation_id</span>, <span class="ruby-identifier">current_relation_id</span> = <span class="ruby-identifier">relation_id_changes</span>
|
199
|
-
|
200
|
-
[<span class="ruby-identifier">previous_relation_id</span>, <span class="ruby-identifier">current_relation_id</span>].<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">id</span>, <span class="ruby-identifier">index</span><span class="ruby-operator">|</span>
|
201
|
-
<span class="ruby-identifier">relation_record</span> = <span class="ruby-identifier">id</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">model_class</span>.<span class="ruby-identifier">find_by</span>(<span class="ruby-value">id:</span>) <span class="ruby-operator">:</span> <span class="ruby-keyword">nil</span>
|
202
|
-
<span class="ruby-keyword">next</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">relation_record</span>
|
203
|
-
|
204
|
-
<span class="ruby-identifier">payload_type</span> = <span class="ruby-identifier">index</span>.<span class="ruby-identifier">zero?</span> <span class="ruby-operator">?</span> <span class="ruby-string">'previous_association'</span> <span class="ruby-operator">:</span> <span class="ruby-string">'current_association'</span>
|
205
|
-
<span class="ruby-identifier">build_relation_update_payload</span>(
|
206
|
-
<span class="ruby-identifier">relation_config</span>,
|
207
|
-
<span class="ruby-identifier">relation_record</span>,
|
208
|
-
<span class="ruby-identifier">payload_type</span>
|
209
|
-
)
|
210
|
-
<span class="ruby-keyword">end</span>
|
211
|
-
<span class="ruby-keyword">end</span></pre>
|
212
|
-
</div>
|
213
|
-
</div>
|
214
|
-
|
215
|
-
|
216
|
-
</div>
|
217
|
-
|
218
|
-
<div id="method-i-build_relation_update_for_has_many" class="method-detail ">
|
219
|
-
<div class="method-header">
|
220
|
-
<div class="method-heading">
|
221
|
-
<span class="method-name">build_relation_update_for_has_many</span><span
|
222
|
-
class="method-args">(relation_config)</span>
|
223
|
-
<span class="method-click-advice">click to toggle source</span>
|
224
|
-
</div>
|
225
|
-
</div>
|
226
|
-
|
227
|
-
<div class="method-description">
|
228
|
-
<p>Builds the update payload for a has_many relation.</p>
|
229
|
-
|
230
|
-
<div class="method-source-code" id="build_relation_update_for_has_many-source">
|
231
|
-
<pre><span class="ruby-comment"># File lib/loggable_activity/update_payloads_builder.rb, line 70</span>
|
232
|
-
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">build_relation_update_for_has_many</span>(<span class="ruby-identifier">relation_config</span>)
|
233
|
-
<span class="ruby-comment"># NOTE: This method is not implemented yet.</span>
|
234
|
-
<span class="ruby-comment"># It requires that there is a form where it is possible to change</span>
|
235
|
-
<span class="ruby-comment"># the related records. This is not implemented yet. in the Demo app</span>
|
236
|
-
<span class="ruby-comment"># puts relation_config['has_many']</span>
|
237
|
-
<span class="ruby-keyword">end</span></pre>
|
238
|
-
</div>
|
239
|
-
</div>
|
240
|
-
|
241
|
-
|
242
|
-
</div>
|
243
|
-
|
244
|
-
<div id="method-i-build_relation_update_for_has_one" class="method-detail ">
|
245
|
-
<div class="method-header">
|
246
|
-
<div class="method-heading">
|
247
|
-
<span class="method-name">build_relation_update_for_has_one</span><span
|
248
|
-
class="method-args">(relation_config)</span>
|
249
|
-
<span class="method-click-advice">click to toggle source</span>
|
250
|
-
</div>
|
251
|
-
</div>
|
252
|
-
|
253
|
-
<div class="method-description">
|
254
|
-
<p>Builds the update payload for a has_one relation.</p>
|
255
|
-
|
256
|
-
<div class="method-source-code" id="build_relation_update_for_has_one-source">
|
257
|
-
<pre><span class="ruby-comment"># File lib/loggable_activity/update_payloads_builder.rb, line 78</span>
|
258
|
-
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">build_relation_update_for_has_one</span>(<span class="ruby-identifier">relation_config</span>)
|
259
|
-
<span class="ruby-comment"># NOTE: This method is not implemented yet.</span>
|
260
|
-
<span class="ruby-comment"># It requires that there is a form where it is possible to change</span>
|
261
|
-
<span class="ruby-comment"># the related records. This is not implemented yet. in the Demo app</span>
|
262
|
-
<span class="ruby-comment"># puts relation_config['has_one']</span>
|
263
|
-
<span class="ruby-keyword">end</span></pre>
|
264
|
-
</div>
|
265
|
-
</div>
|
266
|
-
|
267
|
-
|
268
|
-
</div>
|
269
|
-
|
270
|
-
<div id="method-i-build_relation_update_payload" class="method-detail ">
|
271
|
-
<div class="method-header">
|
272
|
-
<div class="method-heading">
|
273
|
-
<span class="method-name">build_relation_update_payload</span><span
|
274
|
-
class="method-args">(relation_config, record, payload_type)</span>
|
275
|
-
<span class="method-click-advice">click to toggle source</span>
|
276
|
-
</div>
|
277
|
-
</div>
|
278
|
-
|
279
|
-
<div class="method-description">
|
280
|
-
<p>Builds the update payload for a relation.</p>
|
281
|
-
|
282
|
-
<div class="method-source-code" id="build_relation_update_payload-source">
|
283
|
-
<pre><span class="ruby-comment"># File lib/loggable_activity/update_payloads_builder.rb, line 110</span>
|
284
|
-
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">build_relation_update_payload</span>(<span class="ruby-identifier">relation_config</span>, <span class="ruby-identifier">record</span>, <span class="ruby-identifier">payload_type</span>)
|
285
|
-
<span class="ruby-identifier">encryption_key</span> = <span class="ruby-constant">LoggableActivity</span><span class="ruby-operator">::</span><span class="ruby-constant">EncryptionKey</span>.<span class="ruby-identifier">for_record</span>(<span class="ruby-identifier">record</span>)&.<span class="ruby-identifier">key</span>
|
286
|
-
<span class="ruby-identifier">encrypted_attrs</span> = <span class="ruby-identifier">relation_encrypted_attrs</span>(<span class="ruby-identifier">record</span>.<span class="ruby-identifier">attributes</span>, <span class="ruby-identifier">relation_config</span>[<span class="ruby-string">'loggable_attrs'</span>], <span class="ruby-identifier">encryption_key</span>)
|
287
|
-
|
288
|
-
<span class="ruby-ivar">@update_payloads</span> <span class="ruby-operator"><<</span> <span class="ruby-constant">LoggableActivity</span><span class="ruby-operator">::</span><span class="ruby-constant">Payload</span>.<span class="ruby-identifier">new</span>(
|
289
|
-
<span class="ruby-value">record:</span>,
|
290
|
-
<span class="ruby-value">encrypted_attrs:</span>,
|
291
|
-
<span class="ruby-value">payload_type:</span>,
|
292
|
-
<span class="ruby-value">route:</span> <span class="ruby-identifier">relation_config</span>[<span class="ruby-string">'route'</span>]
|
293
|
-
)
|
294
|
-
<span class="ruby-keyword">end</span></pre>
|
295
|
-
</div>
|
296
|
-
</div>
|
297
|
-
|
298
|
-
|
299
|
-
</div>
|
300
|
-
|
301
|
-
<div id="method-i-build_update_relation_payloads" class="method-detail ">
|
302
|
-
<div class="method-header">
|
303
|
-
<div class="method-heading">
|
304
|
-
<span class="method-name">build_update_relation_payloads</span><span
|
305
|
-
class="method-args">(relation_config)</span>
|
306
|
-
<span class="method-click-advice">click to toggle source</span>
|
307
|
-
</div>
|
308
|
-
</div>
|
309
|
-
|
310
|
-
<div class="method-description">
|
311
|
-
<p>Builds update payloads for relations.</p>
|
312
|
-
|
313
|
-
<div class="method-source-code" id="build_update_relation_payloads-source">
|
314
|
-
<pre><span class="ruby-comment"># File lib/loggable_activity/update_payloads_builder.rb, line 56</span>
|
315
|
-
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">build_update_relation_payloads</span>(<span class="ruby-identifier">relation_config</span>)
|
316
|
-
<span class="ruby-identifier">relation_config</span>.<span class="ruby-identifier">each_key</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span><span class="ruby-operator">|</span>
|
317
|
-
<span class="ruby-keyword">case</span> <span class="ruby-identifier">key</span>
|
318
|
-
<span class="ruby-keyword">when</span> <span class="ruby-string">'belongs_to'</span>
|
319
|
-
<span class="ruby-identifier">build_relation_update_for_belongs_to</span>(<span class="ruby-identifier">relation_config</span>)
|
320
|
-
<span class="ruby-keyword">when</span> <span class="ruby-string">'has_one'</span>
|
321
|
-
<span class="ruby-identifier">build_relation_update_for_has_one</span>(<span class="ruby-identifier">relation_config</span>)
|
322
|
-
<span class="ruby-keyword">when</span> <span class="ruby-string">'has_many'</span>
|
323
|
-
<span class="ruby-identifier">build_relation_update_for_has_many</span>(<span class="ruby-identifier">relation_config</span>)
|
324
|
-
<span class="ruby-keyword">end</span>
|
325
|
-
<span class="ruby-keyword">end</span>
|
326
|
-
<span class="ruby-keyword">end</span></pre>
|
327
|
-
</div>
|
328
|
-
</div>
|
329
|
-
|
330
|
-
|
331
|
-
</div>
|
332
|
-
|
333
|
-
<div id="method-i-encrypted_update_attrs" class="method-detail ">
|
334
|
-
<div class="method-header">
|
335
|
-
<div class="method-heading">
|
336
|
-
<span class="method-name">encrypted_update_attrs</span><span
|
337
|
-
class="method-args">(previous_values, current_values)</span>
|
338
|
-
<span class="method-click-advice">click to toggle source</span>
|
339
|
-
</div>
|
340
|
-
</div>
|
341
|
-
|
342
|
-
<div class="method-description">
|
343
|
-
<p>Returns the encrypted attributes for the update payload.</p>
|
344
|
-
|
345
|
-
<div class="method-source-code" id="encrypted_update_attrs-source">
|
346
|
-
<pre><span class="ruby-comment"># File lib/loggable_activity/update_payloads_builder.rb, line 43</span>
|
347
|
-
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">encrypted_update_attrs</span>(<span class="ruby-identifier">previous_values</span>, <span class="ruby-identifier">current_values</span>)
|
348
|
-
<span class="ruby-identifier">changes</span> = []
|
349
|
-
<span class="ruby-identifier">changed_attrs</span> = <span class="ruby-identifier">previous_values</span>.<span class="ruby-identifier">slice</span>(<span class="ruby-operator">*</span><span class="ruby-keyword">self</span>.<span class="ruby-identifier">class</span>.<span class="ruby-identifier">loggable_attrs</span>)
|
350
|
-
<span class="ruby-identifier">changed_attrs</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">from_value</span><span class="ruby-operator">|</span>
|
351
|
-
<span class="ruby-identifier">from</span> = <span class="ruby-constant">LoggableActivity</span><span class="ruby-operator">::</span><span class="ruby-constant">Encryption</span>.<span class="ruby-identifier">encrypt</span>(<span class="ruby-identifier">from_value</span>, <span class="ruby-identifier">primary_encryption_key</span>)
|
352
|
-
<span class="ruby-identifier">to_value</span> = <span class="ruby-identifier">current_values</span>[<span class="ruby-identifier">key</span>]
|
353
|
-
<span class="ruby-identifier">to</span> = <span class="ruby-constant">LoggableActivity</span><span class="ruby-operator">::</span><span class="ruby-constant">Encryption</span>.<span class="ruby-identifier">encrypt</span>(<span class="ruby-identifier">to_value</span>, <span class="ruby-identifier">primary_encryption_key</span>)
|
354
|
-
<span class="ruby-identifier">changes</span> <span class="ruby-operator"><<</span> { <span class="ruby-identifier">key</span> <span class="ruby-operator">=></span> { <span class="ruby-value">from:</span>, <span class="ruby-value">to:</span> } }
|
355
|
-
<span class="ruby-keyword">end</span>
|
356
|
-
{ <span class="ruby-value">changes:</span> }
|
357
|
-
<span class="ruby-keyword">end</span></pre>
|
358
|
-
</div>
|
359
|
-
</div>
|
360
|
-
|
361
|
-
|
362
|
-
</div>
|
363
|
-
|
364
|
-
<div id="method-i-primary_update_attrs" class="method-detail ">
|
365
|
-
<div class="method-header">
|
366
|
-
<div class="method-heading">
|
367
|
-
<span class="method-name">primary_update_attrs</span><span
|
368
|
-
class="method-args">()</span>
|
369
|
-
<span class="method-click-advice">click to toggle source</span>
|
370
|
-
</div>
|
371
|
-
</div>
|
372
|
-
|
373
|
-
<div class="method-description">
|
374
|
-
<p>Fetch the previous and current values of the primary record.</p>
|
375
|
-
|
376
|
-
<div class="method-source-code" id="primary_update_attrs-source">
|
377
|
-
<pre><span class="ruby-comment"># File lib/loggable_activity/update_payloads_builder.rb, line 22</span>
|
378
|
-
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">primary_update_attrs</span>
|
379
|
-
<span class="ruby-identifier">previous_values</span> = <span class="ruby-identifier">saved_changes</span>.<span class="ruby-identifier">transform_values</span>(<span class="ruby-operator">&</span><span class="ruby-value">:first</span>)
|
380
|
-
<span class="ruby-identifier">current_values</span> = <span class="ruby-identifier">saved_changes</span>.<span class="ruby-identifier">transform_values</span>(<span class="ruby-operator">&</span><span class="ruby-value">:last</span>)
|
381
|
-
|
382
|
-
[<span class="ruby-identifier">previous_values</span>, <span class="ruby-identifier">current_values</span>]
|
383
|
-
<span class="ruby-keyword">end</span></pre>
|
384
|
-
</div>
|
385
|
-
</div>
|
386
|
-
|
387
|
-
|
388
|
-
</div>
|
389
|
-
|
390
|
-
<div id="method-i-relation_encrypted_attrs" class="method-detail ">
|
391
|
-
<div class="method-header">
|
392
|
-
<div class="method-heading">
|
393
|
-
<span class="method-name">relation_encrypted_attrs</span><span
|
394
|
-
class="method-args">(attrs, loggable_attrs, encryption_key)</span>
|
395
|
-
<span class="method-click-advice">click to toggle source</span>
|
396
|
-
</div>
|
397
|
-
</div>
|
398
|
-
|
399
|
-
<div class="method-description">
|
400
|
-
<p>Returns the encrypted attributes for a relation.</p>
|
401
|
-
|
402
|
-
<div class="method-source-code" id="relation_encrypted_attrs-source">
|
403
|
-
<pre><span class="ruby-comment"># File lib/loggable_activity/update_payloads_builder.rb, line 123</span>
|
404
|
-
<span class="ruby-keyword">def</span> <span class="ruby-identifier ruby-title">relation_encrypted_attrs</span>(<span class="ruby-identifier">attrs</span>, <span class="ruby-identifier">loggable_attrs</span>, <span class="ruby-identifier">encryption_key</span>)
|
405
|
-
<span class="ruby-identifier">encrypt_attrs</span>(<span class="ruby-identifier">attrs</span>, <span class="ruby-identifier">loggable_attrs</span>, <span class="ruby-identifier">encryption_key</span>)
|
406
|
-
<span class="ruby-keyword">end</span></pre>
|
407
|
-
</div>
|
408
|
-
</div>
|
409
|
-
|
410
|
-
|
411
|
-
</div>
|
412
|
-
|
413
|
-
</section>
|
414
|
-
|
415
|
-
</section>
|
416
|
-
</main>
|
417
|
-
|
418
|
-
|
419
|
-
<footer id="validator-badges" role="contentinfo">
|
420
|
-
<p><a href="https://validator.w3.org/check/referer">Validate</a>
|
421
|
-
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.6.2.
|
422
|
-
<p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
|
423
|
-
</footer>
|
424
|
-
|
@@ -1,105 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'rails/generators/base'
|
4
|
-
|
5
|
-
module LoggableActivity
|
6
|
-
module Generators
|
7
|
-
class InstallTemplatesGenerator < Rails::Generators::Base
|
8
|
-
source_root File.expand_path('templates', __dir__)
|
9
|
-
|
10
|
-
class_option :template, type: :string, default: 'erb'
|
11
|
-
|
12
|
-
def create_helper
|
13
|
-
copy_file 'helpers/activity_helper.rb', 'app/helpers/loggable_activity/activity_helper.rb'
|
14
|
-
copy_file 'helpers/routes_helper.rb', 'app/helpers/loggable_activity/routes_helper.rb'
|
15
|
-
copy_file 'helpers/router.rb', 'app/helpers/loggable_activity/router.rb'
|
16
|
-
end
|
17
|
-
|
18
|
-
def create_views
|
19
|
-
template_type = options['template']
|
20
|
-
|
21
|
-
case template_type
|
22
|
-
when 'slim'
|
23
|
-
# Copy slim files
|
24
|
-
copy_files('slim')
|
25
|
-
else
|
26
|
-
# Copy erb files
|
27
|
-
copy_files('erb')
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
def completion_message
|
32
|
-
message = <<~MESSAGE
|
33
|
-
------------------------------------------------
|
34
|
-
___ _ _ _ _#{' '}
|
35
|
-
|_ _| _ __ ___| |_ __ _| | __ _| |_(_) ___ _ __#{' '}
|
36
|
-
| | | '_ \\/ __| __/ _` | |/ _` | __| |/ _ \\| '_ \\#{' '}
|
37
|
-
| | | | | \\__ \\ || (_| | | (_| | |_| | (_) | | | |
|
38
|
-
|___| |_| |_|___/\\__\\__,_|_|\\__,_|\\__|_|\\___/|_| |_|
|
39
|
-
____ _ _ _#{' '}
|
40
|
-
/ ___| ___ _ __ ___ _ __ | | ___| |_ ___ __| |
|
41
|
-
| | / _ \\| '_ ` _ \\| '_ \\| |/ _ \\ __/ _ \\/ _` |
|
42
|
-
| |___ | (_) | | | | | | |_) | | __/ || __/ (_| |
|
43
|
-
\\____| \\___/|_| |_| |_| .__/|_|\\___|\\__\\___|\\__,_|
|
44
|
-
|_|#{' '}
|
45
|
-
|
46
|
-
LoggableActivity templates installed successfully!
|
47
|
-
|
48
|
-
Quick Start:
|
49
|
-
|
50
|
-
1. Create a new controller to show the list of activities.
|
51
|
-
$ rails generate controller LoggableActivities index
|
52
|
-
|
53
|
-
2 Add the following to the loggable_activities_controller.rb
|
54
|
-
def index
|
55
|
-
@loggable_activities = LoggableActivity::Activity.latest(50)
|
56
|
-
end
|
57
|
-
|
58
|
-
3. Update routes.rb
|
59
|
-
resources :loggable_activities, only: [:index]
|
60
|
-
|
61
|
-
4. update the index view in app/views/loggable_activities/index.html.TEMPLATE_TYPE
|
62
|
-
h1 Activities#{' '}
|
63
|
-
table.table#{' '}
|
64
|
-
thead
|
65
|
-
tr
|
66
|
-
th Info#{' '}
|
67
|
-
th Attributes
|
68
|
-
th Actions
|
69
|
-
tbody
|
70
|
-
- @loggable_activities.each do |activity|
|
71
|
-
= render_activity(activity)
|
72
|
-
|
73
|
-
5. Visit
|
74
|
-
http://localhost:3000/loggable_activities
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
For more information, please visit:
|
79
|
-
https://github.com/maxgronlund/LoggableActivity/blob/main/GETTING-STARTED.md
|
80
|
-
|
81
|
-
Install templates
|
82
|
-
$ rails generate loggable_activity:install_templates
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
------------------------------------------------
|
87
|
-
MESSAGE
|
88
|
-
|
89
|
-
puts message
|
90
|
-
end
|
91
|
-
|
92
|
-
private
|
93
|
-
|
94
|
-
def copy_files(type)
|
95
|
-
file_extension = type == 'slim' ? 'html.slim' : 'html.erb'
|
96
|
-
%w[create destroy show update].each do |action|
|
97
|
-
copy_file "views/loggable_activity/templates/default/_#{action}.#{file_extension}", "app/views/loggable_activity/templates/default/_#{action}.#{file_extension}"
|
98
|
-
end
|
99
|
-
%w[activity_info list_attrs update_attrs updated_relations].each do |shared|
|
100
|
-
copy_file "views/loggable_activity/templates/shared/_#{shared}.#{file_extension}", "app/views/loggable_activity/templates/shared/_#{shared}.#{file_extension}"
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module LoggableActivity
|
4
|
-
module ActivityHelper
|
5
|
-
# include ApplicationHelper
|
6
|
-
include LoggableActivity::Router
|
7
|
-
|
8
|
-
def render_activity(activity)
|
9
|
-
render partial: template_path(activity), locals: { activity: }
|
10
|
-
end
|
11
|
-
|
12
|
-
# def relation_type(relation_attrs)
|
13
|
-
# title = I18n.t("loggable.activity.models.#{relation_attrs[:record_type]}")
|
14
|
-
# if path = path_to_payload(relation_attrs[:path])
|
15
|
-
# path
|
16
|
-
# else
|
17
|
-
# title
|
18
|
-
# end
|
19
|
-
# end
|
20
|
-
|
21
|
-
private
|
22
|
-
|
23
|
-
def action_template_path(activity)
|
24
|
-
"loggable_activity/templates/#{activity.action.gsub('.', '/')}"
|
25
|
-
end
|
26
|
-
|
27
|
-
def template_path(activity)
|
28
|
-
template_path = action_template_path(activity)
|
29
|
-
if lookup_context.template_exists?(template_path, [], true)
|
30
|
-
template_path
|
31
|
-
else
|
32
|
-
action = activity.action.split('.').last || 'default'
|
33
|
-
"loggable_activity/templates/default/#{action}"
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
@@ -1,52 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'action_view'
|
4
|
-
|
5
|
-
module LoggableActivity
|
6
|
-
module Router
|
7
|
-
# include ApplicationHelper
|
8
|
-
include LoggableActivity::RoutesHelper
|
9
|
-
|
10
|
-
def primary_activity_text_or_link(activity)
|
11
|
-
route = activity.primary_route
|
12
|
-
text = text_for_link(route)
|
13
|
-
return text if route.nil?
|
14
|
-
return text if activity.record.nil?
|
15
|
-
|
16
|
-
url = url_to_record(route, activity.record)
|
17
|
-
return text unless url.present?
|
18
|
-
|
19
|
-
link_to(text, url)
|
20
|
-
end
|
21
|
-
|
22
|
-
def payload_type_text_or_link(attrs)
|
23
|
-
route = attrs[:route]
|
24
|
-
return model_translation(attrs) if route.nil?
|
25
|
-
|
26
|
-
record = find_record(attrs)
|
27
|
-
return model_translation(attrs) if record.nil?
|
28
|
-
|
29
|
-
text = text_for_link(route)
|
30
|
-
|
31
|
-
url = url_to_record(route, record)
|
32
|
-
return text if url.nil?
|
33
|
-
|
34
|
-
link_to(text, url)
|
35
|
-
end
|
36
|
-
|
37
|
-
private
|
38
|
-
|
39
|
-
def text_for_link(route)
|
40
|
-
I18n.t("loggable.activity.routes.#{route}")
|
41
|
-
end
|
42
|
-
|
43
|
-
def model_translation(attrs)
|
44
|
-
I18n.t("loggable.activity.models.#{attrs[:record_type]}")
|
45
|
-
end
|
46
|
-
|
47
|
-
def find_record(attrs)
|
48
|
-
record_class = attrs[:record_type].constantize
|
49
|
-
record_class.find(attrs[:record_id])
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module LoggableActivity
|
4
|
-
module RoutesHelper
|
5
|
-
include ApplicationHelper
|
6
|
-
|
7
|
-
def url_to_record(route, record)
|
8
|
-
case route
|
9
|
-
when 'show_doctor', 'show_patient', 'show_user', 'show_user_profile'
|
10
|
-
demo_user_url(record)
|
11
|
-
when 'show_demo_address'
|
12
|
-
demo_city_demo_address_url(record.demo_city, record)
|
13
|
-
when 'show_demo_city'
|
14
|
-
demo_city_url(record)
|
15
|
-
when 'show_demo_journal'
|
16
|
-
demo_journal_url(record)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|