eitil 0.3.6 → 0.3.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +28 -1
- data/app/models/eitil/stack_trace/audit.rb +15 -0
- data/app/models/eitil/stack_trace/call.rb +17 -0
- data/app/models/eitil/stack_trace/stack.rb +28 -0
- data/config/initializers/monkeys/application_record.rb +18 -4
- data/lib/eitil/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24a0dccf0357bf5e01f41be73b6b1d4c840cbb8efa233ab772ad1c6c8bd94cff
|
4
|
+
data.tar.gz: 7dc80a7a0268a68302fa74ddc1e0f371a83fba8a77dee2cb38a5ad03c08b3688
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6d4a5e8baadfbd18962a5452e42b2051dff922765fbd2a53dcbe15a415a8e805a031efe18defc70d7360f52701d12b2ddcbbc07a96dc8ae2cffd3c33e121a636
|
7
|
+
data.tar.gz: 83a19e9611e3553faf36663b5676c1abb3bc81af22052014cc250f8230665ce36b98a606a4a834923d2c24d81f7c347fa27ab91171a1cd74ca25a871e81d4e7a
|
data/README.md
CHANGED
@@ -131,6 +131,14 @@ slice_params(*args)
|
|
131
131
|
self.all_associations
|
132
132
|
# returns all associations for a given model
|
133
133
|
# call as: Environment.all_associations
|
134
|
+
|
135
|
+
self.where_like(_hash)
|
136
|
+
# runs .where with your string field made into a wildcard and case insensitive
|
137
|
+
# call as: User.where_like(name: 'jurriaan')
|
138
|
+
|
139
|
+
self.find_by_like(_hash)
|
140
|
+
# runs .find_by with your string field made into a wildcard and case insensitive
|
141
|
+
# call as: User.find_by_like(name: 'jurriaan')
|
134
142
|
```
|
135
143
|
|
136
144
|
|
@@ -309,7 +317,7 @@ Your models should inherit the module Eitil::DefaultScopes through inclusion in
|
|
309
317
|
|
310
318
|
|
311
319
|
|
312
|
-
# Modules
|
320
|
+
# Modules & Classes
|
313
321
|
|
314
322
|
|
315
323
|
|
@@ -336,3 +344,22 @@ Eitil::Dir.lines(directory='app')
|
|
336
344
|
```
|
337
345
|
|
338
346
|
|
347
|
+
|
348
|
+
## Eitil::StackTrace
|
349
|
+
|
350
|
+
### Info
|
351
|
+
|
352
|
+
The two classes Eitil::StackTrace::Stack and Eitil::StackTrace::Call, and the single module Eitil::StackTrace::Audit, provide the utility of easily viewing and storing the current stacktrace anywhere in your code. By initializing stack = Eitil::StackTrace::Stack.new, you can call methods as stack.report (returns the stacktrace as array), stack.show (pretty prints the stacktrace) and stack.find (accepts a block to find a call).
|
353
|
+
|
354
|
+
You can also store the stacktrace of a record's update action into its audit. In order to do so, you need 1) to include Eitil::StackTrace::Audit into your model, and 2) add a :stacktrace column to your audits through the following migration.
|
355
|
+
|
356
|
+
### Migration
|
357
|
+
|
358
|
+
```ruby
|
359
|
+
def change
|
360
|
+
add_column :audits, :stacktrace, :text, array: true, default: []
|
361
|
+
end
|
362
|
+
```
|
363
|
+
|
364
|
+
|
365
|
+
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Eitil::StackTrace::Audit
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
included do
|
4
|
+
|
5
|
+
private
|
6
|
+
|
7
|
+
after_update :add_stacktrace_to_audit
|
8
|
+
|
9
|
+
def add_stacktrace_to_audit
|
10
|
+
stacktrace = Eitil::StackTrace::Stack.new.report
|
11
|
+
self.audits.last.update(stacktrace: stacktrace)
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Eitil::StackTrace
|
2
|
+
class Call
|
3
|
+
|
4
|
+
attr_reader :program, :line, :meth
|
5
|
+
|
6
|
+
CALL_RE = /(.*):(\d+):in `(.*)'/
|
7
|
+
|
8
|
+
def initialize(string)
|
9
|
+
@program, @line, @meth = CALL_RE.match(string).captures
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_s
|
13
|
+
"#{"#{meth}".ljust(50)} #{"(#{line})".ljust(6)} #{program}"
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Eitil::StackTrace
|
2
|
+
class Stack
|
3
|
+
|
4
|
+
attr_reader :stack, :backtrace
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@stack = caller[1..]
|
8
|
+
@backtrace = stack.map { |call| Eitil::StackTrace::Call.new(call) }
|
9
|
+
end
|
10
|
+
|
11
|
+
def report
|
12
|
+
backtrace.map(&:to_s)
|
13
|
+
end
|
14
|
+
|
15
|
+
def show
|
16
|
+
ap report
|
17
|
+
end
|
18
|
+
|
19
|
+
def find(&block)
|
20
|
+
backtrace.find(&block)
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.parse(array_as_string)
|
24
|
+
array_as_string.sub('[', ' ').reverse.sub(']','').reverse.split(',').flatten
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -4,10 +4,24 @@ module ApplicationRecordMonkey
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
included do
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
class << self
|
8
|
+
|
9
|
+
def all_associations
|
10
|
+
reflect_on_all_associations.map do |assoc|
|
11
|
+
{ assoc.name => assoc.association_class.to_s.demodulize }
|
12
|
+
end.inject &:merge
|
13
|
+
end
|
14
|
+
|
15
|
+
def where_like(_hash)
|
16
|
+
column, like = _hash.first
|
17
|
+
where("LOWER(#{column}) LIKE ?", "%#{like.downcase}%")
|
18
|
+
end
|
19
|
+
|
20
|
+
def find_by_like(_hash)
|
21
|
+
column, like = _hash.first
|
22
|
+
find_by("LOWER(#{column}) LIKE ?", "%#{like.downcase}%")
|
23
|
+
end
|
24
|
+
|
11
25
|
end
|
12
26
|
|
13
27
|
end
|
data/lib/eitil/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eitil
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jurriaan Schrofer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-06-
|
11
|
+
date: 2021-06-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -52,6 +52,9 @@ files:
|
|
52
52
|
- app/jobs/eitil/application_job.rb
|
53
53
|
- app/mailers/eitil/application_mailer.rb
|
54
54
|
- app/models/eitil/application_record.rb
|
55
|
+
- app/models/eitil/stack_trace/audit.rb
|
56
|
+
- app/models/eitil/stack_trace/call.rb
|
57
|
+
- app/models/eitil/stack_trace/stack.rb
|
55
58
|
- config/initializers/modules/dir.rb
|
56
59
|
- config/initializers/monkeys/application_controller.rb
|
57
60
|
- config/initializers/monkeys/application_record.rb
|