Skip to content

Commit a2b1dbb

Browse files
committed
avoid clashes between Environment class methods
Fixes #10860
1 parent 7b9877a commit a2b1dbb

File tree

5 files changed

+15
-11
lines changed

5 files changed

+15
-11
lines changed

lib/bootstrap/environment.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def oss_only?
4242
!File.exists?(File.join(LogStash::Environment::LOGSTASH_HOME, "x-pack"))
4343
end
4444

45-
def windows?
45+
def win_platform?
4646
::Gem.win_platform?
4747
end
4848

lib/pluginmanager/pack.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
require_relative "pack_command"
33

44
class LogStash::PluginManager::Pack < LogStash::PluginManager::PackCommand
5-
option "--tgz", :flag, "compress package as a tar.gz file", :default => !LogStash::Environment.windows?
6-
option "--zip", :flag, "compress package as a zip file", :default => LogStash::Environment.windows?
5+
option "--tgz", :flag, "compress package as a tar.gz file", :default => !LogStash::Environment.win_platform?
6+
option "--zip", :flag, "compress package as a zip file", :default => LogStash::Environment.win_platform?
77
option "--[no-]clean", :flag, "clean up the generated dump of plugins", :default => true
88
option "--overwrite", :flag, "Overwrite a previously generated package file", :default => false
99

lib/pluginmanager/unpack.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
require_relative "pack_command"
33

44
class LogStash::PluginManager::Unpack < LogStash::PluginManager::PackCommand
5-
option "--tgz", :flag, "unpack a packaged tar.gz file", :default => !LogStash::Environment.windows?
6-
option "--zip", :flag, "unpack a packaged zip file", :default => LogStash::Environment.windows?
5+
option "--tgz", :flag, "unpack a packaged tar.gz file", :default => !LogStash::Environment.win_platform?
6+
option "--zip", :flag, "unpack a packaged zip file", :default => LogStash::Environment.win_platform?
77

88
parameter "file", "the package file name", :attribute_name => :package_file, :required => true
99

logstash-core/lib/logstash/environment.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,15 @@ def ruby_bin
164164
end
165165

166166
def windows?
167-
RbConfig::CONFIG['host_os'] =~ WINDOW_OS_RE
167+
host_os =~ WINDOW_OS_RE
168168
end
169169

170170
def linux?
171-
RbConfig::CONFIG['host_os'] =~ LINUX_OS_RE
171+
host_os =~ LINUX_OS_RE
172+
end
173+
174+
def host_os
175+
RbConfig::CONFIG['host_os']
172176
end
173177

174178
def locales_path(path)

logstash-core/spec/logstash/environment_spec.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,14 @@
5757
context "windows" do
5858
windows_host_os.each do |host|
5959
it "#{host} returns true" do
60-
expect(RbConfig::CONFIG).to receive(:[]).with("host_os").and_return(host)
60+
allow(LogStash::Environment).to receive(:host_os).and_return(host)
6161
expect(LogStash::Environment.windows?).to be_truthy
6262
end
6363
end
6464

6565
linux_host_os.each do |host|
6666
it "#{host} returns false" do
67-
expect(RbConfig::CONFIG).to receive(:[]).with("host_os").and_return(host)
67+
allow(LogStash::Environment).to receive(:host_os).and_return(host)
6868
expect(LogStash::Environment.windows?).to be_falsey
6969
end
7070
end
@@ -73,14 +73,14 @@
7373
context "Linux" do
7474
windows_host_os.each do |host|
7575
it "#{host} returns true" do
76-
expect(RbConfig::CONFIG).to receive(:[]).with("host_os").and_return(host)
76+
allow(LogStash::Environment).to receive(:host_os).and_return(host)
7777
expect(LogStash::Environment.linux?).to be_falsey
7878
end
7979
end
8080

8181
linux_host_os.each do |host|
8282
it "#{host} returns false" do
83-
expect(RbConfig::CONFIG).to receive(:[]).with("host_os").and_return(host)
83+
allow(LogStash::Environment).to receive(:host_os).and_return(host)
8484
expect(LogStash::Environment.linux?).to be_truthy
8585
end
8686
end

0 commit comments

Comments
 (0)