Skip to content

Commit ceaffce

Browse files
committed
Merge branch 'pr/3593' into staging/electro-release
2 parents e6a0e07 + 7cc5af5 commit ceaffce

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

lib/metasploit/framework/command/base.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,11 @@ def self.require_environment!
4949
parsed_options.environment!
5050
ARGV.replace(parsed_options.positional)
5151

52-
# @see https://github.com/rails/rails/blob/v3.2.17/railties/lib/rails/commands.rb#L39-L40
53-
require Pathname.new(__FILE__).parent.parent.parent.parent.parent.join('config', 'application')
52+
# allow other Rails::Applications to use this command
53+
if !defined?(Rails) || Rails.application.nil?
54+
# @see https://github.com/rails/rails/blob/v3.2.17/railties/lib/rails/commands.rb#L39-L40
55+
require Pathname.new(__FILE__).parent.parent.parent.parent.parent.join('config', 'application')
56+
end
5457

5558
# have to configure before requiring environment because
5659
# config/environment.rb calls initialize! and the initializers will use

lib/metasploit/framework/parsed_options/base.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def configure(application)
5757
#
5858
# @return [void]
5959
def environment!
60-
if defined?(Rails) && Rails.instance_variable_defined?(:@_env)
60+
if defined?(Rails) && Rails.instance_variable_defined?(:@_env) && Rails.env != options.environment
6161
raise "#{self.class}##{__method__} called too late to set RAILS_ENV: Rails.env already memoized"
6262
end
6363

@@ -85,14 +85,16 @@ def options
8585
options.database.disable = false
8686
options.database.migrations_paths = []
8787

88+
# If RAILS_ENV is set, then it will be used, but if RAILS_ENV is set and the --environment option is given, then
89+
# --environment value will be used to reset ENV[RAILS_ENV].
90+
options.environment = ENV['RAILS_ENV'] || DEFAULT_ENVIRONMENT
91+
8892
options.framework = ActiveSupport::OrderedOptions.new
8993
options.framework.config = nil
9094

9195
options.modules = ActiveSupport::OrderedOptions.new
9296
options.modules.path = nil
9397

94-
options.environment = DEFAULT_ENVIRONMENT
95-
9698
@options = options
9799
end
98100

0 commit comments

Comments
 (0)