dhs 1.0.2 → 1.0.3
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/lib/dhs.rb +4 -2
- data/lib/dhs/concerns/autoload_records.rb +17 -14
- data/lib/dhs/railtie.rb +2 -25
- data/lib/dhs/railtie/action_controller_extension.rb +34 -0
- data/lib/dhs/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b7d6af021c9cf582a27709769c0355f5b9c978df218606456887641f7fcf83fc
|
4
|
+
data.tar.gz: 8cc46642942b9804799c74c2568b0dc8d9b131a87f8b2f9fe5615f2b510759e1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8a4620d4f6861dde1bc5cf577fe73f37fca800c4c5758cc0664ef5bd0f2d52b870839275446d5a29cd8b00f5d0fbf518310fdf55f1e40e2bb9c3f169550f766
|
7
|
+
data.tar.gz: 9c6a6ff69bc89e7ee2b84518c7c60ff673bdace69def5ee778ea54f4dd513705eb06d599a218353be7182f9487ac000ed0acad711cc56c8eb34e948817451638
|
data/lib/dhs.rb
CHANGED
@@ -58,10 +58,12 @@ module DHS
|
|
58
58
|
autoload :Unprocessable, 'dhs/unprocessable'
|
59
59
|
|
60
60
|
include Configuration
|
61
|
-
include AutoloadRecords if defined?(Rails)
|
62
61
|
include OptionBlocks
|
63
62
|
|
64
63
|
require 'dhs/record' # as dhs records in an application are directly inheriting it
|
65
64
|
|
66
|
-
|
65
|
+
if defined?(Rails)
|
66
|
+
include AutoloadRecords
|
67
|
+
require 'dhs/railtie'
|
68
|
+
end
|
67
69
|
end
|
@@ -18,6 +18,9 @@ module AutoloadRecords
|
|
18
18
|
end
|
19
19
|
|
20
20
|
class Middleware
|
21
|
+
|
22
|
+
MODEL_FILES = 'app/models/**/*.rb'
|
23
|
+
|
21
24
|
def initialize(app)
|
22
25
|
@app = app
|
23
26
|
end
|
@@ -27,24 +30,24 @@ module AutoloadRecords
|
|
27
30
|
@app.call(env)
|
28
31
|
end
|
29
32
|
|
30
|
-
def self.model_files
|
31
|
-
Dir.glob(Rails.root.join('app', 'models', '**', '*.rb'))
|
32
|
-
end
|
33
|
-
|
34
33
|
def self.require_direct_inheritance
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
34
|
+
Rails.application.reloader.to_prepare do
|
35
|
+
Dir.glob(Rails.root.join(MODEL_FILES)).each do |file|
|
36
|
+
next unless File.read(file).match('DHS::Record')
|
37
|
+
require_dependency file
|
38
|
+
file.split('models/').last.gsub('.rb', '').classify
|
39
|
+
end.compact
|
40
|
+
end
|
40
41
|
end
|
41
42
|
|
42
43
|
def self.require_inheriting_records(parents)
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
44
|
+
Rails.application.reloader.to_prepare do
|
45
|
+
Dir.glob(Rails.root.join(MODEL_FILES)).each do |file|
|
46
|
+
file_content = File.read(file)
|
47
|
+
next if parents.none? { |parent| file_content.match(/\b#{parent}\b/) }
|
48
|
+
next if file_content.match?('extend ActiveSupport::Concern')
|
49
|
+
require_dependency file
|
50
|
+
end
|
48
51
|
end
|
49
52
|
end
|
50
53
|
|
data/lib/dhs/railtie.rb
CHANGED
@@ -3,31 +3,8 @@
|
|
3
3
|
module DHS
|
4
4
|
class Railtie < Rails::Railtie
|
5
5
|
initializer 'dhs.hook_into_controller_initialization' do
|
6
|
-
|
7
|
-
|
8
|
-
def initialize
|
9
|
-
prepare_dhs_request_cycle_cache
|
10
|
-
reset_option_blocks
|
11
|
-
reset_extended_rollbar_request_logs
|
12
|
-
super
|
13
|
-
end
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
def prepare_dhs_request_cycle_cache
|
18
|
-
return unless DHS.config.request_cycle_cache_enabled
|
19
|
-
DHS::Interceptors::RequestCycleCache::ThreadRegistry.request_id = [Time.now.to_f, request.object_id].join('#')
|
20
|
-
end
|
21
|
-
|
22
|
-
def reset_option_blocks
|
23
|
-
DHS::OptionBlocks::CurrentOptionBlock.options = nil
|
24
|
-
end
|
25
|
-
|
26
|
-
def reset_extended_rollbar_request_logs
|
27
|
-
return unless defined?(::Rollbar)
|
28
|
-
return unless DHC.config.interceptors.include?(DHS::Interceptors::ExtendedRollbar::Interceptor)
|
29
|
-
DHS::Interceptors::ExtendedRollbar::ThreadRegistry.log = []
|
30
|
-
end
|
6
|
+
Rails.application.reloader.to_prepare do
|
7
|
+
require_relative 'railtie/action_controller_extension'
|
31
8
|
end
|
32
9
|
end
|
33
10
|
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module DHS
|
4
|
+
class Railtie < Rails::Railtie
|
5
|
+
|
6
|
+
class ::ActionController::Base
|
7
|
+
|
8
|
+
def initialize
|
9
|
+
prepare_dhs_request_cycle_cache
|
10
|
+
reset_option_blocks
|
11
|
+
reset_extended_rollbar_request_logs
|
12
|
+
super
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def prepare_dhs_request_cycle_cache
|
18
|
+
return unless DHS.config.request_cycle_cache_enabled
|
19
|
+
DHS::Interceptors::RequestCycleCache::ThreadRegistry.request_id = [Time.now.to_f, request.object_id].join('#')
|
20
|
+
end
|
21
|
+
|
22
|
+
def reset_option_blocks
|
23
|
+
DHS::OptionBlocks::CurrentOptionBlock.options = nil
|
24
|
+
end
|
25
|
+
|
26
|
+
def reset_extended_rollbar_request_logs
|
27
|
+
return unless defined?(::Rollbar)
|
28
|
+
return unless DHC.config.interceptors.include?(DHS::Interceptors::ExtendedRollbar::Interceptor)
|
29
|
+
DHS::Interceptors::ExtendedRollbar::ThreadRegistry.log = []
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
data/lib/dhs/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dhs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- https://github.com/DePayFi/dhs/graphs/contributors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-04-
|
11
|
+
date: 2021-04-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -333,6 +333,7 @@ files:
|
|
333
333
|
- lib/dhs/problems/warnings.rb
|
334
334
|
- lib/dhs/proxy.rb
|
335
335
|
- lib/dhs/railtie.rb
|
336
|
+
- lib/dhs/railtie/action_controller_extension.rb
|
336
337
|
- lib/dhs/record.rb
|
337
338
|
- lib/dhs/rspec.rb
|
338
339
|
- lib/dhs/test/stubbable_records.rb
|