Skip to content

Commit

Permalink
chore: rubocop
Browse files Browse the repository at this point in the history
  • Loading branch information
ronaldtse committed Jul 22, 2024
1 parent 96a04e4 commit cf946e7
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 35 deletions.
6 changes: 1 addition & 5 deletions .github/workflows/rake.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Auto-generated by Cimas: Do not edit it manually!
# See https://github.com/metanorma/cimas
name: rake

on:
Expand All @@ -11,6 +9,4 @@ on:

jobs:
rake:
uses: metanorma/ci/.github/workflows/generic-rake.yml@main
secrets:
pat_token: ${{ secrets.METANORMA_CI_PAT_TOKEN }}
uses: metanorma/ci/.github/workflows/graphviz-rake.yml@main
7 changes: 3 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# Auto-generated by Cimas: Do not edit it manually!
# See https://github.com/metanorma/cimas
name: release

on:
Expand All @@ -19,5 +17,6 @@ jobs:
with:
next_version: ${{ github.event.inputs.next_version }}
secrets:
rubygems-api-key: ${{ secrets.METANORMA_CI_RUBYGEMS_API_KEY }}
pat_token: ${{ secrets.METANORMA_CI_PAT_TOKEN }}
rubygems-api-key: ${{ secrets.LUTAML_CI_RUBYGEMS_API_KEY }}
pat_token: ${{ secrets.LUTAML_CI_PAT_TOKEN }}

5 changes: 4 additions & 1 deletion lib/poepod/cli.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# lib/poepod/cli.rb
require "thor"
require_relative "file_processor"
Expand Down Expand Up @@ -27,7 +29,8 @@ def concat(*files, output_file: nil)
end

desc "wrap GEMSPEC_PATH", "Wrap a gem based on its gemspec file"
option :include_unstaged, type: :boolean, default: false, desc: "Include unstaged files from lib, spec, and test directories"
option :include_unstaged, type: :boolean, default: false,
desc: "Include unstaged files from lib, spec, and test directories"

def wrap(gemspec_path)
processor = Poepod::GemProcessor.new(gemspec_path, nil, options[:include_unstaged])
Expand Down
26 changes: 14 additions & 12 deletions lib/poepod/file_processor.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require_relative "processor"
require "yaml"
require "tqdm"
Expand All @@ -9,7 +11,7 @@
module Poepod
class FileProcessor < Processor
EXCLUDE_DEFAULT = [
/node_modules\//, /.git\//, /.gitignore$/, /.DS_Store$/,
%r{node_modules/}, %r{.git/}, /.gitignore$/, /.DS_Store$/
].freeze

def initialize(files, output_file, config_file = nil, include_binary = false)
Expand All @@ -27,17 +29,17 @@ def process
File.open(@output_file, "w", encoding: "utf-8") do |output|
@files.each do |file|
Dir.glob(file).each do |matched_file|
if File.file?(matched_file)
total_files += 1
file_path, content, error = process_file(matched_file)
if content
output.puts "--- START FILE: #{file_path} ---"
output.puts content
output.puts "--- END FILE: #{file_path} ---"
copied_files += 1
elsif error
output.puts "#{file_path}\n#{error}"
end
next unless File.file?(matched_file)

total_files += 1
file_path, content, error = process_file(matched_file)
if content
output.puts "--- START FILE: #{file_path} ---"
output.puts content
output.puts "--- END FILE: #{file_path} ---"
copied_files += 1
elsif error
output.puts "#{file_path}\n#{error}"
end
end
end
Expand Down
16 changes: 9 additions & 7 deletions lib/poepod/gem_processor.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# lib/poepod/gem_processor.rb
require_relative "processor"
require "rubygems/specification"
Expand All @@ -18,7 +20,7 @@ def process

begin
spec = Gem::Specification.load(@gemspec_path)
rescue => e
rescue StandardError => e
return [false, "Error loading gemspec: #{e.message}"]
end

Expand All @@ -43,11 +45,11 @@ def process

files_to_include.uniq.each do |relative_path|
full_path = File.join(File.dirname(@gemspec_path), relative_path)
if File.file?(full_path)
file.puts "--- START FILE: #{relative_path} ---"
file.puts File.read(full_path)
file.puts "--- END FILE: #{relative_path} ---\n\n"
end
next unless File.file?(full_path)

file.puts "--- START FILE: #{relative_path} ---"
file.puts File.read(full_path)
file.puts "--- END FILE: #{relative_path} ---\n\n"
end
end

Expand All @@ -58,7 +60,7 @@ def process

def find_readme_files
Dir.glob(File.join(File.dirname(@gemspec_path), "README*"))
.map { |path| Pathname.new(path).relative_path_from(Pathname.new(File.dirname(@gemspec_path))).to_s }
.map { |path| Pathname.new(path).relative_path_from(Pathname.new(File.dirname(@gemspec_path))).to_s }
end

def check_unstaged_files
Expand Down
2 changes: 2 additions & 0 deletions lib/poepod/processor.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# lib/poepod/processor.rb
module Poepod
class Processor
Expand Down
4 changes: 2 additions & 2 deletions poepod.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,11 @@ Gem::Specification.new do |spec|
spec.require_paths = ["lib"]
spec.test_files = `git ls-files -- spec/*`.split("\n")

spec.add_runtime_dependency "git", "~> 1.11"
spec.add_runtime_dependency "mime-types", "~> 3.3"
spec.add_runtime_dependency "parallel", "~> 1.20"
spec.add_runtime_dependency "thor", "~> 1.0"
spec.add_runtime_dependency "tqdm"
spec.add_runtime_dependency "mime-types", "~> 3.3"
spec.add_runtime_dependency "git", "~> 1.11"

spec.add_development_dependency "rake"
spec.add_development_dependency "rspec"
Expand Down
16 changes: 13 additions & 3 deletions spec/poepod/cli_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require "spec_helper"
require "poepod/cli"

Expand Down Expand Up @@ -27,12 +29,18 @@

it "excludes binary files by default" do
output_file = File.join(temp_dir, "output.txt")
expect { cli.concat(text_file, binary_file, output_file: output_file) }.to output(/-> 2 files detected\.\n=> 1 files have been concatenated into.*\.txt/).to_stdout
expect do
cli.concat(text_file, binary_file,
output_file: output_file)
end.to output(/-> 2 files detected\.\n=> 1 files have been concatenated into.*\.txt/).to_stdout
end

it "includes binary files when specified" do
output_file = File.join(temp_dir, "output.txt")
expect { cli.invoke(:concat, [text_file, binary_file], output_file: output_file, include_binary: true) }.to output(/-> 2 files detected\.\n=> 2 files have been concatenated into.*\.txt/).to_stdout
expect do
cli.invoke(:concat, [text_file, binary_file], output_file: output_file,
include_binary: true)
end.to output(/-> 2 files detected\.\n=> 2 files have been concatenated into.*\.txt/).to_stdout
end
end

Expand Down Expand Up @@ -74,7 +82,9 @@
end

it "handles non-existent gemspec" do
expect { cli.wrap("non_existent.gemspec") }.to output(/Error: The specified gemspec file/).to_stdout.and raise_error(SystemExit)
expect do
cli.wrap("non_existent.gemspec")
end.to output(/Error: The specified gemspec file/).to_stdout.and raise_error(SystemExit)
end
end
end
2 changes: 2 additions & 0 deletions spec/poepod/file_processor_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# spec/poepod/file_processor_spec.rb
require "spec_helper"
require "poepod/file_processor"
Expand Down
4 changes: 3 additions & 1 deletion spec/poepod/gem_processor_spec.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

# spec/poepod/gem_processor_spec.rb
require "spec_helper"
require "poepod/gem_processor"
Expand Down Expand Up @@ -103,7 +105,7 @@
"spec/test_gem_spec.rb" => "RSpec.describe TestGem do\nend",
"README.md" => "# Test Gem\n\nThis is a test gem.",
"README.txt" => "Test Gem\n\nThis is a test gem in plain text.",
"lib/unstaged_file.rb" => "Unstaged content",
"lib/unstaged_file.rb" => "Unstaged content"
}

# Mock File.read
Expand Down

0 comments on commit cf946e7

Please sign in to comment.