sha256_everything 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 688fe76f244135f722701b6b7e11b0bc9cea9eab7bf64c2be65178437b20f3ae
4
+ data.tar.gz: cf5b03d7cc0b6963b026217026ac466e87f8e44c81fe393093263d04f112ec0e
5
+ SHA512:
6
+ metadata.gz: 65fd64a6592fb62d6abecb35770074d1b099d6e02755457d7085fbdcec9b3e5467c45c9e9ca2043c0719d038cc9e5c7917bb98cd309f1a79e10a17cc29e88781
7
+ data.tar.gz: 8374bb33199253e24d41e2e7d0e322cb73e0af96546d80b9de2bdc44b4a5e5e4ef37a7283c628e96933116cc7b34beab1584815f764ded359a75f77284b90b00
data/README.md ADDED
@@ -0,0 +1,77 @@
1
+ # sha256_everything
2
+
3
+ **sha256_everything** is a Ruby gem that hashes every single file in a specified directory and outputs the result in a neatly formatted TXT file.
4
+
5
+ ## Example Output
6
+
7
+ ```
8
+ File Hierarchy SHA256 Hash
9
+
10
+ ├── .gitignore 1e152031a561398186651a06090f3b08e0c0abb486fd516524e93ec4e57c1cc3
11
+ ├── .rspec 06245e25d7cf46b4fbde27b5faa0df0d4110e11918eeb5848de4ab2aff897b59
12
+ ├── CODE_OF_CONDUCT.md f02b057ee644a4f7e722156b8497d6b8932101ca2083425d829790797d6f538f
13
+ ├── Gemfile 81d62526d923ef3a2b684a4dfa9b3a76eebe03a0fc037268f2763165a52b03a4
14
+ ├── lib
15
+ │ ├── sha256_everything
16
+ │ │ ├── application.rb 54b5b8713c27fbc2d61af29a2f7851dc174da80339735013c645a619eb710e5d
17
+ │ │ ├── cli.rb d5f9993b29c6adc1569718d17ae10692eb40393019f34673993a3a37b6eaa1d0
18
+ │ │ ├── file_collector.rb 095e96607d636b7392a6201799dc5b54e8bd5a4b0251534091bdb22a16eb0ebd
19
+ │ │ ├── file_hasher.rb 24baecab98a3143a5f292bcd8bb3e85ea29472f0552b65eec08d7581825d1f65
20
+ │ │ ├── output_writer.rb bb7830388ca1f7ab4faf641508cef101691809b83c3bc0496644c288cac8d3a8
21
+ │ │ ├── tree_generator.rb 448522451bb7a8b52e5bf4f797e3e97a3b443729b660d4b0e1b8e2bf07d0f794
22
+ │ │ └── version.rb 0507bfc041b1fff564afc4fd5e7c293d84b8eb8e53fbd398735c9d6a7625dca3
23
+ │ └── sha256_everything.rb a458e489aab5eecc4cb328b5ea04e5a2f4cad5872579f62a7faf4ceec10b9011
24
+
25
+ ```
26
+
27
+ ## Features
28
+
29
+ - **Recursive Processing:** Scans and hashes all files (including hidden ones) while skipping internal directories (like `.git`).
30
+ - **Live Progress:** A dynamic progress bar keeps you informed as each file is hashed.
31
+ - **Formatted Output:** Produces a prettified result showing the file hierarchy and corresponding SHA256 hashes.
32
+
33
+ ## Installation
34
+
35
+ Install it directly via:
36
+
37
+ ```bash
38
+ gem install sha256_everything
39
+ ```
40
+
41
+ ## Usage
42
+
43
+ After installation, you can run the gem's command from your terminal:
44
+
45
+ ```bash
46
+ sha256_everything
47
+ ```
48
+
49
+ ### Options
50
+
51
+ - `-f [NAME]`, `--filename [NAME]` — Specify the output file name (default: hashes.txt).
52
+ - `-d`, `--display_here` — Display the file hierarchy in the terminal.
53
+ - `-h`, `--help` — Show help and usage instructions.
54
+
55
+ ## Testing
56
+
57
+ ```bash
58
+ bundle install
59
+ bundle exec rspec
60
+ ```
61
+
62
+ ## Contributing
63
+
64
+ Contributions, bug reports, and pull requests are welcome!
65
+ Feel free to check issues or submit your own at [GitHub Issues](https://github.com/jibril-tapiador/sha256_everything/issues).
66
+
67
+ ## License
68
+
69
+ This gem is available as open source under the terms of the [MIT License](LICENSE).
70
+
71
+ ## Authors
72
+
73
+ - **Jibril Tapiador** - [tapiador@jib.is](mailto:tapiador@jib.is)
74
+
75
+ ## Acknowledgements
76
+
77
+ - Thanks to [ruby-progressbar](https://github.com/jfelchner/ruby-progressbar) for the progress bar implementation.
data/bin/console ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "sha256_everything"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ require "irb"
11
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../lib/sha256_everything'
3
+
4
+ Sha256Everything::CLI.start
@@ -0,0 +1,30 @@
1
+ require 'ruby-progressbar'
2
+
3
+ module Sha256Everything
4
+ class Application
5
+ def initialize(options)
6
+ @directory = options.fetch(:directory, Dir.pwd)
7
+ file_name = options.fetch(:filename, "hashes.txt")
8
+ @output_file = file_name.end_with?(".txt") ? file_name : "#{file_name}.txt"
9
+ @display = options.fetch(:display_here, false)
10
+ end
11
+
12
+ def run
13
+ files = FileCollector.new(@directory).files
14
+ progress = ProgressBar.create(total: files.size, format: '%a %B %p%% %t')
15
+ results = files.each_with_object({}) do |file, memo|
16
+ memo[file] = FileHasher.new(file).compute
17
+ progress.increment
18
+ end
19
+
20
+ # Generate formatted tree (including hash values)
21
+ tree = TreeGenerator.new(@directory, results).generate
22
+ OutputWriter.new(@output_file, tree).write
23
+
24
+ # Display message after progress bar finishes
25
+ puts "\n\nHash file saved as #{@output_file}"
26
+ puts "\n" if @display
27
+ puts tree if @display
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,33 @@
1
+ require 'optparse'
2
+
3
+ module Sha256Everything
4
+ class CLI
5
+ def self.start(args = ARGV)
6
+ options = parse_options(args)
7
+ Application.new(options).run
8
+ end
9
+
10
+ def self.parse_options(args)
11
+ # Set default options
12
+ options = { filename: 'hashes.txt', display_here: false, directory: Dir.pwd }
13
+ parser = OptionParser.new do |opts|
14
+ opts.banner = 'Usage: sha256_everything [options]'
15
+
16
+ opts.on('-fNAME', '--filename=NAME', 'Set the output file name') do |name|
17
+ options[:filename] = name
18
+ end
19
+
20
+ opts.on('-d', '--display_here', 'Display the file hierarchy in the terminal') do
21
+ options[:display_here] = true
22
+ end
23
+
24
+ opts.on('-h', '--help', 'Prints this help') do
25
+ puts opts
26
+ exit
27
+ end
28
+ end
29
+ parser.parse!(args)
30
+ options
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,23 @@
1
+ module Sha256Everything
2
+ class FileCollector
3
+ IGNORED_DIRECTORIES = ['.git'].freeze
4
+
5
+ def initialize(directory)
6
+ @directory = directory
7
+ end
8
+
9
+ def files
10
+ pattern = File.join(@directory, '**', '{*,.*}')
11
+ Dir.glob(pattern, File::FNM_DOTMATCH)
12
+ .reject { |f| ignore?(f) }
13
+ .select { |f| File.file?(f) }
14
+ end
15
+
16
+ private
17
+
18
+ def ignore?(file)
19
+ path_components = file.split(File::SEPARATOR)
20
+ (path_components & IGNORED_DIRECTORIES).any?
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,15 @@
1
+ require 'digest'
2
+
3
+ module Sha256Everything
4
+ class FileHasher
5
+ def initialize(file)
6
+ @file = file
7
+ end
8
+
9
+ def compute
10
+ Digest::SHA256.file(@file).hexdigest
11
+ rescue StandardError => e
12
+ "Error: #{e.message}"
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ module Sha256Everything
2
+ class OutputWriter
3
+ def initialize(filename, tree_str)
4
+ @filename = filename
5
+ @tree_str = tree_str
6
+ end
7
+
8
+ def write
9
+ File.open(@filename, 'w') do |f|
10
+ f.puts @tree_str
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,49 @@
1
+ module Sha256Everything
2
+ class TreeGenerator
3
+ IGNORED_DIRECTORIES = ['.git'].freeze
4
+
5
+ def initialize(root, results = {})
6
+ @root = root
7
+ @results = results
8
+ end
9
+
10
+ def generate
11
+ lines = generate_lines(@root)
12
+ max_length = lines.map { |line| line[:left].length }.max || 0
13
+ header_left = 'File Hierarchy'
14
+ header_right = 'SHA256 Hash'
15
+ header_line = header_left.ljust(max_length + 4) + header_right
16
+ tree_str = header_line + "\n\n"
17
+ lines.each do |line|
18
+ tree_str << line[:left].ljust(max_length + 4) + line[:right] + "\n"
19
+ end
20
+ tree_str
21
+ end
22
+
23
+ private
24
+
25
+ def generate_lines(base, prefix = '')
26
+ entries = visible_entries(base)
27
+ lines = []
28
+ entries.each_with_index do |entry, index|
29
+ path = File.join(base, entry)
30
+ connector = (index == entries.size - 1) ? "└── " : "├── "
31
+ left_text = "#{prefix}#{connector}#{entry}"
32
+ if File.file?(path)
33
+ hash_value = @results[path] || '-'
34
+ lines << { left: left_text, right: hash_value }
35
+ else
36
+ lines << { left: left_text, right: '' }
37
+ extension = (index == entries.size - 1) ? " " : "│ "
38
+ lines.concat(generate_lines(path, prefix + extension))
39
+ end
40
+ end
41
+ lines
42
+ end
43
+
44
+ def visible_entries(base)
45
+ entries = Dir.entries(base) - %w[. ..]
46
+ entries.reject { |entry| IGNORED_DIRECTORIES.include?(entry) }.sort
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Sha256Everything
4
+ VERSION = '1.0.0'
5
+ end
@@ -0,0 +1,16 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'sha256_everything/version'
4
+
5
+ require 'sha256_everything/version'
6
+ require 'sha256_everything/cli'
7
+ require 'sha256_everything/application'
8
+ require 'sha256_everything/file_collector'
9
+ require 'sha256_everything/file_hasher'
10
+ require 'sha256_everything/tree_generator'
11
+ require 'sha256_everything/output_writer'
12
+
13
+ module Sha256Everything
14
+ class Error < StandardError; end
15
+ # Your code goes here...
16
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/sha256_everything/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'sha256_everything'
7
+ spec.version = '1.0.0'
8
+ spec.authors = ['Jibril Tapiador']
9
+ spec.email = ['tapiador@jib.is']
10
+
11
+ spec.summary = 'Hashes every file in a directory using SHA256'
12
+ spec.description = 'A gem that iterates over each file in a folder, computes its SHA256 hash, and writes a prettified file hierarchy to a text file.'
13
+ spec.homepage = 'https://github.com/jibril-tapiador/sha256_everything'
14
+ spec.license = 'MIT'
15
+
16
+ spec.files = Dir['lib/**/*', 'bin/*', 'README.md', 'LICENSE', '*.gemspec']
17
+ spec.executables = ['sha256_everything']
18
+ spec.require_paths = ['lib']
19
+
20
+ spec.add_dependency 'ruby-progressbar', '~> 1.10'
21
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sha256_everything
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jibril Tapiador
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2025-02-12 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: ruby-progressbar
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ description: A gem that iterates over each file in a folder, computes its SHA256 hash,
28
+ and writes a prettified file hierarchy to a text file.
29
+ email:
30
+ - tapiador@jib.is
31
+ executables:
32
+ - sha256_everything
33
+ extensions: []
34
+ extra_rdoc_files: []
35
+ files:
36
+ - README.md
37
+ - bin/console
38
+ - bin/setup
39
+ - bin/sha256_everything
40
+ - lib/sha256_everything.rb
41
+ - lib/sha256_everything/application.rb
42
+ - lib/sha256_everything/cli.rb
43
+ - lib/sha256_everything/file_collector.rb
44
+ - lib/sha256_everything/file_hasher.rb
45
+ - lib/sha256_everything/output_writer.rb
46
+ - lib/sha256_everything/tree_generator.rb
47
+ - lib/sha256_everything/version.rb
48
+ - sha256_everything.gemspec
49
+ homepage: https://github.com/jibril-tapiador/sha256_everything
50
+ licenses:
51
+ - MIT
52
+ metadata: {}
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubygems_version: 3.5.16
69
+ signing_key:
70
+ specification_version: 4
71
+ summary: Hashes every file in a directory using SHA256
72
+ test_files: []