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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 92cb9e9c82e5a3bfac7cbc0b5f662428bac557a2c3abbca8e30c86d60174363a
4
- data.tar.gz: 20c072c5d8b8ce2e055ff0635472a66fdb11ba4155d770ac3cd600be0c0892da
3
+ metadata.gz: 24a0dccf0357bf5e01f41be73b6b1d4c840cbb8efa233ab772ad1c6c8bd94cff
4
+ data.tar.gz: 7dc80a7a0268a68302fa74ddc1e0f371a83fba8a77dee2cb38a5ad03c08b3688
5
5
  SHA512:
6
- metadata.gz: 945e8da34ffe7c89a24c11d2c4f75f2861ed9355ed0ed0c6759cc57d63485d7bb37006be1c4cb4f1fa8c93d13a672b238f4c99ec3110001db917cdc4cc2e02e0
7
- data.tar.gz: d0a0641152e75e6f100eda08f83a3b253d8d80dd570fb26d76a2649822180e0f3c834da64012bb5d0e61709163fc81dbc7986ec5fa04d8d74faa8fd6a7f290a9
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
- def self.all_associations
8
- reflect_on_all_associations.map do |assoc|
9
- { assoc.name => assoc.association_class.to_s.demodulize }
10
- end.inject &:merge
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
@@ -1,3 +1,3 @@
1
1
  module Eitil
2
- VERSION = '0.3.6'
2
+ VERSION = '0.3.7'
3
3
  end
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.6
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-01 00:00:00.000000000 Z
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