Skip to content

Commit

Permalink
avoid clashes between Environment class methods
Browse files Browse the repository at this point in the history
Fixes #10860
  • Loading branch information
jsvd committed Jun 14, 2019
1 parent 7b9877a commit a2b1dbb
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/bootstrap/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def oss_only?
!File.exists?(File.join(LogStash::Environment::LOGSTASH_HOME, "x-pack"))
end

def windows?
def win_platform?
::Gem.win_platform?
end

Expand Down
4 changes: 2 additions & 2 deletions lib/pluginmanager/pack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
require_relative "pack_command"

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

Expand Down
4 changes: 2 additions & 2 deletions lib/pluginmanager/unpack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
require_relative "pack_command"

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

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

Expand Down
8 changes: 6 additions & 2 deletions logstash-core/lib/logstash/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,15 @@ def ruby_bin
end

def windows?
RbConfig::CONFIG['host_os'] =~ WINDOW_OS_RE
host_os =~ WINDOW_OS_RE
end

def linux?
RbConfig::CONFIG['host_os'] =~ LINUX_OS_RE
host_os =~ LINUX_OS_RE
end

def host_os
RbConfig::CONFIG['host_os']
end

def locales_path(path)
Expand Down
8 changes: 4 additions & 4 deletions logstash-core/spec/logstash/environment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@
context "windows" do
windows_host_os.each do |host|
it "#{host} returns true" do
expect(RbConfig::CONFIG).to receive(:[]).with("host_os").and_return(host)
allow(LogStash::Environment).to receive(:host_os).and_return(host)
expect(LogStash::Environment.windows?).to be_truthy
end
end

linux_host_os.each do |host|
it "#{host} returns false" do
expect(RbConfig::CONFIG).to receive(:[]).with("host_os").and_return(host)
allow(LogStash::Environment).to receive(:host_os).and_return(host)
expect(LogStash::Environment.windows?).to be_falsey
end
end
Expand All @@ -73,14 +73,14 @@
context "Linux" do
windows_host_os.each do |host|
it "#{host} returns true" do
expect(RbConfig::CONFIG).to receive(:[]).with("host_os").and_return(host)
allow(LogStash::Environment).to receive(:host_os).and_return(host)
expect(LogStash::Environment.linux?).to be_falsey
end
end

linux_host_os.each do |host|
it "#{host} returns false" do
expect(RbConfig::CONFIG).to receive(:[]).with("host_os").and_return(host)
allow(LogStash::Environment).to receive(:host_os).and_return(host)
expect(LogStash::Environment.linux?).to be_truthy
end
end
Expand Down

0 comments on commit a2b1dbb

Please sign in to comment.