Skip to content

Commit

Permalink
Allow registering OutputFormats without file extension
Browse files Browse the repository at this point in the history
  • Loading branch information
moozzi committed Aug 31, 2024
1 parent 9478d68 commit b7d151a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/ronin/core/output_formats.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ def file_exts
#
# Registers a new output format.
#
def register(name,ext,output_format)
def register(name,ext=nil,output_format)
formats[name] = output_format
file_exts[ext] = output_format
file_exts[ext] = output_format if ext
end

#
Expand Down
28 changes: 28 additions & 0 deletions spec/output_formats_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ module OutputFormats
register :json, '.json', JSON
register :ndjson, '.ndjson', NDJSON
end

class NoExtOutputFormat < Ronin::Core::OutputFormats::OutputFile; end

module NoExtOutputFormats
include Ronin::Core::OutputFormats

register :no_ext, NoExtOutputFormat
end
end

subject { TestOutputFormats::EmptyOutputFormats }
Expand Down Expand Up @@ -66,6 +74,14 @@ module OutputFormats
)
end
end

context "when output formats without extension have been registered" do
subject { TestOutputFormats::NoExtOutputFormats }

it "must return an empty Hash" do
expect(subject.file_exts).to eq({})
end
end
end

describe ".register" do
Expand All @@ -78,6 +94,18 @@ module OutputFormats
it "must register the output format in #file_exts with the given ext" do
expect(subject.file_exts['.txt']).to be(described_class::TXT)
end

context "without file extension" do
subject { TestOutputFormats::NoExtOutputFormats }

it "must register the output format in #formats with the given name" do
expect(subject.formats[:no_ext]).to be(TestOutputFormats::NoExtOutputFormat)
end

it "must not register the output format in #file_exts" do
expect(subject.file_exts).to eq({})
end
end
end

describe ".infer_from" do
Expand Down

0 comments on commit b7d151a

Please sign in to comment.