File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -60,6 +60,11 @@ def self.require_environment!
60
60
# the configuration from the parsed options.
61
61
parsed_options . configure ( Rails . application )
62
62
63
+ # support disabling the database
64
+ unless parsed_options . options . database . disable
65
+ Metasploit ::Framework ::Require . optionally_active_record_railtie
66
+ end
67
+
63
68
Rails . application . require_environment!
64
69
65
70
parsed_options
Original file line number Diff line number Diff line change @@ -34,6 +34,31 @@ def self.optionally(name, without_warning)
34
34
end
35
35
end
36
36
37
+ # Tries to `require 'active_record/railtie'` to define the activerecord Rails initializers and rake tasks.
38
+ #
39
+ # @example Optionally requiring 'active_record/railtie'
40
+ # require 'metasploit/framework/require'
41
+ #
42
+ # class MyClass
43
+ # def setup
44
+ # if database_enabled
45
+ # Metasploit::Framework::Require.optionally_active_record_railtie
46
+ # end
47
+ # end
48
+ # end
49
+ #
50
+ # @return [void]
51
+ def self . optionally_active_record_railtie
52
+ if ::File . exist? ( Rails . application . config . paths [ 'config/database' ] . first )
53
+ optionally (
54
+ 'active_record/railtie' ,
55
+ 'activerecord not in the bundle, so database support will be disabled.'
56
+ )
57
+ else
58
+ warn 'Could not find database.yml, so database support will be disabled.'
59
+ end
60
+ end
61
+
37
62
# Tries to `require 'metasploit/credential/creation'` and include it in the `including_module`.
38
63
#
39
64
# @param including_module [Module] `Class` or `Module` that wants to `include Metasploit::Credential::Creation`.
You can’t perform that action at this time.
0 commit comments