uri-ni 0.1.2 → 0.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e205294ee6b137c97fca41dfe3017b8fcfe41e28ba949002ba00167d216c3dd8
4
- data.tar.gz: d81cbabc67dc1ed564d790232011119e1b3eec87044531680e6db77f2bc728a6
3
+ metadata.gz: c1c4325ac19a7451179586b13811dab241ea0ea6ecb5d5e655193a4b1780e3b0
4
+ data.tar.gz: b3318a52162366d7887619c7b2b60727f5b43c6624960e61affaad53b6a25121
5
5
  SHA512:
6
- metadata.gz: 85745faf2e879e90a233f60f937b9f55adcfcca2cb06e4871ebfab119ba98bc88517b8907baafb50412cbdd6af7342dbdadc1f0652382ad96a614cd64084b56c
7
- data.tar.gz: fe3bd0a1fef2939489dc31dc463e7038f632a771f0d9feb17b72617c37bc19cfae78eb19d304b7f06f85694114ea6cafb34d0065e664147c9516bd0078cfe97e
6
+ metadata.gz: 9892531f60b96df7e275f5ec5b5b2e9088166bf40883363a40f3002b47af05ca7905e287f2251d00689305b97f6f2e0f70fec7ef28f86c7a1b03c43b7ddf9928
7
+ data.tar.gz: 1c390012d6210ea3b02798eedd22f2d3a920c0961d458b06487f6a52002924bd9007139f142fb6255a0afe652c64e30b032882795138cdadb55457af1c16da26
data/exe/ni-uri ADDED
@@ -0,0 +1,40 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- mode: enh-ruby -*-
3
+
4
+ require 'uri/ni'
5
+ require 'pathname'
6
+ require 'optparse'
7
+
8
+ options = {}
9
+ op = OptionParser.new do |opts|
10
+ opts.banner = "Usage: ni-uri [options] FILES"
11
+
12
+ opts.on("-a", "--algorithm STRING", "algorithm") do |a|
13
+ options[:algorithm] = a.to_sym
14
+ end
15
+ end
16
+
17
+ op.parse!
18
+
19
+ options[:algorithm] ||= :"sha-256"
20
+ unless URI::NI.valid_algo? options[:algorithm]
21
+ $stderr.puts "#{options[:algorithm]} is not a valid algorithm"
22
+ exit 1
23
+ end
24
+
25
+ if ARGV.empty?
26
+ puts op.to_s
27
+ exit 1
28
+ end
29
+
30
+ ARGV.each do |fn|
31
+ fn = Pathname(fn).expand_path
32
+ begin
33
+ fh = fn.open
34
+ ni = URI::NI.compute fh, algorithm: options[:algorithm]
35
+ puts ni.to_s
36
+ rescue SystemCallError => e
37
+ $stderr.puts "Could not compute digest for #{fn}: #{e.message}"
38
+ next
39
+ end
40
+ end
data/lib/uri/ni.rb CHANGED
@@ -186,7 +186,7 @@ class URI::NI < URI::Generic
186
186
  # @raise [ArgumentError] if the algorithm is unrecognized
187
187
  def self.context algorithm
188
188
  raise ArgumentError, "Cannot coerce #{algorithm} to a symbol" unless
189
- algorithm.respond_to(:to_s) # cheat: symbols respond to to_s
189
+ algorithm.respond_to? :to_s # cheat: symbols respond to to_s
190
190
  algorithm = algorithm.to_s.to_sym unless algorithm.is_a? Symbol
191
191
  raise ArgumentError, "Unsupported digest algorithm #{algorithm}" unless
192
192
  ctx = DIGESTS[algorithm]
@@ -475,4 +475,16 @@ class URI::NI < URI::Generic
475
475
  to_www https: false, authority: authority
476
476
  end
477
477
 
478
+ # Returns the set of supported algorithms.
479
+ # @return [Array] the algorithms
480
+ def self.algorithms
481
+ DIGESTS.keys
482
+ end
483
+
484
+ # Returns true if the algorithm is supported.
485
+ # @param algorithm [Symbol,String] the algorithm identifier to test
486
+ # @return [true, false] whether it is supported
487
+ def self.valid_algo? algorithm
488
+ DIGESTS.has_key? algorithm.to_s.downcase.to_sym
489
+ end
478
490
  end
@@ -3,7 +3,7 @@ require 'uri/generic'
3
3
 
4
4
  module URI
5
5
  class NI < Generic
6
- VERSION = "0.1.2"
6
+ VERSION = "0.1.4"
7
7
  end
8
8
 
9
9
  # might as well put this here
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uri-ni
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dorian Taylor
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-17 00:00:00.000000000 Z
11
+ date: 2020-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -41,7 +41,8 @@ dependencies:
41
41
  description: ''
42
42
  email:
43
43
  - code@doriantaylor.com
44
- executables: []
44
+ executables:
45
+ - ni-uri
45
46
  extensions: []
46
47
  extra_rdoc_files: []
47
48
  files:
@@ -54,6 +55,7 @@ files:
54
55
  - Rakefile
55
56
  - bin/console
56
57
  - bin/setup
58
+ - exe/ni-uri
57
59
  - lib/uri-ni.rb
58
60
  - lib/uri/ni.rb
59
61
  - lib/uri/ni/version.rb